Follow-up: lift in-transaction! to DB; make transactions exclusive.
This commit is contained in:
parent
f408cfd314
commit
52af06ce28
2 changed files with 22 additions and 12 deletions
|
@ -67,6 +67,12 @@
|
|||
[db]
|
||||
"TODO: document this interface.")
|
||||
|
||||
(in-transaction!
|
||||
[db chan-fn]
|
||||
"Evaluate the given pair-chan `chan-fn` in an exclusive transaction. If it returns non-nil,
|
||||
commit the transaction; otherwise, rollback the transaction. Returns a pair-chan resolving to
|
||||
the pair-chan returned by `chan-fn`.")
|
||||
|
||||
(<eavt
|
||||
[db pattern]
|
||||
"Search for datoms using the EAVT index.")
|
||||
|
@ -132,6 +138,10 @@
|
|||
[db]
|
||||
(inc (:current-tx db)))
|
||||
|
||||
(in-transaction! [db chan-fn]
|
||||
(s/in-transaction!
|
||||
(:sqlite-connection db) chan-fn))
|
||||
|
||||
;; TODO: use q for searching? Have q use this for searching for a single pattern?
|
||||
(<eavt [db pattern]
|
||||
(let [[e a v] pattern
|
||||
|
@ -1077,8 +1087,8 @@
|
|||
[conn tx-data]
|
||||
{:pre [(conn? conn)]}
|
||||
(let [db (db conn)] ;; TODO: be careful with swapping atoms.
|
||||
(s/in-transaction!
|
||||
(:sqlite-connection db)
|
||||
(in-transaction!
|
||||
db
|
||||
#(go-pair
|
||||
(let [report (<? (<with db tx-data))]
|
||||
(reset! (:current-db conn) (:db-after report))
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
(defn in-transaction! [db chan-fn]
|
||||
(go
|
||||
(try
|
||||
(<? (execute! db ["BEGIN TRANSACTION"]))
|
||||
(<? (execute! db ["BEGIN EXCLUSIVE TRANSACTION"]))
|
||||
(let [[v e] (<! (chan-fn))]
|
||||
(if v
|
||||
(do
|
||||
|
|
Loading…
Reference in a new issue