Extract out some database functionality to another module

This commit is contained in:
Christopher Baines 2019-04-14 10:04:19 +01:00
parent b352b5040a
commit 2e45bb0696
6 changed files with 54 additions and 27 deletions

View file

@ -21,30 +21,14 @@
#:use-module (web http)
#:use-module (web request)
#:use-module (web uri)
#:use-module (squee)
#:use-module (fibers web server)
#:use-module (guix-data-service database)
#:use-module (guix-data-service web controller)
#:use-module (guix-data-service web util)
#:export (start-guix-data-service-web-server))
;; TODO This isn't exported for some reason
(define pg-conn-finish
(@@ (squee) pg-conn-finish))
(define (with-postgresql-connection paramstring f)
(let* ((conn (connect-to-postgres-paramstring paramstring)))
(with-throw-handler
#t
(lambda ()
(let ((result (f conn)))
(pg-conn-finish conn)
result))
(lambda (key . args)
(pg-conn-finish conn)))))
(define (run-controller controller request body)
(with-postgresql-connection
"dbname=guix_data_service"
(lambda (conn)
((controller request body conn)
(cons (request-method request)