Open raggesilver opened 4 months ago
Having the same issue. @raggesilver were you able to resolve?
Having the same issue. @raggesilver were you able to resolve?
I edited the migration file manually...
It seems that all conditional helpers that use a parameter cannot be used inside functions that create migrations. $1
is part of a behavior used in queries.
https://github.com/drizzle-team/drizzle-orm/issues/1845#issuecomment-1925306192
You have to use the sql
util. This is not explained in the docs but used in the examples.
This wont work eq(table.active, true)
but this will:
sql`${table.active} IS TRUE`
I would also like to see the DX here improved so we can use the helpers and have a consistent feel for using drizzle both in the schema and when writing queries. With that said there's another workaround that allows you to keep a bit more of the structure I would like to see by pushing the magic sql
operator as far down as possible.
.where(eq(table.active, sql`true`));
This tells drizzle you want to use the sql literal true
rather than passing in a JS variable that needs to be parameterized for safety. This also works with strings if you quote them manually inside the sql string i.e.
sql`'my string'`
The following schema does not generate a valid migration. The value for the where clause is not substituted in the generated SQL.
Expected Output
Actual Output
Error
Versions
drizzle-orm 0.31.2 drizzle-kit 0.22.7 postgres 3.4.4 Node v21.7.3 Pnpm 9.2.0