3 utils
(require datadef/lib/utils) | package: datadef |
struct
(struct datadef (parts query-string result-func sql-select) #:transparent) parts : (listof datadef-part?) query-string : string?
result-func :
(->i () (#:where [query-where (or/c false? string?)] #:order-by [query-order-by (or/c false? string?)] #:group-by [query-group-by (or/c false? string?)] #:limit [query-limit (or/c false? integer?)] #:mutable [mutable boolean?] #:json [json? boolean?]) #:rest [query-args (listof any/c)] [result (or/c list? vector? hash? false?)]) sql-select : sql-select?
Datadef struct holding information about a datadef with functions to
query the database and return a properly formatted data structure.
struct
(struct datadef-part (col key mock-data type) #:transparent) col : (or/c symbol? string?) key : (or/c symbol? (list/c symbol? string?)) mock-data : (or/c false? list?) type : (or/c symbol? false?)
procedure
(parse-datadef-parts list-of-dd case-thunk keys-strip-prefix? keep-dot-prefix?) → (listof datadef-part?) list-of-dd : list? case-thunk : (-> (or/c symbol? (list/c symbol? string?)) (or/c symbol? (list/c symbol? string?))) keys-strip-prefix? : boolean? keep-dot-prefix? : boolean?
syntax
(define-conversion predicate procedure)
predicate : symbol?
procedure : (-> any/c any)
procedure
(build-select-query [ str #:columns columns #:from tables #:where where #:order-by order-by #:group-by group-by #:limit limit]) → string? str : string? = "" columns : (or/c string? (listof any/c)) = #f tables : (or/c false? string?) = #f where : (or/c false? string?) = #f order-by : (or/c false? string?) = #f group-by : (or/c false? string?) = #f limit : (or/c false? integer?) = #f
Creates a query string based on provided arguments.
#:columns and #:from must be provided if initial string
(str) is not supplied.
If str is provided, #:columns and #:from must
not be supplied.
#:columns can be a string or a datadef.
procedure
(format-query-string str) → (listof string?)
str : string?
Accepts a query string and returns a list of strings, which can be used in scribble
documentation.
procedure
(get-formatted-result datadef-part-list iter-func rows json? #:single-ret-val single-ret-val #:single-ret-val/f single-ret-val/f #:ret-type ret-type [ #:custom-iter-func custom-iter-func]) → (or/c list? hash? vector? false?) datadef-part-list : (listof datadef-part?) iter-func : (-> (listof datadef-part?) vector? boolean? (or/c vector? list? hash?)) rows : (listof vector?) json? : boolean? single-ret-val : boolean? single-ret-val/f : boolean? ret-type : procedure?
custom-iter-func : (or/c false?(-> (listof datadef-part?) vector? boolean? (or/c vector? list? hash?))) = #f
Formats db rows and returns a result based on the datadef’s return type.
procedure
(get-iter-func ret-type)
→ (-> (listof datadef-part?) vector? boolean? (or/c vector? list? hash?)) ret-type : procedure?
Returns appropriate function for iterating over db rows based on the given
datadef’s return type.
procedure
(get-mock-data datadef-part-list position) → any
datadef-part-list : (or/c (listof datadef-part?) (listof any/c))
position :
(or/c (listof (or/c false? integer?)) (or/c false? integer?))
parameter
(datadef:ensure-json-func datadef:ensure-json-func) → void? datadef:ensure-json-func : procedure?
Parameter holding the function that will be used when
#:json #t is specified in the datadef result function.