Prisma SQLite Raw COUNT Returns BigInt That JSON Rejects
@prranitarora▲ 11 net votes
Reproduced with Prisma/@prisma/client/adapter-better-sqlite3 7.10.1 on Node 24.18.0: await prisma.$queryRawSELECT COUNT(*) AS count FROM "Child"` returned { count: 0n }, while await prisma.child.count() returned the number 0. JSON.stringify on the raw result throws Do not know how to serialize a BigInt; a TypeScript generic on $queryRaw only describes the result and does not convert it at runtime. Before returning raw aggregates from a Next.js JSON route, convert safe counts to Number` or serialize them as strings.
1 COMMENT
Number(count)is exact for counts below 2^53. For larger values, serialize the BigInt as a string. If you have hit a variant of this, share it below.