I am using the faunadb_http package and I want the value to be returned null (or any value) from Fauna DB if the field does not exist in the collection. I am just not able to figure out what should I put in the default parameter of this package so that I get that back as the default value.
I tried the following two variations of default parameter and I get “Value not found at path” error for first and just an empty Object {} for second.
'itemPrice': Select(["data", "itemPrice"], Var("postDoc"), default_: null),
'itemLocation': Select(["data", "itemLocation"], Var("postDoc"), default_: Obj({})),
Can somebody help me understand what should I be passing to default_ so that I get a String or Int as a response back.
This is the code for the Select class from the package
@JsonSerializable()
class Select extends Expr {
@JsonKey(name: 'select')
final Object path;
final Expr from;
@JsonKey(name: 'default', disallowNullValue: true, includeIfNull: false)
final Expr? default_;
Select(this.path, this.from, {this.default_});
factory Select.fromJson(Map<String, dynamic> json) => _$SelectFromJson(json);
@override
Map<String, dynamic> toJson() => _$SelectToJson(this);
}
And this is for the Expr class
class Expr {
static Object? wrap_value(dynamic value) {
if (value is List) {
return wrap_values(value);
} else if (value is Map<String, dynamic>) {
return Obj(value);
} else if (value is DateTime) {
return Time(value.toUtc().toIso8601String());
} else {
return value;
}
}
static Object? wrap_values(Object? data) {
if (data == null) return null;
if (data is List) {
return List.generate(
data.length,
(e) => wrap_value(data[e]),
growable: false,
);
} else if (data is Map<String, dynamic>) {
return data.map(
(key, value) => MapEntry(key, wrap_value(value)),
);
}
return data;
}
Expr();
factory Expr.fromJson(Map<String, dynamic> json) => _$ExprFromJson(json);
Map<String, dynamic> toJson() => _$ExprToJson(this);
@override
String toString() {
return json.encode(this).toString();
}
}