(define-module(database postgres-col-defs)#:export(column-name type-name type-options validate-def objectifiers stringifiers)#:use-module((srfi srfi-13)#:select(string-any))#:use-module((srfi srfi-14)#:select(char-set:whitespace))#:use-module((database postgres-types)#:select(type-objectifier type-stringifier)))
(define(column-name def)(car def))
(define(type-name def)(let((type-info(cdr def)))(if(pair? type-info)(car type-info)type-info)))
(define(type-options def)(let((type-info(cdr def)))(if(pair? type-info)(cdr type-info) '())))
(define (validate-def obj . typecheck)(or(and(pair? obj)(let((col-name(column-name obj)))(and(symbol? col-name)(not(string-any char-set:whitespace(symbol->string col-name)))))(pair?(cdr obj))(let((col-type(type-name obj)))(and(symbol? col-type)(or(null? typecheck)((car typecheck)col-type)))))(error "malformed def:" obj)))
(define(objectifiers defs)(map type-objectifier(map type-name defs)))
(define(stringifiers defs)(map type-stringifier(map type-name defs)))
