This PR extends the syntax of the sqlair DSL to support bulk INSERT SQL DML statements. This will allow the user to write statments such as INSERT INTO person (name, id) VALUES ($Person.*), or INSERT INTO person (*) VALUES ($Person.*). This will allow for a more concise syntax when inserting multiple fields of structs.
We take advantage of the go/sql libraries support of named parameters to ensure the order of the inputs can be kept consistent in the complete stage. We name the parameters with their type and tag name. When we extract the parameter values from the structs at the complete stage we can use this information to match each value to to the corresponding input position.
We only parse the column and value information around the VALUES keyword, the INSERT INTO can be ignored. Specifically, this transforms the query as follows:
This PR extends the syntax of the sqlair DSL to support bulk
INSERT
SQL DML statements. This will allow the user to write statments such asINSERT INTO person (name, id) VALUES ($Person.*)
, orINSERT INTO person (*) VALUES ($Person.*)
. This will allow for a more concise syntax when inserting multiple fields of structs.We take advantage of the go/sql libraries support of named parameters to ensure the order of the inputs can be kept consistent in the complete stage. We name the parameters with their type and tag name. When we extract the parameter values from the structs at the complete stage we can use this information to match each value to to the corresponding input position.
We only parse the column and value information around the
VALUES
keyword, theINSERT INTO
can be ignored. Specifically, this transforms the query as follows:Note that the final two are of the same form but the last one uses multiple types and renames the columns.
The parsing resembles that of output expressions. Where they use the keyword
AS
here we use the keywordVALUES
.