Tupl icon indicating copy to clipboard operation
Tupl copied to clipboard

Support default columns

Open broneill opened this issue 2 years ago • 1 comments

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 avatar Jan 13 '23 18:01 broneill

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.

broneill avatar Jan 17 '23 17:01 broneill