drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[FEATURE]: Add findFirstOrThrow and findUniqueOrThrow to relational queries

Open jgoux opened this issue 2 years ago • 0 comments

Describe what you want

These methods are super helpful in Prisma to avoid boilerplate code when we want to fetch an entity that we know should exist, which is very often.

Prisma doc about it: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference/#findfirstorthrow

One thing to note is the ability to throw a custom error per table/model: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference/#throw-a-custom-error-per-model-and-operation-if-record-is-not-found This is great for raising domain errors instead of generic database errors.

I'm unsure where we would map the definition of custom errors in Drizzle, so suggestions are welcome!

jgoux avatar Jun 09 '23 09:06 jgoux