Fork me on GitHub
#datalog
<
2022-06-20
>
Benjamin11:06:56

what is the best way to check if an attribute exists? (it is avet indexed)

plexus12:06:50

That would depend on the database I suppose.

timo13:06:33

(d/q [:find ?e :where [?e :my/attribute _]] db) ? Maybe direct index access is faster!? (index-pull)

plexus12:06:18

I happened to have a need for this today and came up with

(defn has-attr? [db eid attr]
  (-> db
      ^Iterable (d/datoms :eavt eid attr)
      .iterator
      .hasNext))
very datomic-peer specific, but I can't imagine it getting much faster.

💯 2
Benjamin14:06:48

for datalevin I found there is d/eid . My use case was checking if an indexed entity exists