Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: #1826

Open
Tracked by #3649
CaptainYarb opened this issue Jan 23, 2024 · 5 comments
Open
Tracked by #3649

[BUG]: #1826

CaptainYarb opened this issue Jan 23, 2024 · 5 comments
Assignees
Labels
good first issue Good for newcomers has-pr This issue has one or more PRs that that could close the issue when merged improvement priority Will be worked on next qb/crud

Comments

@CaptainYarb
Copy link

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

@CaptainYarb CaptainYarb added the bug Something isn't working label Jan 23, 2024
@AndriiSherman AndriiSherman added enhancement New feature or request and removed bug Something isn't working labels Feb 3, 2024
@AndriiSherman AndriiSherman self-assigned this Feb 3, 2024
@AndriiSherman AndriiSherman added the good first issue Good for newcomers label Feb 3, 2024
@AndriiSherman
Copy link
Member

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

@JohnAllenTech
Copy link

Any update on this one?

@glassworks-projects
Copy link

+1

1 similar comment
@whysocket
Copy link

+1

@cluah
Copy link

cluah commented Jan 9, 2025

hi, here are two more workarounds:

sql<boolean>`${isNotNull(table.column)}`
isNotNull(table.column).mapWith(Boolean)

@L-Mario564 L-Mario564 added the has-pr This issue has one or more PRs that that could close the issue when merged label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers has-pr This issue has one or more PRs that that could close the issue when merged improvement priority Will be worked on next qb/crud
Projects
None yet
Development

No branches or pull requests

7 participants