Fork me on GitHub
#datascript
<
2022-01-25
>
lilactown00:01:59

is there a way to quickly lookup an entity via ref like [:id 0] and get a map of all attrs?

Niki07:01:55

Entities are not well-suited for that type of problem. Better use pull: (d/pull db '[*] [:id 0])

lilactown17:01:23

ah nice, thanks!

lilactown00:01:25

I'm running into issues using entity because it doesn't implement empty

lilactown00:01:32

and I'm trying to walk it

lilactown00:01:32

it's totally fine if it doesn't resolve references to other entities, as long as it contains the refs. e.g.

{:id 0
 :refs #{[:id 1] [:id 2]}}

quoll13:01:04

I’d rather a query for that, though you’d get :db/id values rather than :id (into {} (q '[:find ?attr ?val :where [?e :id 0] [?e ?a ?val] [?a :db/ident ?attr]] the-db))

Niki13:01:51

That would work too, although queries are much slower