This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-23
Channels
- # announcements (2)
- # babashka (25)
- # beginners (33)
- # biff (13)
- # calva (13)
- # clerk (82)
- # clj-commons (3)
- # clj-kondo (8)
- # clj-on-windows (23)
- # cljdoc (6)
- # clojure (16)
- # clojure-belgium (1)
- # clojure-dev (58)
- # clojure-europe (53)
- # clojure-nl (1)
- # clojure-norway (15)
- # clojure-uk (2)
- # clojurescript (17)
- # core-async (5)
- # cursive (6)
- # datahike (1)
- # datomic (8)
- # emacs (25)
- # etaoin (21)
- # events (4)
- # graalvm (33)
- # honeysql (7)
- # hyperfiddle (1)
- # lsp (49)
- # luminus (4)
- # malli (18)
- # off-topic (63)
- # reagent (11)
- # releases (1)
- # shadow-cljs (200)
- # timbre (1)
- # tools-build (17)
Hello all. I have some Very Baby questions about queries that I will thread.
So I've got this code:
(biff/q db '{:find [(pull user [*])]
:where [[user :user/id ?uid]]})
And it's not finding any users... even though I'm logged in as one. I tried some iterations without pull
but they're long gone.
haaaaaalp thanks
(I'm looking for your basic find-all for an admin page)
is this with the default biff project? if so, you can replace :user/id with :user/email. :user/id isn't part of the default app's schema (:xt/id is the closest equivalent, but it isn't specific to users or any other document type)
I see :user/id :uuid
in the schema but I might have put it there for some reason? The code would have to populate it anyway...
pprint says I'm getting a result! thanks. but it's disturbing that there's no way to say "just show me everything"
oh yeah, that could be confusing--the :user/id
there is basically an alias for :xt/id
. it's a malli thing
You can query for all the documents if you do
(q db '{:find [(pull doc [*])]
:where [[doc :xt/id]]})
I've attempted to generalize this:
(defn find-all-with-key [db key]
(biff/q db '{:find (pull doc [*])
:in [key]
:where [[doc key ?val]]}
key))
but am getting the error xtdb.IllegalArgumentException: Query didn't match expected structure
which one wishes would be more specific
yeah, it's a limitation of :in
arguments--they can only be used as variables in the entity or value positions, not in the attribute positions. To do dynamic attributes you have to do it like this:
(defn find-all-with-key [db key]
(biff/q db {:find '(pull doc [*])
:where [['doc key '?val]]}))
Oh right, you can do a bunch of little quotes instead of one big one. I even saw that somewhere and spaced it. Thanks again!