zetawar
zetawar copied to clipboard
Discussion: Find-by vs e-by-av
I'm curious whether this
(defn e-by-av [db a v]
(-> (d/datoms db :avet a v) first :e))
Might in many cases be more efficient than this, (even if adjusted to make use of ssolo etc, and why you wouldn't want to do a straight datom search in these cases
(defn find-by
"Returns the unique entity identified by either attr (for singleton
entities) or attr and val."
([db attr]
(qe '[:find ?e
:in $ ?attr
:where [?e ?attr]]
db attr))
([db attr val]
(qe '[:find ?e
:in $ ?attr ?val
:where [?e ?attr ?val]]
db attr val)))
I suspect e-by-av would be more efficient. When I added find-by I wasn't as familiar with the raw datom access functions.