how to fix prisma query where 1=1

I have this query const user = await prisma.user.findFirst({ where: { id: session?.user.id } });, which seems to translate to
prisma:query SELECT `main`.`User`.`id`, `main`.`User`.`name`, `main`.`User`.`email`, `main`.`User`.`emailVerified`, `main`.`User`.`image` FROM `main`.`User` WHERE 1=1 LIMIT ? OFFSET ?
prisma:query SELECT `main`.`User`.`id`, `main`.`User`.`name`, `main`.`User`.`email`, `main`.`User`.`emailVerified`, `main`.`User`.`image` FROM `main`.`User` WHERE 1=1 LIMIT ? OFFSET ?
This guarantees that I return an entry even if id is undefined, which I don't want. How do i fix this?
12 Replies
alan
alanOP•2y ago
it looks like this is also an issue: https://github.com/prisma/prisma/issues/5149 a "design decision" poohheh
GitHub
findFirst with undefined value shouldn't return data · Issue #514...
Bug description Calling findFirst with an undefined in where filter still returns data. This is not intuitive. How to reproduce Deploy this schema with yarn prisma db push --preview-feature datasou...
Aland
Aland•2y ago
I think it's fixed now is it? But i don't understand why somebody would make that "design decision"
Neto
Neto•2y ago
javascript serialization
Neto
Neto•2y ago
Aland
Aland•2y ago
Prisma should use Zod in their source code, I stopped trusting JS a long time ago...
Neto
Neto•2y ago
why? problem is js serialization if you ever talk about superjson, the perf would tank prisma even more
Aland
Aland•2y ago
Well there are many the other weird behavior with null/undefined in JS Prisma is already considered "too slow" many people are jumping on drizzle so, i think adding a couple more packages won't be that bad 😅
Neto
Neto•2y ago
50x slower isnt worth for that
Neto
Neto•2y ago
plus superjson is the middleman in the whole process prisma client calls the prisma rust biding its just a javascript serialization issue
Aland
Aland•2y ago
man it hurts to see that performance hit, even with bun!
Neto
Neto•2y ago
Superjson wasn't made to be fast
Aland
Aland•2y ago
trpc uses it, i think they have no option
Want results from more Discord servers?
Add your server