From bddf7a4240341426c504d4b756c5255e3403d3bc Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 29 Mar 2020 10:29:08 +0100 Subject: 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(+) (limited to 'guix-data-service/model/utils.scm') 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 -- cgit v1.2.3