Using sql.placeholder with limit in creating a prepared query

I am attempting to create a prepared query like this...
const findByNamePrepared = this.database
.select()
.from(table)
.where(like(table.fullName, sql.placeholder('fullName')))
.limit(sql.placeholder('limit'))
.offset(sql.placeholder('offset'))
.prepare();
const findByNamePrepared = this.database
.select()
.from(table)
.where(like(table.fullName, sql.placeholder('fullName')))
.limit(sql.placeholder('limit'))
.offset(sql.placeholder('offset'))
.prepare();
It fails to compile with the following message:
error TS2345: Argument of type 'Placeholder<"limit", any>' is not assignable to parameter of type 'number'.
35 .limit(sql.placeholder('limit'))
error TS2345: Argument of type 'Placeholder<"offset", any>' is not assignable to parameter of type 'number'.
36 .offset(sql.placeholder('offset'))
error TS2345: Argument of type 'Placeholder<"limit", any>' is not assignable to parameter of type 'number'.
35 .limit(sql.placeholder('limit'))
error TS2345: Argument of type 'Placeholder<"offset", any>' is not assignable to parameter of type 'number'.
36 .offset(sql.placeholder('offset'))
How are placeholders suppose to work with limit and offset?
12 Replies
Huge Letters
Huge Letters8mo ago
what drizzle version and driver are you using? i've tried this just now on the latest version with sqlite - no issues
Vinny
VinnyOP8mo ago
"drizzle-orm": "~0.30.7" "drizzle-kit": "~0.20.14" "@planetscale/database": "~1.16.0"
Vinny
VinnyOP8mo ago
The placeholder examples on the site are not working for me either (https://orm.drizzle.team/docs/rqb#placeholder-in-limit)
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Huge Letters
Huge Letters8mo ago
yeah, it seems like an issue with type definitions(maybe because implementation differs?) this is typedef in mysql-core
No description
Huge Letters
Huge Letters8mo ago
and this is in sqlite-core
No description
Huge Letters
Huge Letters8mo ago
so I think you can file an issue on gh
Vinny
VinnyOP8mo ago
Nice find
Huge Letters
Huge Letters8mo ago
does it work tho? is it just a typescript error or query also doesn't work? if it's only a TS problem it's pretty easy fix - you could patch it temporarily while waiting for an update
Vinny
VinnyOP8mo ago
I'm not able to compile it and it's a located in a package that is shared with two other webapps, so I think it has to sucessfully compile in order to output the runtime code in the /dist folder for the apps to use.
Huge Letters
Huge Letters8mo ago
you could put as never there for now to test it
Vinny
VinnyOP8mo ago
Good idea BTW, this worked. I still need to record an issue on gh. Time is a commodity that is hard to spend properly.
Vinny
VinnyOP8mo ago
GitHub
[BUG]: Using sql.placeholder with limit and/or offset for a p...
What version of drizzle-orm are you using? 0.30.7 What version of drizzle-kit are you using? 0.20.14 Describe the Bug Given the following code, const database: PlanetScaleDatabase = drizzle(client)...
Want results from more Discord servers?
Add your server