mozilla / mentat

UNMAINTAINED A persistent, relational store inspired by Datomic and DataScript.
https://mozilla.github.io/mentat/
Apache License 2.0
1.65k stars 115 forks source link

Don't allow violation of cardinality-one restrictions within a single transact. #533

Closed rnewman closed 6 years ago

rnewman commented 6 years ago

This requires maintaining a unique index so that we can INSERT OR REPLACE. The last value will win. We could also do INSERT 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?

rnewman commented 6 years ago

We can't easily detect duplicates within a tx boundary: we can use INSERT and have an opaque error about uniqueness constraints being violated, which we wrap to Could not insert non-fts one statements into temporary search table!; use INSERT OR IGNORE and silently take the first value; or INSERT OR REPLACE and silently take the last (based on some permutation of the input order, I assume).

I think I'd prefer the opaque error, which we can improve in the future. I'll file that now.

rnewman commented 6 years ago

ef9f2d9 with a map notation test.