aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/datastore/sqlite.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix-build-coordinator/datastore/sqlite.scm')
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm24
1 files changed, 24 insertions, 0 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 159124c..6a49f19 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -11,6 +11,7 @@
#:use-module (guix-build-coordinator datastore abstract)
#:export (sqlite-datastore
datastore-update
+ datastore-call-with-transaction
datastore-store-derivation
datastore-list-related-derivations-with-no-build-for-outputs
datastore-list-failed-builds-with-blocking-count
@@ -131,6 +132,29 @@
result))
(thunk)))
+(define* (datastore-call-with-transaction datastore thunk
+ #:key readonly?)
+ (call-with-worker-thread
+ (slot-ref datastore (if readonly?
+ 'worker-reader-thread-channel
+ 'worker-writer-thread-channel))
+ (lambda (db)
+ (sqlite-exec db "BEGIN TRANSACTION;")
+ (with-exception-handler
+ (lambda (exn)
+ (simple-format (current-error-port)
+ "error: sqlite: ~A\n"
+ exn)
+ (sqlite-exec db "ROLLBACK TRANSACTION;")
+ (raise-exception exn))
+ (lambda ()
+ (call-with-values
+ thunk
+ (lambda vals
+ (sqlite-exec db "COMMIT TRANSACTION;")
+ (apply values vals))))
+ #:unwind? #t))))
+
(define-method (datastore-find-agent
(datastore <sqlite-datastore>)
uuid)