Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default columns #118

Open
broneill opened this issue Jan 13, 2023 · 1 comment
Open

Support default columns #118

broneill opened this issue Jan 13, 2023 · 1 comment

Comments

@broneill
Copy link
Member

When inserting a row, all columns must be specified. Define a Default annotation to allow columns to choose a default when no value is explicitly specified. Consider allowing a callback function to be provided which allows custom defaults to be selected by examining the other columns.

@broneill
Copy link
Member Author

broneill commented Jan 17, 2023

Defaults can be dangerous if the client schema doesn't match the server schema. Consider read-modify-write patterns. If a column is unset upon load due to a schema difference, then a store to the server might cause a default to be selected, destroying the original column value.

In those cases where the schema differs, and the client hasn't provided a column value, the default is rejected and an exception is thrown instead. This is safe, but it also defeats the utility of the default in the case that the client is storing a fresh record. Perhaps the rejection happens only when the client would replace an existing record. When inserting a new record, the default is safe because nothing is being replaced.

For consistency, this rule should be applied always, even when the schema matches: A column default is only selected when the column to be stored is missing, and no existing record exists which might be replaced. As a result, the "replace", "update" and "merge" operations would never support defaults. The "store" and "exchange" operations would conditionally support defaults, and the "insert" operation would always support defaults. It should be noted that "update" and "merge" already skip over unset columns, and so applying defaults is never a concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant