Hi 👋 I'm working on adding Datahike support to #dataspex. One of the things its datalog browser does is to browse all entities. What's a good way to find all entities (excluding transactions and attributes) in a Datahike database?
clojure
(require '[datahike.api :as d]
'[datahike.constants :as const])
(->> (d/q '[:find [?e ...]
:in $ ?tx0
:where
[?e _ _]
[(< ?e ?tx0)]
(not [?e :db/ident _])]
db const/tx0)
(map #(d/entity db %)))
This excludes:
- transaction entities via (< ?e tx0)
- attribute/schema entities via (not [?e :db/ident _])
I tested the same query in both :attribute-refs? true and :attribute-refs? false, and it returned only the domain entities in both cases.
One small note: if you want stable ordering, sort the resulting eids before mapping them to entities.Cool, thanks 🙏
For Datomic I do this:
(def last-tx (d/t->tx 0x00000000FFFFFFFF))
(->> (d/seek-datoms db :eavt last-tx)
(map :e)
distinct
(map #(d/entity db %)))
These APIs are available in Datahike as well, but I'm not sure how to make it skip past the transactions.I assume a naive remove would be quite slow on large databases(?)
Another question: Datomic has (d/db-stats (d/db conn)) for quick stats about number of datoms etc. Is there something similar in Datahike?
Not yet, but we have d/metrics. If this is insufficient feel free to open an issue. PRs are also welcome.
Cool, I'll check it out 👍