This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-29
Channels
- # announcements (5)
- # beginners (25)
- # calva (53)
- # clj-kondo (9)
- # clojure (25)
- # clojure-europe (14)
- # clojure-nl (1)
- # clojure-norway (21)
- # clojure-uk (1)
- # conjure (2)
- # data-science (1)
- # datalevin (4)
- # datascript (6)
- # deps-new (5)
- # emacs (5)
- # etaoin (6)
- # figwheel-main (1)
- # fulcro (46)
- # gratitude (3)
- # hyperfiddle (8)
- # introduce-yourself (13)
- # lsp (13)
- # nextjournal (5)
- # off-topic (2)
- # pathom (4)
- # polylith (11)
- # re-frame (16)
- # releases (4)
- # scittle (67)
- # shadow-cljs (38)
- # slack-help (4)
- # specter (13)
- # sql (29)
- # squint (21)
- # test-check (3)
- # vim (13)
- # xtdb (15)
Can someone else me understand why why transacting the same entity, because it has a shared :db.unique/value, unexpectedly results in a new entity (new db/id)? e.g
make value unique
(d/transact! conn [{:db/ident :db/uuid
:db/valueType :db.type/uuid
:db/cardinality :db.cardinality/one
:db/unique :db.unique/value}])
(def uuid (random-uuid))
;; inesrt into do
(d/transact! conn [{:entity/name "foo"
:db/uuid uuid}])
;; this should be an upsert now
(d/transact! conn [{:entity/name "bar"
:db/uuid uuid}])
But when i compare the db before and db after i see the entity "2" didn't change, instead there is a new one "3"
{:db-before
#datascript/DB {:schema {},
:datoms
[[1 :db/cardinality :db.cardinality/one 536870913]
[1 :db/ident :db/uuid 536870913]
[1 :db/unique :db.unique/value 536870913]
[1 :db/valueType :db.type/uuid 536870913]
[2
:db/uuid
#uuid "aa5e8db5-3777-400b-9473-d921a4e6a494"
536870914]
[2 :entity/name "foo" 536870914]]},
:db-after
#datascript/DB {:schema {},
:datoms
[[1 :db/cardinality :db.cardinality/one 536870913]
[1 :db/ident :db/uuid 536870913]
[1 :db/unique :db.unique/value 536870913]
[1 :db/valueType :db.type/uuid 536870913]
[2
:db/uuid
#uuid "aa5e8db5-3777-400b-9473-d921a4e6a494"
536870914]
[2 :entity/name "foo" 536870914]
[3
:db/uuid
#uuid "aa5e8db5-3777-400b-9473-d921a4e6a494"
536870915]
[3 :entity/name "bar" 536870915]]},
:tx-data
[#datascript/Datom [3 :entity/name "bar" 536870915 true]
#datascript/Datom [3
:db/uuid
#uuid "aa5e8db5-3777-400b-9473-d921a4e6a494"
536870915
true]],
:tempids {3 3, :db/current-tx 536870915},
:tx-meta nil}
Though if we query the db we get the expected result:
(d/q '[:find [?db-id ?name ?uuid]
:where
[?db-id :db/uuid ?uuid]
[?db-id :entity/name ?name]]
(d/db conn))
;; => [3 "bar" #uuid "aa5e8db5-3777-400b-9473-d921a4e6a494"]
Then confusingly, if i txt again with the same uuid, but a different name, i unexpectedly don't get the name updated:
(d/transact! conn [{:entity/name "cat"
:db/uuid uuid}])
(d/q '[:find [?db-id ?name ?uuid]
:where
[?db-id :db/uuid ?uuid]
[?db-id :entity/name ?name]]
(d/db conn))
;; => [3 "bar" #uuid "aa5e8db5-3777-400b-9473-d921a4e6a494"]
I'm trying to find docs specific to datascript, but as far as i can tell it should honor how datomic handles unique values right? Maybe I don't understand the contract.
thanks in advance 🙂 :thumbsup:I haven't used datascript a ton, but I believe you have to specify the schema upfront and cannot use transact! to add new attributes (:schema is empty in your output there)
ahhhh.
that's probably it. thanks a ton, that could have taken me a while to have noticed. 😌
i see that. interesting. thanks @U050UBKAA