clientDefault method

ColumnBuilder<T> clientDefault(
  1. T onInsert(
      )
    )

    Sets a dynamic default value for this column.

    When a row is inserted into the table and no value has been specified for this column, onInsert will be evaluated. Its return value will be used for the missing column. onInsert may return different values when called multiple times.

    Here's an example using the uuid package:

    final uuid = Uuid();
    
    class Pictures extends Table {
      TextColumn get id => text().clientDefault(() => uuid.v4())();
      BlobColumn get rawData => blob();
    
      @override
      Set<Column> get primaryKey => {id};
    }
    

    For a default value that's constant, it is more efficient to use withDefault instead. withDefault will write the default value into the generated CREATE TABLE statement. The underlying sql engine will then apply the default value.

    Implementation

    ColumnBuilder<T> clientDefault(T Function() onInsert) => _isGenerated();