customConstraint method

ColumnBuilder<T> customConstraint(
  1. String constraint
)

Tells drift to write a custom constraint after this column definition when writing this column, for instance in a CREATE TABLE statement.

When no custom constraint is set, columns will be written like this: name TYPE NULLABILITY NATIVE_CONSTRAINTS. Native constraints are used to enforce that booleans are either 0 or 1 (e.g. field BOOLEAN NOT NULL CHECK (field in (0, 1)). Auto-Increment columns also make use of the native constraints, as do default values. If customConstraint has been called, the nullability information and native constraints will never be written. Instead, they will be replaced with the constraint. For example, if you call customConstraint('UNIQUE') on an IntColumn named "votes", the generated column definition will be votes INTEGER UNIQUE. Notice how the nullability information is lost - you'll have to include it in constraint if that is desired.

This can be used to implement constraints that drift does not (yet) support. If you've found a common use-case for this, it should be considered a limitation of drift itself. Please feel free to open an issue at https://github.com/simolus3/drift/issues/new to report that.

See also:

Implementation

ColumnBuilder<T> customConstraint(String constraint) => _isGenerated();