cozodb / cozo

A transactional, relational-graph-vector database that uses Datalog for query. The hippocampus for AI!
https://cozodb.org
Mozilla Public License 2.0
3.39k stars 106 forks source link

stored procedures? #276

Open ear7h opened 2 months ago

ear7h commented 2 months ago

Hi, again! I'm messing around with cozo again and came up with an interesting problem. I've created a web of named queries like:

allowed_users[principal, email] := ...

allowed_channels[principal, channel_id] :=
    *channel{author, ...},
    allowed_users[principal, author], ...

allowed_threads[principal, channel_id, thread_id] :=
    *threads{channel_id, thread_id, author, ...},
    allowed_users[principal, author],
    allowed_channels[principal, channel_id], ...

I'd like to use these as part of implementing GET /users, GET /channels, GET /threads, etc. That is, these queries will just be filters for a queries against *user, *channel, and *thread. As far as I can tell, I'll just have to duplicate this text for each query. But, is there a way to save these queries like function/stored procedure?

ear7h commented 2 months ago

Something that has the shape of what I want is fixed rules, and the registration mechanism. However, fixed rules must be implemented in complete isolation to the Db.

creatorrr commented 1 month ago

Currently, we also just duplicate this kind of stuff so stored named rules could be really useful for sure

docteurklein commented 4 weeks ago

I think what you're referring to is more like views, not procedures.