Fork me on GitHub
#datalog
<
2022-01-31
>
denik02:01:02

what’s the best way to find entities without db.type/ref relationships? in a graph these could be called orphan nodes.

quoll05:01:42

Thinking of Datomic: :find ?e :where [?e ?a ?v] [?a :db/ident] (not [?o ?r ?e] [?r :db/ident]) The :db/ident statements are because unbound patterns make Datomic nervous. (I’m not sure if it's needed in the not expression)

refset17:01:21

XT doesn't support wildcard attribute vars, which is needed for a single not to be sufficient, so you'd either need a not per attribute (e.g. generating verbose queries), or you can define orphan? as a custom function that executes an inner query per attribute: https://gist.github.com/refset/25d8ae03c69993831c9c23cf7e12a537

👍 1
quoll18:01:16

This is where it gets tricky between databases. For instance, Asami has several options, but for this query it could just use: :find ?e :where [?e] (not [_ _ ?e])

💯 2
refset21:01:59

oh cool, I don't think I've seen anyone reduce a triple clause to merely [?e] before 🙂

quoll11:02:42

I’ve never needed to before! (Outside of unit tests)

😄 1