This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-10
Channels
- # aleph (1)
- # beginners (4)
- # biff (7)
- # calva (7)
- # cider (8)
- # clara (17)
- # clerk (19)
- # clj-kondo (30)
- # clojure (12)
- # clojure-austin (1)
- # clojure-europe (12)
- # clojure-losangeles (1)
- # clojure-norway (21)
- # clojurescript (2)
- # datalevin (1)
- # datomic (24)
- # duct (3)
- # fulcro (8)
- # hyperfiddle (8)
- # lambdaisland (4)
- # membrane (6)
- # missionary (7)
- # off-topic (55)
- # overtone (2)
- # reagent (4)
- # reitit (4)
- # releases (6)
- # shadow-cljs (80)
hey all how can I group up queries that include "many" cardinality? for example:
(d/q [:find ?user ?group
:where
[?u :user/name ?user]
[?u :user/group ?g]
[?g :group/name ?group]])
I'm receiving the results as repeating user names for each group, and I want the result to be group in a vector for the group:
[{:user "u1"
:groups ["g1" "g2"]}
{:user "u2"
:group ["g1" "g4"]}]
should I just write ad-hoc code for that or datomic has some aggregate / grouping functionality?prefect it worked, thanks
While I'm at it, I'm trying to modify the values of the groups.
I'm receiving as an input the current groups of the user.
I want to remove all the group he currently part of and add the new ones.
I have tried retract
and add
in the same transaction but it failed:
(d/transact conn [{:user u
:groups [{:name g-name} ...]}
[:db/retract [:user u] :groups]])
Two datoms in the same transaction conflict
Woah I never knew vec
could be used like this. Is there a way that you can call pull
in the query on the things you're calling the aggregate function on? like
:find ?user (vec (pull ?groups [*])
That gives me
IllegalArgumentException Argument (pull ?groups [*]) in :find is not a variable
Edit: hmm I think maybe a subquery doing the pull would work, trying that out nowYou can write your own aggregate fn (read the docs). If you are on on-prem, it’s usually pointless to try and stuff everything into a query
Re: retract and add, you can’t retract and add the same value in the same tx; you need to retract the specific ones which will be gone. If you want to do this in a race-proof way, write a transaction fn which accepts the full set of values you want and returns the adds/retracts needed to make that the final value
Since vec
is not documented in the https://docs.datomic.com/cloud/query/query-data-reference.html#aggregates, I wonder if there are other aggregate functions I've been missing. I also wonder if the (also undocumented AFAICT) function signature of custom aggregates just happens to match that of the built-in "ambient" fn vec
...
Works on cloud too. I had a similar line of thought that vec
must be some "special" built in before realizing it's clojure.core/vec and having a mini "aha moment" about how the aggregates work