Prisma Client Dart is an auto-generated type-safe ORM. It uses Prisma Engine as the data access layer and is as consistent as possible with the Prisma Client JS/TS APIs.
Sale.fromJson(s)
factory Sale.fromJson(Map json) => Sale(
id: json['id'],
quantity: json['quantity'],
// eg. quantity: double.tryParse("${json['quantity']}")
// this way it can convert String, int, num to double so you don't have to worry about the api data type
unitPrice: json['unit_price'],
createdAt: switch (json['created_at']) {
DateTime value => value,
String value => DateTime.parse(value),
_ => json['created_at']
},
);
in this example the Map json data is coming from an api but the quantity is either double or int but the model's quantity field only accepts double. can we parse and cast it to double or are there any other available methods to deal with. i could cast every field but it would be if we have this feature inside the model instead of all over my project
in this example the
Map json
data is coming from an api but thequantity
is eitherdouble
orint
but the model's quantity field only acceptsdouble
. can we parse and cast it todouble
or are there any other available methods to deal with. i could cast every field but it would be if we have this feature inside the model instead of all over my project