diff --git a/src/datomish/db.cljc b/src/datomish/db.cljc index e2b28b87..0bdce70a 100644 --- a/src/datomish/db.cljc +++ b/src/datomish/db.cljc @@ -119,13 +119,13 @@ ;; 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. (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 :tx] (take-while (comp not nil?) [e a v tx])))} ;; Must drop nils. + :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)) @@ -517,12 +517,7 @@ ;; n.b., this must not be symbolic -- it's inserted after we map idents -> entids. [:db/add tx (get-in db [:idents :db/txInstant]) txInstant])) -;; TODO: never accept incoming tx, throughout. -(defn maybe-add-tx [current-tx entity] - (let [[op e a v tx] entity] - [op e a v (or tx current-tx)])) - -(defn ensure-entity-form [[op e a v tx & rest :as entity]] +(defn ensure-entity-form [[op e a v & rest :as entity]] (cond (not (sequential? entity)) (raise "Bad entity " entity ", should be sequential at this point" @@ -605,10 +600,7 @@ (conj entities (tx-entity db report))))) ;; Extract the current txInstant for the report. - (->> (update-txInstant db*)) - - ;; Add tx if not given. - (update :entities (partial map (partial maybe-add-tx tx)))))) + (->> (update-txInstant db*))))) (defn- lookup-ref? [x] (and (sequential? x) @@ -699,22 +691,22 @@ {:pre [(db? db) (report? report)]} (go-pair - (let [keyfn (fn [[op e a v tx]] + (let [keyfn (fn [[op e a v]] (if (and (id-literal? e) - (not-any? id-literal? [a v tx])) + (not-any? id-literal? [a v])) (- 5) - (- (count (filter id-literal? [e a v tx]))))) + (- (count (filter id-literal? [e a v]))))) initial-report (assoc report :entities []) ;; TODO. initial-entities (sort-by keyfn (:entities report))] (loop [report initial-report es initial-entities] - (let [[[op e a v tx :as entity] & entities] es] + (let [[[op e a v :as entity] & entities] es] (cond (nil? entity) report (and (not= op :db/add) - (not (empty? (filter id-literal? [e a v tx])))) + (not (empty? (filter id-literal? [e a v])))) (raise "id-literals are resolved for :db/add only" {:error :transact/syntax :op entity }) @@ -722,33 +714,28 @@ ;; Upsert! (and (id-literal? e) (ds/unique-identity? (schema db) a) - (not-any? id-literal? [a v tx])) + (not-any? id-literal? [a v])) (let [upserted-eid (:e (first (tx-data [db report] {:pre [(db? db) (report? report)]} (go-pair - (let [initial-report report] + (let [initial-report report + {tx :tx} report] (loop [report initial-report es (:entities initial-report)] - (let [[[op e a v tx :as entity] & entities] es] + (let [[[op e a v :as entity] & entities] es] (cond (nil? entity) report @@ -881,7 +869,7 @@ (