drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.49k stars 643 forks source link

[BUG]: #1826

Open CaptainYarb opened 9 months ago

CaptainYarb commented 9 months ago

What version of drizzle-orm are you using?

0.29.3

What version of drizzle-kit are you using?

n/a

Describe the Bug

Conditional helper functions such as isNull, isNotNull, exists, notExists cannot be used within a query select, without returning an unknown type.

const results = await db
    .select({
      id: table.id,
      has_title_orm: isNotNull(table.name),
      has_title_sql: sql<boolean>`${table.name} IS NOT NULL`,
    })
    .from(table);

  results[0].has_title_orm; // unknown type
  results[0].has_title_sql; // boolean type

Expected behavior

The sql wrapper used should be able to be typed for these boolean returns. I can imagine that there's a circumstance where you might not want to, given the fact these query helpers can be used in other places?

Environment & setup

Example Stackblitz: https://stackblitz.com/edit/typescript-5bbctn?file=index.ts

AndriiSherman commented 9 months ago

Thanks a lot! I'll mark it as improvement and we will implement this

JohnAllenTech commented 4 weeks ago

Any update on this one?

glassworks-projects commented 3 weeks ago

+1