This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-31
Channels
- # aleph (24)
- # announcements (2)
- # aws (1)
- # babashka (2)
- # beginners (46)
- # calva (15)
- # chlorine-clover (1)
- # clojure-europe (27)
- # clojure-nl (3)
- # clojure-norway (13)
- # clojure-uk (7)
- # clojurescript (16)
- # datomic (29)
- # emacs (4)
- # fulcro (16)
- # hugsql (6)
- # hyperfiddle (65)
- # lsp (9)
- # malli (3)
- # off-topic (29)
- # pedestal (1)
- # releases (1)
- # shadow-cljs (52)
- # specter (5)
- # xtdb (1)
Is it possible to parameterize collection aggregates in a query? I would like to (sample <N> ?x)
where N is provided as a parameter to the query. My fallback is to build the query dynamically, but for obvious reasons that's less desireable.
And if the answer is to build the query dynamically, I'm banging my head on why these two queries are different: A single result with three values (the goal):
(d/q {:query {:find ['(sample 3 ?tid)]
:in '[$]
:where '[[(q '{:find [(min 10 ?exp)]
:where [[_ :st.oauth.token/expires-at ?exp]]} $)
[[?oldests]]]
[?t :st.oauth.token/id ?tid]
[(identity ?oldests) [?expires-at ...]]
[?t :st.oauth.token/status ?s]
[?t :st.oauth.token/expires-at ?expires-at]]}
:args [db]})
Ten results each with a single tid value (unexpected):
(d/q {:query {:find [('sample 3 '?tid)]
:in '[$]
:where '[[(q '{:find [(min 10 ?exp)]
:where [[_ :st.oauth.token/expires-at ?exp]]} $)
[[?oldests]]]
[?t :st.oauth.token/id ?tid]
[(identity ?oldests) [?expires-at ...]]
[?t :st.oauth.token/status ?s]
[?t :st.oauth.token/expires-at ?expires-at]]}
:args [db]})
Clearly the quoting is the issue -but it seems like they should be equivalent.Thank you -I'm embarrassed I didn't catch that myself. I'm struggling with understanding the evaluation context of queries -and doubly so with nested subqueries - getting the inner 10
on the min
collection aggregate to be parameterized is proving even harder than the outer 3
on the sample. But regardless, invoking a symbol as a fn at that outer layer should have been an obvious fail.
This may help https://github.com/brandonbloom/backtick
That is awesome. I've been looking for something like that without realizing it -and not just for this issue but also when building rules and such in Datalog.
Lets you write (let [sample-n 3] (template [:find [(sample ~sample-n ?tid)] …))
without a giant mess of quote-unquote to keep the datalog symbols unqualified
Yep. That's a struggle. @U053S2W0V is probably going to keep me from pulling my hair out. Thanks to both of you.
I am having an issue with a query and wild card patterns:
(d/q {:query '[:find (pull ?page pattern)
:in $ ?id pattern
:where
[?page :page/id ?id]]
:args [(d/db conn)
id
'[*]]})
It gives me an error:
Attribute identifier clojure.core/* of class: class java.lang.String does not start with a colon
Any idea why it doesn't work? I also tried adding the pattern directly to the pull expression, but I get the exact same issueOk, it seems the issue is actually what the message says, the documentation is not clear on this, and you need to use [:] instead of '[*]
Yeah, I find it odd. If I use * directly, it just complains about clojue_STAR something
this is the only way I found that actually worked
I think you need to change pattern
into ?pattern
?
No, that wouldn't work, the '?'convention is only for query arguments, patterns don't use that. If I replace the * with a different pattern, it works
Ok, i thought it became a query argument because of the usage of :in
. But i can be wrong of course
What I mean by query argument, is this '[?page :page/id ?id]'
inside the (pull ….) expression, you can't use '?''
Ah i see
or at least, that's what I have read
but I seem to remember trying that out in another situation, and I got an error because of that
You are doing this correctly. https://docs.datomic.com/cloud/query/query-data-reference.html#separation-of-concerns