Datomic/Datascript/Datalog: How can I check predicate is valid for all edges?

47 views Asked by At

I am working with a fairly straightforward To-Do database. It has a hierarchical tree-like structure. Each entity is a block; every block as a children attribute for all its children, and a checked attribute. So a simple example would be:

5 :block/children 6
5 :block/children 7
6 :block/checked 1
7 :block/checked 0
...

I'd like to query all the blocks, for which all subtasks are completed. In the example above block 5 would not qualify, since it has one unchecked child 7.

I wrote many variants that essentially boiled down to this:

[:find ?ag
 :where 
 [?ag :block/children ?child] 
 (not [?child :block/checked 0])
]

This doesn't work, because it returns all the tasks that have any checked subtasks. Can someone guide me in how I can phrase this as a "for all children, make sure the predicate is correct"?

Thanks!

0

There are 0 answers