guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/03: Add a function to fetch information about a table


From: Christopher Baines
Subject: 02/03: Add a function to fetch information about a table
Date: Sun, 29 Mar 2020 06:38:57 -0400 (EDT)

cbaines pushed a commit to branch master
in repository data-service.

commit bddf7a4240341426c504d4b756c5255e3403d3bc
Author: Christopher Baines <address@hidden>
AuthorDate: Sun Mar 29 10:29:08 2020 +0100

    Add a function to fetch information about a table
    
    Mostly so whether a field can contain NULL values can be determined.
---
 guix-data-service/model/utils.scm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/guix-data-service/model/utils.scm 
b/guix-data-service/model/utils.scm
index 11916e8..3b256f1 100644
--- a/guix-data-service/model/utils.scm
+++ b/guix-data-service/model/utils.scm
@@ -114,6 +114,21 @@
         '()
         lst))
 
+(define (table-schema conn table-name)
+  (map
+   (match-lambda
+     ((column_name data_type is_nullable)
+      (list column_name
+            data_type
+            (string=? is_nullable "YES"))))
+   (exec-query
+    conn
+    "
+SELECT column_name, data_type, is_nullable
+FROM information_schema.columns
+WHERE table_name = $1"
+    (list table-name))))
+
 (define* (insert-missing-data-and-return-all-ids
           conn
           table-name



reply via email to

[Prev in Thread] Current Thread [Next in Thread]