ColumnOperation class abstract
A single declarative transformation applied to one raw entity map during a schema migration.
Use the factory shorthands for the common cases:
ColumnOperation.add('priority', defaultValue: 0);
ColumnOperation.add('slug', compute: (row) => (row['title'] as String).toLowerCase());
ColumnOperation.rename('title', to: 'name');
ColumnOperation.remove('legacyField');
ColumnOperation.transform('createdAt', (value, row) => DateTime.parse(value as String).toUtc().toIso8601String());
ColumnOperation.row((row) => {...row, 'fullName': '${row['first']} ${row['last']}'});
Implement this class directly for reusable custom operations.
Constructors
- ColumnOperation()
-
const
-
ColumnOperation.add(String name, {Object? defaultValue, Object? compute(Map<
String, dynamic> row)?, bool overwrite = false, String? sqlType, String? sqlExpression}) -
Adds a column named
name.factory - ColumnOperation.remove(String name)
-
Removes the column named
nameif present.factory - ColumnOperation.rename(String from, {required String to})
-
Moves the value under
fromto the keyto. Rows withoutfromare left unchanged.factory -
ColumnOperation.row(Map<
String, dynamic> transform(Map<String, dynamic> row), {List<String> ? sql}) -
Applies an arbitrary whole-row rewrite. The returned map replaces the
row entirely, so spread the input to keep untouched columns:
ColumnOperation.row((row) => {...row, 'v': 2}).factory -
ColumnOperation.transform(String name, Object? transform(Object? value, Map<
String, dynamic> row), {bool applyIfAbsent = false, String? sqlExpression}) -
Replaces the value of
namewithtransform(value, row).factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
apply(
Map< String, dynamic> row) → Map<String, dynamic> -
Applies this operation to
rowand returns the resulting row. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited