Skip to content

implement DEFAULT, and default syntax {expr}??#189

Merged
jongleb merged 2 commits intoygrek:masterfrom
jongleb:with-default-insert-master-2
Apr 29, 2025
Merged

implement DEFAULT, and default syntax {expr}??#189
jongleb merged 2 commits intoygrek:masterfrom
jongleb:with-default-insert-master-2

Conversation

@jongleb
Copy link
Copy Markdown
Collaborator

@jongleb jongleb commented Apr 28, 2025

Description

This PR adds support to DEFAULT and special {expr}?? syntax that generates a regular option when insert.

The main motivation is to not make DEFAULT part of regular expr, because in sql this DEFAULT is only available on insert and update.

That is, writing like this will not be valid and an error will be caught:

SELECT ... WHERE {@x + 2}??

On the contrary, using this on insert/update will just generate option, and if there is no data, DEFAULT will be generated, similar to how it works for filtering and skipping {expr}? syntax.

example taken from tests:

INSERT INTO `registration_feedbacks`
SET
  `user_message` = { CONCAT(@user_message, '22222') }??,
  `grant_types` = { @grant_types { A {'2'} | B {'2'} } }??;

The generated result:

T.execute db ("INSERT INTO `registration_feedbacks`\n\
SET\n\
  `user_message` = " ^ (match user_message with Some _ -> " ( " ^ " CONCAT(" ^ "?" ^ ", '22222') " ^ " ) " | None -> " DEFAULT ") ^ ",\n\
  `grant_types` = " ^ (match grant_types with Some (grant_types) -> " ( " ^ " " ^ (match grant_types with `A -> "'2'" | `B -> "'2'") ^ " " ^ " ) " | None -> " DEFAULT ")) set_params

@jongleb jongleb changed the title implement DEFAULT, and default syntax {expr}?? implement DEFAULT, and default syntax {expr}?? Apr 28, 2025
@jongleb jongleb marked this pull request as ready for review April 28, 2025 21:29
@jongleb jongleb merged commit 561d690 into ygrek:master Apr 29, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant