drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: method `.single()` for select query

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

Description

### Feature hasn't been suggested before.

- [x] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

Hello Drizzle Team,

I suggest method `.single()`

A method that returns a single row is very useful. as you can see in the image I only want to get a single row from the table. with `.limit(1)` I know for sure that the output has `<= 1` items. but when I access it I have to keep using `results[0]` or shorthand it `const [result] = await db...` however it loses the type feature of typescript because `results[0]` (`result`) is recognized by typescript as `Row` while it can be `undefined`

![Image](https://github.com/user-attachments/assets/ee236818-3fc6-434e-8141-32b3a8d48eac)

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.