ColumnSnapshot.fromMap constructor

ColumnSnapshot.fromMap(
  1. String name,
  2. Map<String, dynamic> data
)

Creates a column snapshot from a map.

The default is read from default, which is what the snapshot format calls it; ColumnInfo calls the same thing defaultValue.

Implementation

factory ColumnSnapshot.fromMap(String name, Map<String, dynamic> data) {
  _checkKeys(
    data,
    context: 'column "$name"',
    requiredKeys: const {'name', 'type', 'primaryKey', 'isNullable'},
    optionalKeys: const {'autoIncrement', 'default', 'foreignKey'},
  );
  return ColumnSnapshot(
    name: name,
    type: data['type'] as String,
    isNullable: data['isNullable'] as bool,
    primaryKey: data['primaryKey'] as bool,
    autoIncrement: data['autoIncrement'] as bool? ?? false,
    defaultValue: data['default'] as String?,
    foreignKey: switch (data['foreignKey']) {
      final Map<String, dynamic> data => ForeignKeySnapshotRef.fromMap(data),
      _ => null,
    },
  );
}