This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-01
Channels
- # announcements (6)
- # beginners (68)
- # calva (5)
- # cider (3)
- # clara (1)
- # clojure (49)
- # clojure-europe (24)
- # clojure-nl (2)
- # clojure-norway (28)
- # clojure-seattle (1)
- # clojure-uk (5)
- # clojurescript (3)
- # conjure (5)
- # core-typed (6)
- # data-science (1)
- # datalevin (3)
- # datascript (3)
- # datavis (1)
- # datomic (19)
- # events (2)
- # fulcro (6)
- # gratitude (1)
- # helix (6)
- # hyperfiddle (19)
- # joyride (6)
- # lsp (20)
- # music (1)
- # nbb (12)
- # pathom (2)
- # pedestal (10)
- # re-frame (3)
- # reitit (3)
- # ring (5)
- # shadow-cljs (26)
- # yamlscript (17)
hi everyone! i'm a new clojure user who is trying out datomic, can anyone help me understand what the schema field :db/cardinality does? i don't get what it means or when to use it..
One means assertions automatically retract whatever is there, and map projections of entities encode values “bare” without a collection wrapper
IOW one means you can only assert a single value at a time for that attr on a given entity
thanks for the answer, but i'm still pretty new to everything, could you explain what is retract and what is a collection wrapper
I'm trying to make a transaction and then find (for example) all new users in the db as a result of that transaction. My understanding is that the first method is more generally applicable, and the latter will only work if you don't need to get any data that is not in that transaction (due to the "subtlety" described here: https://docs.datomic.com/cloud/time/filters.html#since)? Any other obvious approaches I'm missing?
(let [{:keys [db-after db-before tx-data] :as result}
(d/transact conn {:tx-data [{:user/id 1}]})]
(d/q '[:find (pull ?u [*])
:in $ $before
:where
[$ ?u :user/id ?uid]
(not [$before ?u :user/id ?uid])]
db-after db-before))
(let [{:keys [db-after db-before tx-data] :as result}
(d/transact conn {:tx-data [{:user/id 1}]})]
(d/q '[:find (pull ?u [*])
:where [?u :user/id ?uid]]
(d/since db-after (:basisT db-before))))
Inspect tx-data directly:
(let [{:keys [db-after tx-data] :as result}
(d/transact conn {:tx-data [{:user/id 1}]})]
(d/q '[:find (pull ?u [*])
:in $ $tx-data
:where
[?attr :db/ident :user/id]
[$tx-data ?u ?attr _ _ true]]
db-after tx-data))
Or possibly more efficient if tx-data may be big (avoids re-sending the tx-data back):
(let [{:keys [db-after tx-data] :as result}
(d/transact conn {:tx-data [{:user/id 1}]})
user-attr-id (ffirst (d/q '[:find ?attr
:where [?attr :db/ident :user/id]]
db-after))
created-user-eids (into []
(keep
(fn [[e a _v _tx added?]]
(when (and added? (== a user-attr-id))
e)))
tx-data)]
(d/q '[:find (pull ?u [*]) :in $ [?u ...]]
db-after created-user-eids))
What do you mean by this, @U09R86PA4? https://clojurians.slack.com/archives/C03RZMDSH/p1709313394323919?thread_ts=1709312661.246619&cid=C03RZMDSH
It doesn’t have tx-ids or tx-data https://docs.datomic.com/pro/query/query.html#tx-ids
if it did, you could do this:
(let [{:keys [db-after] :as result}
(d/transact conn {:tx-data [{:user/id 1}]})]
(d/q '[:find (pull ?u [*])
:in $ ?log ?tx
:where
[?attr :db/ident :user/id]
[(ground true) ?op]
[(tx-data ?log ?tx) [[?u ?attr _ _ ?op]]]
db-after (d/basis-t db-after))