prepared statements placeholder typing

Schema
const users = sqliteTable("user", {
id: text("id").primaryKey(),
text: text("text"),
})
const users = sqliteTable("user", {
id: text("id").primaryKey(),
text: text("text"),
})
const updateUser = db
.update(users)
.set({ text: sql.placeholder("text") })
.where(eq(users.id, sql.placeholder("id")))
.prepare()
const updateUser = db
.update(users)
.set({ text: sql.placeholder("text") })
.where(eq(users.id, sql.placeholder("id")))
.prepare()
On the text property I get the following
Type 'Placeholder<"text", any>' is not assignable to type 'string | SQL<unknown> | null | undefined'.
Type 'Placeholder<"text", any>' is not assignable to type 'string | SQL<unknown> | null | undefined'.
The issue only seems to occur in the set part, is there a reason? A better way?
S
Sillvva16d ago
Not sure if this will fix it or not, but try this:
const updateUser = db
.update(users)
.set({ text: sql.placeholder("text").getSQL() })
.where(eq(users.id, sql.placeholder("id")))
.prepare()
const updateUser = db
.update(users)
.set({ text: sql.placeholder("text").getSQL() })
.where(eq(users.id, sql.placeholder("id")))
.prepare()
D
Dayblox12d ago
What's this? Can't seem to find any documentation It seems to work
S
Sillvva12d ago
It's not documented (like a lot of things), but I noticed placeholder had a .getSQL() method that returned an SQL object https://github.com/drizzle-team/drizzle-orm/blob/76eb060acf4829fc25189efb57a11a1408fd1e15/drizzle-orm/src/sql/sql.ts#L539
GitHub
drizzle-orm/drizzle-orm/src/sql/sql.ts at 76eb060acf4829fc25189efb5...
Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅 - drizzle-team/drizzle-orm
Want results from more Discord servers?
Add your server
More Posts