This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-25
Channels
- # announcements (5)
- # babashka (23)
- # beginners (70)
- # cider (24)
- # clj-kondo (14)
- # cljsrn (2)
- # clojars (6)
- # clojure (195)
- # clojure-australia (1)
- # clojure-dev (2)
- # clojure-europe (27)
- # clojure-france (1)
- # clojure-nl (4)
- # clojure-norway (2)
- # clojure-spec (2)
- # clojure-uk (12)
- # clojurescript (3)
- # clojurewerkz (1)
- # core-async (21)
- # cursive (9)
- # datomic (37)
- # duct (3)
- # emacs (16)
- # events (4)
- # fulcro (34)
- # graalvm (12)
- # javascript (3)
- # jobs (4)
- # malli (1)
- # meander (3)
- # nrepl (1)
- # off-topic (27)
- # pathom (16)
- # re-frame (17)
- # reagent (19)
- # rewrite-clj (18)
- # sci (47)
- # shadow-cljs (179)
- # spacemacs (18)
- # sql (52)
- # tools-deps (80)
- # vim (27)
- # vrac (1)
- # xtdb (9)
Is it possible to join documents as part of a query?
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: https://github.com/dvingo/my-clj-utils/blob/master/src/main/dv/crux_pull.clj
you can use the lib it's a part of to try it out https://github.com/dvingo/my-clj-utils
@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?
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"}}
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