Review comments: lift (schema db) in a few places.
This commit is contained in:
parent
5ece60e3e9
commit
c344de665e
1 changed files with 21 additions and 18 deletions
|
@ -150,11 +150,11 @@
|
|||
|
||||
(<apply-datoms [db datoms]
|
||||
(go-pair
|
||||
(let [exec (partial s/execute! (:sqlite-connection db))]
|
||||
(let [exec (partial s/execute! (:sqlite-connection db))
|
||||
schema (.-schema db)] ;; TODO: understand why (schema db) fails.
|
||||
;; TODO: batch insert, batch delete.
|
||||
(doseq [datom datoms]
|
||||
(let [[e a v tx added] datom
|
||||
schema (.-schema db) ;; TODO: understand why (schema db) fails.
|
||||
v (ds/->SQLite schema a v)
|
||||
fulltext? (ds/fulltext? schema a)]
|
||||
;; Append to transaction log.
|
||||
|
@ -798,8 +798,9 @@
|
|||
;; TODO: constrain entities; constrain attributes.
|
||||
|
||||
(go-pair
|
||||
(let [schema (schema db)]
|
||||
(doseq [[op e a v] (:entities report)]
|
||||
(ds/ensure-valid-value (schema db) a v))
|
||||
(ds/ensure-valid-value schema a v)))
|
||||
report))
|
||||
|
||||
(defn- <ensure-unique-constraints
|
||||
|
@ -813,12 +814,13 @@
|
|||
|
||||
(go-pair
|
||||
;; TODO: comment on applying datoms that violate uniqueness.
|
||||
(let [unique-datoms (transient {})] ;; map (nil, a, v)|(e, a, nil)|(e, a, v) -> datom.
|
||||
(let [schema (schema db)
|
||||
unique-datoms (transient {})] ;; map (nil, a, v)|(e, a, nil)|(e, a, v) -> datom.
|
||||
(doseq [[e a v tx added :as datom] (:tx-data report)]
|
||||
|
||||
(when added
|
||||
;; Check for violated :db/unique constraint between datom and existing store.
|
||||
(when (ds/unique? (schema db) a)
|
||||
(when (ds/unique? schema a)
|
||||
(when-let [found (first (<? (<avet db [a v])))]
|
||||
(raise "Cannot add " datom " because of unique constraint: " found
|
||||
{:error :transact/unique
|
||||
|
@ -826,7 +828,7 @@
|
|||
:entity datom})))
|
||||
|
||||
;; Check for violated :db/unique constraint between datoms.
|
||||
(when (ds/unique? (schema db) a)
|
||||
(when (ds/unique? schema a)
|
||||
(let [key [nil a v]]
|
||||
(when-let [other (get unique-datoms key)]
|
||||
(raise "Cannot add " datom " and " other " because together they violate unique constraint"
|
||||
|
@ -836,7 +838,7 @@
|
|||
(assoc! unique-datoms key datom)))
|
||||
|
||||
;; Check for violated :db/cardinality :db.cardinality/one constraint between datoms.
|
||||
(when-not (ds/multival? (schema db) a)
|
||||
(when-not (ds/multival? schema a)
|
||||
(let [key [e a nil]]
|
||||
(when-let [other (get unique-datoms key)]
|
||||
(raise "Cannot add " datom " and " other " because together they violate cardinality constraint"
|
||||
|
@ -858,7 +860,8 @@
|
|||
{:pre [(db? db) (report? report)]}
|
||||
(go-pair
|
||||
(let [initial-report report
|
||||
{tx :tx} report]
|
||||
{tx :tx} report
|
||||
schema (schema db)]
|
||||
(loop [report initial-report
|
||||
es (:entities initial-report)]
|
||||
(let [[[op e a v :as entity] & entities] es]
|
||||
|
@ -867,7 +870,7 @@
|
|||
report
|
||||
|
||||
(= op :db/add)
|
||||
(if (ds/multival? (schema db) a)
|
||||
(if (ds/multival? schema a)
|
||||
(if (empty? (<? (<eavt db [e a v])))
|
||||
(recur (transact-report report (datom e a v tx true)) entities)
|
||||
(recur report entities))
|
||||
|
|
Loading…
Reference in a new issue