 
   (<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)]
+                v                (ds/->SQLite schema a v)
+                fulltext?        (ds/fulltext? schema a)]
             ;; Append to transaction log.
             (<? (exec
                   ["INSERT INTO transactions VALUES (?, ?, ?, ?, ?)" e a v tx (if added 1 0)]))

  {:pre [(db? db) (report? report)]}
  (go-pair
    (let [initial-report report
          {tx :tx}       report]
      (loop [report initial-report
             es (:entities initial-report)]
        (let [[[op e a v :as entity] & entities] es]

  ;; TODO: constrain entities; constrain attributes.

  (go-pair
    (let [schema (schema db)]
      (doseq [[op e a v] (:entities report)]
        (ds/ensure-valid-value schema a v)))
    report))

(defn- <ensure-unique-constraints
