SetExpr.fromJson constructor
SetExpr.fromJson(
- Object? json_
Returns a new instance from a JSON value. May throw if the value does not have the expected structure.
Implementation
factory SetExpr.fromJson(Object? json_) {
Object? json = json_;
if (json is Map) {
final rt = json['runtimeType'];
if (rt is String) {
json = (
const [
'SqlSelectRef',
'SqlQueryRef',
'SetOperation',
'Values',
'SqlInsertRef',
'SqlUpdateRef',
'Table'
].indexOf(rt),
json
);
} else {
final MapEntry(:key, :value) = json.entries.first;
json = (key is int ? key : int.parse(key! as String), value);
}
}
return switch (json) {
(0, final value) || [0, final value] => SqlSelectRef.fromJson(value),
(1, final value) || [1, final value] => SqlQueryRef.fromJson(value),
(2, final value) || [2, final value] => SetOperation.fromJson(value),
(3, final value) || [3, final value] => Values.fromJson(value),
(4, final value) || [4, final value] => SqlInsertRef.fromJson(value),
(5, final value) || [5, final value] => SqlUpdateRef.fromJson(value),
(6, final value) || [6, final value] => Table.fromJson(value),
_ => throw Exception('Invalid JSON $json_'),
};
}