From c7baf53c3fdf0982a0e83c25184d8a09a810f811 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 31 Aug 2019 12:07:58 +0100 Subject: Add value->sql-boolean to (guix-data-service model utils) --- guix-data-service/model/utils.scm | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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) -- cgit v1.2.3