Don't allow violation of cardinality-one restrictions within a single transact.#533
Don't allow violation of cardinality-one restrictions within a single transact.#533rnewman wants to merge 2 commits into
Conversation
ncalexan
left a comment
There was a problem hiding this comment.
In general, I think this is great. Perhaps a little expensive, but clear.
I have no strong opinion on OR REPLACE vs OR IGNORE. Last one wins -- i.e., transaction is processed in the order it is presented -- certainly seems to be most clear.
I am a little concerned that it violates Datomic's set-oriented model, but I am comforted by the fact that Datomic doesn't allow, for example, a schema change in the first datom transacted and then the use of the new schema fragment in subsequent datoms transacted. (In the same transaction.)
Does this not address the map notation bug you originally started from? If it does not, OK; if it does, please include a map notation test, since there is some hairy interleaving of the transactor stages that should be exercised.
| [:db/add "foo" :test/unique "x"] | ||
| ]"#); | ||
|
|
||
| // You can try to assert two values for the same entity and attribute, |
There was a problem hiding this comment.
Does this agree with Datomic? With DataScript?
There was a problem hiding this comment.
Datomic raises an error:
":db.error/datoms-conflict Two datoms in the same transaction conflict\n{:d1 [17592186045418 :test/one 123 13194139534313 true],\n :d2 [17592186045418 :test/one 124 13194139534313 true]}\n"
|
We can't easily detect duplicates within a tx boundary: we can use I think I'd prefer the opaque error, which we can improve in the future. I'll file that now. |
|
ef9f2d9 with a map notation test. |
This requires maintaining a unique index so that we can
INSERT OR REPLACE. The last value will win. We could also doINSERT OR IGNORE, check the number of changed rows, and throw.This only works if the lookup ref succeeds. If it doesn't, then we're into #532.
Thoughts, @ncalexan?