Fork me on GitHub
#crux
<
2020-06-25
>
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

refset22:06:42

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)

dvingo01:06:16

I think pull syntax may help with this. I copied datascript's implementation and update to work with crux: https://github.com/dvingo/my-clj-utils/blob/master/src/main/dv/crux_pull.clj

dvingo01:06:45

you can use the lib it's a part of to try it out https://github.com/dvingo/my-clj-utils

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
dvingo01:06:55

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 ['*]}]}])
https://docs.datomic.com/on-prem/pull.html

👍 1
refset07:06:37

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

fulcro 1
👍 1