Dynamic pull selector


#1

I wan’t to pass inn a pull selector as an argument to a query, like this:

(d/q '[:find (pull ?e ?fields)
         :in $ ?fields
         :where [?e :game/name _]] 
  (d/db conn) [:db/id :game/name])

But this results in a “Invalid pull syntax” exception. The alternative (which I’m doing now) is to use the find query to get out all the entity ids I’m interested in, and then running pull on each of those ids. But since I’m using the client.api, that would result in a lot of overhead in communicating with the peer server, right?

Is there a way to pass in the pull selector dynamically that I’ve missed in the documentation?


#2

Hey @Robin, poking around the query I got this to work:

(d/q '[:find (pull ?e fields)
:in $ fields
:where [?e :game/name _]]
(d/db conn) '[*])

Which can be rewritten as:

(d/q '[:find (pull ?e fields)
:in $ fields
:where [?e :game/name _]]
(d/db conn) '[:db/id :game/name])

Not sure why though =)…

Hope it helps!