   {: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]


  (<apply-datoms [db datoms]
    (go-pair
      (let [exec (partial s/execute! (:sqlite-connection db))]
        ;; 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.
            (<? (exec
                  ["INSERT INTO transactions VALUES (?, ?, ?, ?, ?)" e a v tx (if added 1 0)]))


  (go-pair
    ;; TODO: comment on applying datoms that violate uniqueness.
    (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 a)
            (when-let [found (first (<? (<avet db [a v])))]
              (raise "Cannot add " datom " because of unique constraint: " found
                     {:error :transact/unique
