SqlDeclare.fromJson constructor

SqlDeclare.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 SqlDeclare.fromJson(Object? json_) {
  final json = json_ is Map
      ? _spec.fields.map((f) => json_[f.label]).toList(growable: false)
      : json_;
  return switch (json) {
    [
      final name,
      final binary,
      final sensitive,
      final scroll,
      final hold,
      final query
    ] ||
    (
      final name,
      final binary,
      final sensitive,
      final scroll,
      final hold,
      final query
    ) =>
      SqlDeclare(
        name: Ident.fromJson(name),
        binary: binary! as bool,
        sensitive: Option.fromJson(sensitive, (some) => some! as bool).value,
        scroll: Option.fromJson(scroll, (some) => some! as bool).value,
        hold: Option.fromJson(hold, (some) => some! as bool).value,
        query: SqlQuery.fromJson(query),
      ),
    _ => throw Exception('Invalid JSON $json_')
  };
}