I'm trying to fetch data from database and this is my prisma model:
model instant_reports {
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
created_at DateTime?
updated_at DateTime?
deleted_at DateTime?
timestamp BigInt?
client_id BigInt?
uniq_users BigInt?
}
So when i fetch data like this
prismaService.instant_reports.findMany({
skip: 0,
take: 30,
});
It throws error
TypeError: Do not know how to serialize a BigInt at JSON.stringify(<anonymous>)
And i don't even know how to deal with it, is there way to change data handler in findMany method?
If there is no rows in instant_reports so it gives me empty array without error, so the problem is in data with BigInt type
It worked for me. Add this code to the beginning of yours.
BigInt.prototype.toJSON = function () {
const int = Number.parseInt(this.toString());
return int ?? this.toString();
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With