This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-30
Channels
- # announcements (12)
- # babashka (25)
- # biff (30)
- # cherry (34)
- # cider (46)
- # clj-kondo (23)
- # clojure (37)
- # clojure-berlin (6)
- # clojure-europe (12)
- # clojure-nl (4)
- # clojure-norway (6)
- # clojure-uk (2)
- # clojurescript (8)
- # conjure (1)
- # cursive (4)
- # data-science (11)
- # datalevin (12)
- # datascript (15)
- # emacs (2)
- # events (1)
- # fulcro (14)
- # graalvm (16)
- # gratitude (23)
- # honeysql (11)
- # jobs (2)
- # jobs-discuss (14)
- # kaocha (1)
- # leiningen (8)
- # nbb (45)
- # off-topic (7)
- # portal (8)
- # re-frame (9)
- # releases (2)
- # shadow-cljs (24)
- # squint (5)
- # tools-build (17)
- # tools-deps (7)
- # vim (5)
I'm trying to understand what this error is telling me i need to do
;; => #error {:message "Conflicting upsert: \"-12\" resolves both to 4 and 25", :data {:error :transact/upsert}}
-12 is a temporary id, are 4 and 25 supposed to be entity ids?is it saying that -12 has matched two entities that it should be associated with?
yeah, that would seem to be the case...
I was hoping that two entities with different tempids but a shared unique identity attribute (e.g server.db/id would merge, rather then confict.
;; => [[:db/add "-12" :user/roles :sponsor 536870913 true]
;; [:db/add "-12" :centriq.sync.remote.server.db/id "316659348808228"]]
;; => [[:db/add "-4" :user/roles :admin 536870913 true]
;; [:db/add "-4" :centriq.sync.remote.server.db/id "316659348808228"]]
;; => [[:db/add
;; "-25"
;; :user/roles
;; :centriq-web.data-browser/edit-field
;; 536870913
;; true]
;; [:db/add "-25" :centriq.sync.remote.server.db/id "316659348808228"]]
i guess another way to do this is to just map the server ids to shorter ids on the client. then map back when i send to the server.
Though, if i just transact that information by itself, not as part of the much larger transaction that throws, it doesnt throw.
(def a-tx (concat
[[:db/add "-12" :user/roles :sponsor 536870913 true]
[:db/add "-12" :centriq.sync.remote.server.db/id "316659348808228"]]
[[:db/add "-4" :user/roles :admin 536870913 true]
[:db/add "-4" :centriq.sync.remote.server.db/id "316659348808228"]]
[[:db/add
"-25"
:user/roles
:centriq-web.data-browser/edit-field
536870913
true]
[:db/add "-25" :centriq.sync.remote.server.db/id "316659348808228"]]))
a-tx
(def after
(d/transact! connection
a-tx))
(:tx-data after)
;; results...
[#datascript/Datom [1 :user/roles :sponsor 536870914 true]
#datascript/Datom [1 :centriq.sync.remote.server.db/id "316659348808228" 536870914 true]
#datascript/Datom [1 :user/roles :admin 536870914 true]
#datascript/Datom [1 :user/roles :centriq-web.data-browser/edit-field 536870914 true]]
if the temp ids are out of order then it fails ...
(def a-tx (concat
[[:db/add "-12" :user/roles :sponsor 536870913 true]
]
[[:db/add "-4" :user/roles :admin 536870913 true]
[:db/add "-12" :centriq.sync.remote.server.db/id "316659348808228"] ;;<--- out of order
[:db/add "-4" :centriq.sync.remote.server.db/id "316659348808228"]]
[[:db/add
"-25"
:user/roles
:centriq-web.data-browser/edit-field
536870913
true]
[:db/add "-25" :centriq.sync.remote.server.db/id "316659348808228"]]))
if i sort them, it works though. so ok, i can do that 🙂
I'm curious what you mean by sorting them, do you mean to say that this works?
[[:db/add "-4" :user/roles :admin 536870913 true]
[:db/add "-4" :centriq.sync.remote.server.db/id "316659348808228"]
[:db/add "-12" :user/roles :sponsor 536870913 true]
[:db/add "-12" :centriq.sync.remote.server.db/id "316659348808228"]]
but this doesn't?
[[:db/add "-12" :user/roles :sponsor 536870913 true]
[:db/add "-12" :centriq.sync.remote.server.db/id "316659348808228"]
[:db/add "-4" :user/roles :admin 536870913 true]
[:db/add "-4" :centriq.sync.remote.server.db/id "316659348808228"]]
For what it's worth, the way I am handling this is that if I am trying to send datoms to the client from the server, I loop through the datoms collecting a mapping of tempid to serverid. What I send to the client is to first set the :server/id for the set of tempids that I'm working with, then in the datoms themselves I use a lookup by :server/id.
(datoms->client
[[316659348808228 :user/roles :admin 536870913 true]
[316659348808228 :user/roles :sponsor 536870913 true]])
=> [[:db/add -1 :server/id 316659348808228]
[:db/add [:server/id 316659348808228] :user/roles :admin 536870913 true]
[:db/add [:server/id 316659348808228] :user/roles :sponsor 536870913 true]]
I also need to make sure I look at the schema to see if I also need to convert any values that are :db.type/ref
[:db/add [:server/id 316659348808228] :some/ref [:server/id 316659348808229]]
Also note that a ref could appear in a tuple, I've been avoiding using tuples for anything other than uniqueness because I haven't sorted out how that should work in datascript yet.Btw, I use the lookup because you can't retract a tempid like this
[:db/retract -1 :user/roles]
Lots of details 🙂@U03NXD9TGBD When i said "out of order" i should have said "not grouped" (as it's more specific). So "1 1 2" will work but not "1 2 1". I think i was rather tried when i typed that message, and the error was eating up 90% of my brain.
> When i said "out of order" i should have said "not grouped" (as it's more specific). So "1 1 2" will work but not "1 2 1". So both of my examples work? > I think i was rather tried when i typed that message, and the error was eating up 90% of my brain. Oh yeah, I've been there 🙂
Yes, i believe both would work. But i didn't check.