Open pingustar opened 12 months ago
drizzle-orm
0.29.1
drizzle-kit
0.20.6
sql.placeholder throws type error for enums.
sql.placeholder
import { drizzle } from "drizzle-orm/mysql2" import { mysqlTable, varchar, mysqlEnum } from "drizzle-orm/mysql-core" import { sql, SQL } from "drizzle-orm" const statuses = ["PENDING", "ACCEPTED", "DECLINED"] as const const status = mysqlEnum("status", statuses) .notNull() .default("PENDING") type Status = typeof status const tableA = mysqlTable("table_a", { id: varchar("id", { length: 30}).primaryKey(), status: status }); const db = drizzle({} as any) db.update(tableA).set({ status: sql.placeholder("status") })
the last line, db.update(tableA).set({ status: sql.placeholder("status") }) throws a type error and a workaround is to type cast like so:
db.update(tableA).set({ status: sql.placeholder("status") })
db.update(tableA).set({ status: sql.placeholder("status") as unknown as SQL<string> })
for reference, @Angelelz asked me to open an issue for it in this discord discussion https://discord.com/channels/1043890932593987624/1181229913798357032
handle enum types correctly.
In general, it would be awesome to get actual type safety with prepared statements. I love the performance improvements, but the missing type safety really bums me out and makes the dev experience very error prone.
macos bun next 14
I am having same problem with postgres.
https://github.com/drizzle-team/drizzle-orm/discussions/2373
What version of
drizzle-orm
are you using?0.29.1
What version of
drizzle-kit
are you using?0.20.6
Describe the Bug
sql.placeholder
throws type error for enums.the last line,
db.update(tableA).set({ status: sql.placeholder("status") })
throws a type error and a workaround is to type cast like so:db.update(tableA).set({ status: sql.placeholder("status") as unknown as SQL<string> })
for reference, @Angelelz asked me to open an issue for it in this discord discussion https://discord.com/channels/1043890932593987624/1181229913798357032
Expected behavior
handle enum types correctly.
In general, it would be awesome to get actual type safety with prepared statements. I love the performance improvements, but the missing type safety really bums me out and makes the dev experience very error prone.
Environment & setup
macos bun next 14