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

[FEATURE]: `limit(1)` change type to `T | undefined`

Open oscartbeaumont opened this issue 2 years ago • 0 comments

Describe want to want

Currently when do a query similar to the following the return type is T[].

const result: User[] = await db
    .select()
    .from(users)
    .where(eq(users.email, email))
    .limit(1);
const user: User | undefined = result?.[0];

It would be really nice if when limit(1) is set the return type could instead be T | undefined. This would make it feel more like Prisma's findOne.

const user: User | undefined = await db
    .select()
    .from(users)
    .where(eq(users.email, email));

I could completely understand if this isn't possible due to breaking changes but I personally think it would be really improvement to DX. If the problem was breaking changes maybe a separate .findOne or something could exist instead, I'm not sure.

oscartbeaumont avatar May 01 '23 06:05 oscartbeaumont