Closed LiberalArtist closed 6 years ago
I noticed while working on this that the functions from "private/dynamic.rkt" don't currently have tests. I'd be happy to try writing some.
Also, just to put it somewhere for posterity, here is a little macro I've been experimenting with using on top of make-values*-table-expr-ast
:
(define-syntax-parser for/insert-statement
[(_ (#:into name-ast-form
for-clause ...)
body-or-break ...
#:set
[column-ident-form
scalar-expr-form] ...)
#`(insert
#:into name-ast-form
#:columns column-ident-form ...
#:from
(TableExpr:AST
,(make-values*-table-expr-ast
(for/fold/derived #,this-syntax
([so-far '()])
(for-clause ...)
body-or-break ...
(cons (list (scalar-expr-qq scalar-expr-form)
...)
so-far)))))])
(for/insert-statement
(#:into somewhere
[row '(["apples" 1 "standard"]
["bananas" 5 "organic"]
["cranberries" 50 "canned"])])
(match-define (list name num type)
row)
#:set
[name ,name]
[num ,num]
[type ,type])
Thanks!
This change makes it possible to construct INSERT statements for dynamic numbers of rows, for example.
Other changes:
TableExpr
syntax class raises a syntax error if thevalues*
form is used with rows that are not all of the same length.scalar-expr-ast?
predicate to recognize values that satisfyscalar:unquote?
. Before this change,value->scalar-expr-ast
would break its own contract (e.g. with(value->scalar-expr-ast "apples")
.Closes https://github.com/rmculpepper/sql/issues/9