drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Add findFirstOrThrow() method

Open
#889 11 comments 30 reactions 0 assignees View on GitHub
enhancement rqb
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

I've been integrating drizzle into my codebase (replacing Prisma) and so far I've had to write hundreds of snippets like this:

```ts
const feedTopic = await db.query.feedTopic.findFirst({
where: eq(schema.feedTopic.id, input.id)
})
if (!feedTopic) throw new Error('Feed topic not found')
return feedTopic
```

To save users from (mild) carpal tunnel I suggest simply adding a `findFirstOrThrow` method (like Prisma has)

The above becomes this:
```ts
return db.query.feedTopic.findFirstOrThrow({
where: eq(schema.feedTopic.id, input.id)
})
```

Bikeshedding, but it would be a nice little DX improvement.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.