diff --git a/src/datomish/db.cljc b/src/datomish/db.cljc index 63de0db2..dcd6eb00 100644 --- a/src/datomish/db.cljc +++ b/src/datomish/db.cljc @@ -120,12 +120,12 @@ ;; TODO: use q for searching? Have q use this for searching for a single pattern? (SQLite schema a v))] ;; We assume e and a are always given. + v (and v (ds/->SQLite schema a v))] ;; We assume e and a are always given. (go-pair (->> {:select [:e :a :v :tx [1 :added]] ;; TODO: generalize columns. - :from [:all_datoms] - :where (cons :and (map #(vector := %1 %2) [:e :a :v] (take-while (comp not nil?) [e a v])))} ;; Must drop nils. + :from [:all_datoms] + :where (cons :and (map #(vector := %1 %2) [:e :a :v] (take-while (comp not nil?) [e a v])))} ;; Must drop nils. (sql/format) (s/all-rows (:sqlite-connection db)) @@ -135,12 +135,12 @@ (SQLite schema a v)] + v (ds/->SQLite schema a v)] (go-pair (->> {:select [:e :a :v :tx [1 :added]] ;; TODO: generalize columns. - :from [:all_datoms] - :where [:and [:= :a a] [:= :v v] [:= :index_avet 1]]} + :from [:all_datoms] + :where [:and [:= :a a] [:= :v v] [:= :index_avet 1]]} (sql/format) (s/all-rows (:sqlite-connection db)) @@ -150,13 +150,13 @@ (SQLite schema a v) - fulltext? (ds/fulltext? schema a)] + v (ds/->SQLite schema a v) + fulltext? (ds/fulltext? schema a)] ;; Append to transaction log. ( 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 (