mirror of
git://git.savannah.gnu.org/guix/data-service.git
synced 2023-12-14 03:23:03 +01:00
Add a with-postgresql-transaction procedure
To help with running tests.
This commit is contained in:
parent
a171287f27
commit
051962b54d
|
@ -17,7 +17,8 @@
|
|||
|
||||
(define-module (guix-data-service database)
|
||||
#:use-module (squee)
|
||||
#:export (with-postgresql-connection))
|
||||
#:export (with-postgresql-connection
|
||||
with-postgresql-transaction))
|
||||
|
||||
;; TODO This isn't exported for some reason
|
||||
(define pg-conn-finish
|
||||
|
@ -38,3 +39,16 @@
|
|||
(lambda (key . args)
|
||||
(pg-conn-finish conn)))))
|
||||
|
||||
(define* (with-postgresql-transaction conn f
|
||||
#:key always-rollback?)
|
||||
(exec-query conn "BEGIN;")
|
||||
|
||||
(with-throw-handler #t
|
||||
(lambda ()
|
||||
(let ((result (f conn)))
|
||||
(exec-query conn (if always-rollback?
|
||||
"ROLLBACK;"
|
||||
"COMMIT;"))
|
||||
result))
|
||||
(lambda (key . args)
|
||||
(exec-query conn "ROLLBACK;"))))
|
||||
|
|
Loading…
Reference in a new issue