AlterColumnOperation.fromJson constructor

AlterColumnOperation.fromJson(
  1. Object? json_
)

Returns a new instance from a JSON value. May throw if the value does not have the expected structure.

Implementation

factory AlterColumnOperation.fromJson(Object? json_) {
  Object? json = json_;
  if (json is Map) {
    final MapEntry(:key, :value) =
        json.entries.firstWhere((e) => e.key != 'runtimeType');
    json = (
      key is int ? key : _spec.cases.indexWhere((c) => c.label == key),
      value,
    );
  }
  return switch (json) {
    (0, null) || [0, null] => const AlterColumnOperationSetNotNull(),
    (1, null) || [1, null] => const AlterColumnOperationDropNotNull(),
    (2, null) || [2, null] => const AlterColumnOperationDropDefault(),
    (3, final value) ||
    [3, final value] =>
      AlterColumnOperationSetDataType(SetDataType.fromJson(value)),
    (4, final value) ||
    [4, final value] =>
      AlterColumnOperationSetDefault(SetDefault.fromJson(value)),
    _ => throw Exception('Invalid JSON $json_'),
  };
}