diff options
author | Christopher Baines <mail@cbaines.net> | 2020-03-29 10:29:08 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-03-29 10:29:08 +0100 |
commit | bddf7a4240341426c504d4b756c5255e3403d3bc (patch) | |
tree | 5d9b335d42b64aa0b50051420281c19fa48de01e /guix-data-service/model | |
parent | b30904e1afe426e7e38c8a43176efbfc656ab7e6 (diff) | |
download | data-service-bddf7a4240341426c504d4b756c5255e3403d3bc.tar data-service-bddf7a4240341426c504d4b756c5255e3403d3bc.tar.gz |
Add a function to fetch information about a table
Mostly so whether a field can contain NULL values can be determined.
Diffstat (limited to 'guix-data-service/model')
-rw-r--r-- | guix-data-service/model/utils.scm | 15 |
1 files changed, 15 insertions, 0 deletions
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 |