We let users work with a variable as if it has multiple types.
For example:
Our schema:
-- @create_some_table
CREATE TABLE IF NOT EXISTS `some_table` (
`id` int NOT NULL,
`some_field` TEXT NULL,
`some_field_2` TEXT NULL DEFAULT NULL
)
Our query
-- @create
INSERT INTO some_table (
some_field,
some_field_2
) VALUES (
@some_field,
case when @some_field = 'TEST' then 'A' else NULL end
);
And in this case it generates:
let create db ~some_field =
let set_params stmt =
let p = T.start_params stmt (19) in
begin match some_field with None -> T.set_param_null p | Some v -> T.set_param_Text p v end;
T.set_param_Text p some_field;
T.finish_params p
in
T.execute db ("INSERT INTO some_table (\n\
some_field,
some_field_2
) VALUES (
?,\n\
?,\n\
case when ? like 'TEST' then 'A' else NULL end,\n\
)") set_params
We let users work with a variable as if it has multiple types.
For example:
Our schema:
Our query
And in this case it generates:
This PR fixes it.