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]
|
[db]
|
||||||
"TODO: document this interface.")
|
"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
|
(<eavt
|
||||||
[db pattern]
|
[db pattern]
|
||||||
"Search for datoms using the EAVT index.")
|
"Search for datoms using the EAVT index.")
|
||||||
|
@ -132,6 +138,10 @@
|
||||||
[db]
|
[db]
|
||||||
(inc (:current-tx 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?
|
;; TODO: use q for searching? Have q use this for searching for a single pattern?
|
||||||
(<eavt [db pattern]
|
(<eavt [db pattern]
|
||||||
(let [[e a v] pattern
|
(let [[e a v] pattern
|
||||||
|
@ -1077,8 +1087,8 @@
|
||||||
[conn tx-data]
|
[conn tx-data]
|
||||||
{:pre [(conn? conn)]}
|
{:pre [(conn? conn)]}
|
||||||
(let [db (db conn)] ;; TODO: be careful with swapping atoms.
|
(let [db (db conn)] ;; TODO: be careful with swapping atoms.
|
||||||
(s/in-transaction!
|
(in-transaction!
|
||||||
(:sqlite-connection db)
|
db
|
||||||
#(go-pair
|
#(go-pair
|
||||||
(let [report (<? (<with db tx-data))]
|
(let [report (<? (<with db tx-data))]
|
||||||
(reset! (:current-db conn) (:db-after report))
|
(reset! (:current-db conn) (:db-after report))
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
(defn in-transaction! [db chan-fn]
|
(defn in-transaction! [db chan-fn]
|
||||||
(go
|
(go
|
||||||
(try
|
(try
|
||||||
(<? (execute! db ["BEGIN TRANSACTION"]))
|
(<? (execute! db ["BEGIN EXCLUSIVE TRANSACTION"]))
|
||||||
(let [[v e] (<! (chan-fn))]
|
(let [[v e] (<! (chan-fn))]
|
||||||
(if v
|
(if v
|
||||||
(do
|
(do
|
||||||
|
|
Loading…
Reference in a new issue