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

[drizzle-orm]: add CASE WHEN expression #2812

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

louneskmt
Copy link

@louneskmt louneskmt commented Aug 20, 2024

Humble attempt at a typed CASE WHEN expression. Not quite sure I'm using the right Drizzle types everywhere, please let me know.

Usage:

caseWhen(eq(table1.column, 'condition1')).then('bar1')
  .when(eq(table1.column, 'condition2')).then(table2.otherColumn)
  // [ .when( ... ]
  .else(sql<string>`'default'`)
  .end()

Closes #1065.

};

return {
then: <T extends SQL | SQLWrapper | Column>(value: T) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overloading .then() seems a bit fishy to me

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, any other idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE]: native CASE WHEN support
2 participants