aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/database.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2021-06-16 13:43:32 +0100
committerChristopher Baines <mail@cbaines.net>2021-06-16 13:44:00 +0100
commit0dc05982cde052c985bb440dc026cbe3334ee50b (patch)
treeeaeedc6f2763488bf8b354824b82bcf9f4bc89fe /guix-data-service/database.scm
parent673d762e681568fb5c5598d456df8312e8d40cae (diff)
downloaddata-service-0dc05982cde052c985bb440dc026cbe3334ee50b.tar
data-service-0dc05982cde052c985bb440dc026cbe3334ee50b.tar.gz
Try to adapt the PostgreSQL paramstring to use with sqitch
Diffstat (limited to 'guix-data-service/database.scm')
-rw-r--r--guix-data-service/database.scm20
1 files changed, 19 insertions, 1 deletions
diff --git a/guix-data-service/database.scm b/guix-data-service/database.scm
index 546c678..1204bb4 100644
--- a/guix-data-service/database.scm
+++ b/guix-data-service/database.scm
@@ -21,7 +21,9 @@
#:use-module (ice-9 threads)
#:use-module (squee)
#:use-module (guix-data-service config)
- #:export (with-postgresql-connection
+ #:export (get-database-config
+
+ with-postgresql-connection
with-postgresql-connection-per-thread
with-thread-postgresql-connection
@@ -39,6 +41,22 @@
(define pg-conn-finish
(@@ (squee) pg-conn-finish))
+(define (paramstring->alist s)
+ (map
+ (lambda (param)
+ (match (string-split param #\=)
+ ((key val)
+ (cons key val))))
+ (string-split s #\space)))
+
+(define (get-database-config)
+ (let ((paramstring (getenv "GUIX_DATA_SERVICE_DATABASE_PARAMSTRING")))
+ (if paramstring
+ (paramstring->alist paramstring)
+ `(("dbname" . ,(%config 'database-name))
+ ("user" . ,(%config 'database-user))
+ ("host" . ,(%config 'database-host))))))
+
(define (open-postgresql-connection name statement-timeout)
(define paramstring
(string-append