aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-08-31 12:07:58 +0100
committerChristopher Baines <mail@cbaines.net>2019-08-31 12:07:58 +0100
commitc7baf53c3fdf0982a0e83c25184d8a09a810f811 (patch)
treea482592c2d3d87ba524830d834741c4e12959e9a
parent66df42ae4fddb7ac1ae6d2edc1faaf446457270b (diff)
downloaddata-service-c7baf53c3fdf0982a0e83c25184d8a09a810f811.tar
data-service-c7baf53c3fdf0982a0e83c25184d8a09a810f811.tar.gz
Add value->sql-boolean to (guix-data-service model utils)
-rw-r--r--guix-data-service/model/utils.scm12
1 files changed, 12 insertions, 0 deletions
diff --git a/guix-data-service/model/utils.scm b/guix-data-service/model/utils.scm
index 0ce9fea..a7443d6 100644
--- a/guix-data-service/model/utils.scm
+++ b/guix-data-service/model/utils.scm
@@ -1,10 +1,12 @@
(define-module (guix-data-service model utils)
#:use-module (srfi srfi-1)
+ #:use-module (ice-9 match)
#:use-module (ice-9 vlist)
#:use-module (ice-9 receive)
#:use-module (squee)
#:export (quote-string
value->quoted-string-or-null
+ value->sql-boolean
non-empty-string-or-false
exec-query->vhash
two-lists->vhash
@@ -19,6 +21,16 @@
(string-append "$STR$" value "$STR$")
"NULL"))
+(define (value->sql-boolean v)
+ (match v
+ ((? boolean? x)
+ (if x "TRUE" "FALSE"))
+ ((? string? x)
+ (if (or (string=? x "t")
+ (string=? x "TRUE"))
+ "TRUE"
+ "FALSE"))))
+
(define (non-empty-string-or-false s)
(if (string? s)
(if (string-null? s)