DT
Drizzle Teamโ€ข13mo ago
Hocus

Prepare statement throws type error for enums. How to get type safety for prepared values

the status column in the schema is an enum like so:
status: mysqlEnum("status", "PENDING", "ACCEPTED", "DECLINED")
.notNull()
.default("PENDING"),
status: mysqlEnum("status", "PENDING", "ACCEPTED", "DECLINED")
.notNull()
.default("PENDING"),
and even type casting the placeholder does not work
db.update(table).set({ status: sql.placeholder("status") as Status })
db.update(table).set({ status: sql.placeholder("status") as Status })
is there a proper way to get type safety in general for prepared statements? Love the performance gains, but really bums me out that I loose all safeguards regarding types ๐Ÿ˜•
No description
8 Replies
Angelelz
Angelelzโ€ข13mo ago
Check this typescript playground for a workaround
Angelelz
Angelelzโ€ข13mo ago
Can create a new GH issue for this?
Hocus
HocusOPโ€ข13mo ago
thanks, that works for now. I assume I didn't miss anything in the docs then and there is no better/type-safe way for prepared statements, like generics or something? yea I can add an issue for this
Angelelz
Angelelzโ€ข13mo ago
We just need to add the placeholder type to the mysqlEnum type
Hocus
HocusOPโ€ข13mo ago
ok. It would be cool in general to get some typesafety for the prepared statements, specially for the object that is passed to the execute({...}) argument.
Angelelz
Angelelzโ€ข13mo ago
There is an open issue for that, we just haven't been able to get to that one yet
Hocus
HocusOPโ€ข13mo ago
GitHub
[BUG]: sql.placeholder throws type error for enums ยท Issue #1608 ...
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. import { drizzle } from "drizz...
Want results from more Discord servers?
Add your server