Fork me on GitHub
Brandon Olivier21:06:37

Is it possible to join documents as part of a query?

Brandon Olivier21:06:55

I have a field in a document w/ the id of another. I’d like to merge them together in just 1 query


Hi @UJL94RYSW - Crux queries don't whole return documents currently, only values and IDs. I'm not certain about exactly what you're describing, but it sounds like your best bet may be to return the IDs of both docs and call entity, and then do the merge in Clojure. Do you have a small example of what the 2 source documents & merged document could look like? e.g. something like

{:crux.db/id :a :foo 1}
{:crux.db/id :b :ref :a :bar 2}
=> {:crux.db/id :a :foo 1 :bar 2}
(but I'm guessing that's not quite right)


I think pull syntax may help with this. I copied datascript's implementation and update to work with crux:


you can use the lib it's a part of to try it out

Brandon Olivier23:06:31

@U899JBRPF That kinda seems like a pretty big issue, no? What’s the normal course of action? Should I always enumerate exactly what data I need and primarily use it via a vector?

Brandon Olivier23:06:56

I’m doing like

{:crux.db/id :character/brandon
 :occupation :occupation/programmer}
{:crux.db/id :occupation/programmer
 :name "Software Engineer"}
;; and I'd like to get
{:crux.db/id :character/brandon
 :occupation {:crux.db/id :occupation/programmer ;; where this could be arbitrarily many keys 
              :name "Software Engineer"}}

👍 1

srsly, check out pull syntax (pull [{[:crux.db/id :character/brandon] ['*]}])

and the nested attrs:

(pull [{[:crux.db/id :character/brandon] [crux.db/id {:occupation ['*]}]}])

👍 1

Pull syntax is certainly convenient, which is why we are releasing support for EQL in the next 2-3 weeks 🙂

fulcro 1
👍 1