See all entities

I’m struggling with making a query that would show me all entities in the database. I tried this:

(d/q '[:find ?e ?a ?v
       :in $ 
       :where [?e ?a ?v]]
     db)

But I get an error: Insufficient binding of db clause: [?e ?a ?v] would cause full scan

What if full scan is what I need? How do I do it?

A query is used to get back much more limited sets of data, using the indexes, plus cache, plus the predicates in the query to unify all the variables to a resulting set. The way your query is written, has no predicates, and unification results in every latest datom (presuming you’re not using a history DB) … So it’s not really querying anything.

I looks like you just want access to the :eavt index directly - you can get pretty much exactly what you’re trying to do (and a bit more) with the datoms fn: datomic.client.api documentation

OR - if you want to just iterate on distinct entities, while simultaneously pulling all of their attributes/values (as a seq of entity maps) - then you can use the very handy index-pull fn using the :avet index - this however requires that you provide at least the name of an attribute that the entities must have, but usually that’s more useful anyway. You can do this with a query as well, but index-pull walks the sorted index in the order of the values (if that is advantageous to you)

1 Like

Thanks, it’s starting to make sense :slight_smile: