Closed caleb closed 3 years ago
Thanks for reporting, I’ll take a look at it next week
Quick answer here would be: you can’t specify tuples when creating new entities, but you can use them to reference existing ones (upserts):
(let [conn (ds/create-conn {:one+two {:db/tupleAttrs [:one :two]
:db/unique :db.unique/identity}})]
(ds/transact! conn
[{:one "one" :two "two" :one+two ["one" "two"]}]) ;; doesn’t work
(ds/transact! conn
[{:one "one" :two "two"}]) ;; works
(ds/transact! conn
[{:one "one" :two "two" :one+two ["one" "two"]}])) ;; now this works too, because :one+two refers to an existing entity
(ds/transact! conn
[{:one+two ["one" "two"]}])) ;; works too
Long answer: this is probably not ideal, because it makes upserts a little trickier. After all, idea of upsert is that you write a single transact that works in both cases, when inserting and when updating.
I’ll see if I can do anything about it. For now, you can try not specifying tuples when creating new entities.
I think I found a way to cover your case. If the tuple content fully matches values already in DB, there will be no error anymore. But if it is somehow different (e.g. values are not in DB yet, or have different value), the same error will be thrown. Check out dd584b4, release coming soon.
Thanks! This version worked in my test playground. I will give it a try in my project to see how it works.
Upserting by unique composite tuple doesn't work in Datascript as it does in Datomic.
It was not immediately clear to me how to upsert by unique composite tuple in Datomic by the documentation, but I found this forum post about it:
https://forum.datomic.com/t/db-unique-identity-does-not-work-for-tuple-attributes/1072
The key part is the last post by
jaret
:Datascript:
Gives this error:
But in Datomic, this works:
Yields: