Add with-transaction.

* src/cuirass/database.scm (with-transaction): New macro.
This commit is contained in:
Mathieu Othacehe 2021-03-03 08:39:02 +01:00
parent a5346d615e
commit f5287dc11e
No known key found for this signature in database
GPG Key ID: 8354763531769CA6
2 changed files with 10 additions and 1 deletions

View File

@ -13,6 +13,7 @@
(eval put 'test-error 'scheme-indent-function 1)
(eval put 'make-parameter 'scheme-indent-function 1)
(eval put 'with-database 'scheme-indent-function 0)
(eval put 'with-transaction 'scheme-indent-function 0)
(texinfo-mode
(indent-tabs-mode)
(fill-column . 72)

View File

@ -107,7 +107,8 @@
;; Macros.
exec-query/bind
with-database
with-db-worker-thread))
with-db-worker-thread
with-transaction))
;; Maximum priority for a Build or Specification.
(define max-priority 9)
@ -273,6 +274,13 @@ DB is bound to the argument of that critical section: the database connection."
(number->string receive-timeout)
caller-name))))))
(define-syntax-rule (with-transaction exp ...)
"Evalute EXP within an SQL transaction."
(with-db-worker-thread db
(exec-query db "BEGIN TRANSACTION;")
exp ...
(exec-query db "COMMIT;")))
(define (read-sql-file file-name)
"Return a list of string containing SQL instructions from FILE-NAME."
(call-with-input-file file-name