        (get @*eid-map* index)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Transaction Identifier
+;; Locks
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defn hold-lock

(defmethod -apply-fact :db/add
  [conn txid [type eid attr val :as fact]]
  (let [table (attrs/normalize-attrname attr "user")
        current-value (current-attr-value conn fact)]
    (if current-value
      (when (not= current-value val)
        (let [tmpl (str "UPDATE TABLE {{table}} "
                        "  SET modified_at=current_timestamp, "
                        "      content=?, txid=?"
                        "  WHERE eid=?")
              sql (tmpl/render-string tmpl {:table table})]
          (sc/execute conn [sql val txid eid])))
      (let [tmpl  (str "INSERT INTO {{table}} "
                       "  (eid, txid, modified_at, content)"
                       "  VALUES (?,?,current_timestamp,?)")
            sql (tmpl/render-string tmpl {:table table})]
        (sc/execute conn [sql eid txid val])))))

(defmethod -apply-fact :db/retract
  [conn txid [type eid attr val]]

        data (codecs/data->bytes facts)]
    (sc/execute conn [sql txid data])))

(defn run-transaction
  "Given an connection and seq of operation objects,
  execute them in serie."
  [conn facts]
  (binding [*eid-map* (volatile! {})]
    (let [txid (get-next-txid conn)]
      (-apply-tx conn txid facts)
      (let [ids (reduce #(conj %1 (-apply-fact conn txid %)) facts)]
        (filterv identity ids)))))

(defn transact
  [tx facts]
  (exec/submit
   #(let [conn (impl/-get-connection tx)]
      (sc/atomic conn
        (hold-lock conn)
        (run-transaction conn facts)))))
