diff options
author | Christopher Baines <mail@cbaines.net> | 2019-11-30 10:53:13 +0000 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2019-11-30 10:53:13 +0000 |
commit | 0fa747e404b1baebf3c733a1554959e122c7ab25 (patch) | |
tree | ab38478d84ad1cd08ed54447be4a05746fc5abf9 | |
parent | b6194e7b3d32d99ff4cd9f93f1438afaf489ab46 (diff) | |
download | data-service-0fa747e404b1baebf3c733a1554959e122c7ab25.tar data-service-0fa747e404b1baebf3c733a1554959e122c7ab25.tar.gz |
Support handling jsonb in insert-missing-data-and-return-all-ids
-rw-r--r-- | guix-data-service/model/utils.scm | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/guix-data-service/model/utils.scm b/guix-data-service/model/utils.scm index a1cd432..c17224b 100644 --- a/guix-data-service/model/utils.scm +++ b/guix-data-service/model/utils.scm @@ -106,6 +106,9 @@ (if b "TRUE" "FALSE")) ((? null?) "NULL") + ((cast . value) + (string-append + (value->sql value) "::" cast)) (v (error (simple-format #f "error: unknown type for value: ~A" v))))) @@ -161,6 +164,15 @@ ", ") " RETURNING id")) + (define (format-json json) + ;; PostgreSQL formats JSON strings differently to guile-json, so use + ;; PostgreSQL to do the formatting + (caar + (exec-query + conn + (string-append + "SELECT $STR$" json "$STR$::jsonb")))) + (define (normalise-values data) (map (match-lambda ((? boolean? b) @@ -174,6 +186,10 @@ ((? null? n) ;; exec-query-with-null-handling specifies NULL values as '() n) + ((cast . value) + (if (string=? cast "jsonb") + (format-json value) + value)) (unknown (error (simple-format #f "normalise-values: error: ~A\n" unknown)))) data)) |