This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-14
Channels
- # aleph (3)
- # announcements (1)
- # babashka (36)
- # babashka-sci-dev (4)
- # beginners (62)
- # biff (2)
- # calva (13)
- # cider (4)
- # clj-kondo (6)
- # cljdoc (17)
- # clojure (142)
- # clojure-dev (6)
- # clojure-europe (62)
- # clojurescript (20)
- # core-async (26)
- # cursive (18)
- # data-oriented-programming (9)
- # data-science (1)
- # datahike (18)
- # events (4)
- # fulcro (4)
- # graalvm (2)
- # hyperfiddle (15)
- # interop (1)
- # jobs-discuss (8)
- # leiningen (2)
- # lsp (91)
- # malli (1)
- # missionary (11)
- # nbb (65)
- # off-topic (50)
- # practicalli (2)
- # programming-beginners (4)
- # re-frame (18)
- # remote-jobs (1)
- # shadow-cljs (53)
- # spacemacs (1)
- # specter (2)
- # sql (17)
- # tools-build (63)
- # web-security (1)
- # xtdb (15)
Hey again, nope, the nested map is only hashed and that hashed gets indexed (so equality can be determined quickly at query time)
If you need to index nested things, then you probably want to 'shred' your document into additional entities and join across them
In some circumstances you may not need the speed of having the data indexed though, in which case it might be good enough to simply use Clojure functions inside the query: [(get-in ?stats [:attr]) ?attr-v]

hello everyone, I have this query
(db-core/q
db
'{:find [(pull ?user
[(:xt/id {:as :id})
:user/name
:user/email
:organization/id])]
:in [?org-id]
:where [[?user :organization/id ?org-id]
[?user :user/status :user.status/active]]}
"org-id")
and I would like to sort the results by the user name, I tried to use order-by
without too much success
is it possible to sort results using pull?hey @U3QUAHZJ6 👋
you could try returning the name as a separate field in the result (i.e. :find [?username (pull ?user ...)]
), and then ordering by ?username
?
maybe Im missing something basic but
(db-core/q
db
'{:find [?username
(pull
?user
[(:xt/id {:as :id})
:auth0/id
:user/name
:user/email
:organization/id])]
:in [?org-id]
:where [[?user :organization/id ?org-id]
[?user :user/status :user.status/active]
[?username :user/name ?user]]
:order-by [[?username :asc]]
}
org-id)
this now returns me nothing
I tried with [?user :user/name ?username]
just for the sake of it but it didnt workedI would guess [?user :user/name ?username]
is the correct orientation of the triple clause, so should work :thinking_face:
Do you get a vector returned? Or a set? If it's a vector, is there no evidence of ordering at all? Is ?username
always a ~short string?
my repl state was borked somehow, it changes the shape of the result, but it works, thanks =D
Do I remember incorrectly that pull
-ing would not work against map keys?
I will also try it out...sorry about the lazy question 😄
Hey, it seems not 🙂
(with-open [n (xt/start-node {})]
(->> [[::xt/put {:xt/id :foo :att {{:map-key true} :bar}}]]
(xt/submit-tx n)
(xt/await-tx n))
(xt/q (xt/db n) '{:find [(pull e [{:map-key true}])]
:where [[e :xt/id :foo]]}))
In fairness though XT doesn't really support non-keyword keys in general (but will happily store them in nested values, thanks to Nippy)