Having placeholders "survive" dynamic query building

If the query I'm trying to modify with a dynamic query (....$dynamic()) contains any placeholders, I'm getting an error that says No value for placeholder.... provided. That seems counterintuitive because I should only be required to provide placeholder values when I actually execute the query, not when I'm still "building" it. Is this a limitation of Drizzle, or am I thinking the wrong way about this? EDIT: Funny enough, the query seems to still work despite the error.. Simple example to illustrate:
function withPagination<T extends PgSelect>(
qb: T,
page: number = 1,
pageSize: number = 10,
) {
return qb.limit(pageSize).offset((page - 1) * pageSize);
}

const query = db.select().from(users).where(eq(users.id, sql.placeholder("myPlaceholder"))

const dynamicQuery = query.$dynamic()

withPagination(dynamicQuery, 2, 20) // Error: No value for placeholder "myPlaceholder" was provided
function withPagination<T extends PgSelect>(
qb: T,
page: number = 1,
pageSize: number = 10,
) {
return qb.limit(pageSize).offset((page - 1) * pageSize);
}

const query = db.select().from(users).where(eq(users.id, sql.placeholder("myPlaceholder"))

const dynamicQuery = query.$dynamic()

withPagination(dynamicQuery, 2, 20) // Error: No value for placeholder "myPlaceholder" was provided
Error: No value for placeholder "myPlaceholder" was provided
at eval (webpack-internal:///(rsc)/./node_modules/drizzle-orm/sql/sql.js:358:15)
at Array.map (<anonymous>)
at fillPlaceholders (webpack-internal:///(rsc)/./node_modules/drizzle-orm/sql/sql.js:355:17)
at eval (webpack-internal:///(rsc)/./node_modules/drizzle-orm/postgres-js/session.js:34:83)
at Object.startActiveSpan (webpack-internal:///(rsc)/./node_modules/drizzle-orm/tracing.js:14:14)
at PostgresJsPreparedQuery.execute (webpack-internal:///(rsc)/./node_modules/drizzle-orm/postgres-js/session.js:33:60)
at eval (webpack-internal:///(rsc)/./node_modules/drizzle-orm/pg-core/query-builders/select.js:713:30)
at Object.startActiveSpan (webpack-internal:///(rsc)/./node_modules/drizzle-orm/tracing.js:14:14)
at PgSelectBase.execute (webpack-internal:///(rsc)/./node_modules/drizzle-orm/pg-core/query-builders/select.js:712:60)
at PgSelectBase.then (webpack-internal:///(rsc)/./node_modules/drizzle-orm/query-promise.js:26:17)
at process.processTicksAndRejections..
Error: No value for placeholder "myPlaceholder" was provided
at eval (webpack-internal:///(rsc)/./node_modules/drizzle-orm/sql/sql.js:358:15)
at Array.map (<anonymous>)
at fillPlaceholders (webpack-internal:///(rsc)/./node_modules/drizzle-orm/sql/sql.js:355:17)
at eval (webpack-internal:///(rsc)/./node_modules/drizzle-orm/postgres-js/session.js:34:83)
at Object.startActiveSpan (webpack-internal:///(rsc)/./node_modules/drizzle-orm/tracing.js:14:14)
at PostgresJsPreparedQuery.execute (webpack-internal:///(rsc)/./node_modules/drizzle-orm/postgres-js/session.js:33:60)
at eval (webpack-internal:///(rsc)/./node_modules/drizzle-orm/pg-core/query-builders/select.js:713:30)
at Object.startActiveSpan (webpack-internal:///(rsc)/./node_modules/drizzle-orm/tracing.js:14:14)
at PgSelectBase.execute (webpack-internal:///(rsc)/./node_modules/drizzle-orm/pg-core/query-builders/select.js:712:60)
at PgSelectBase.then (webpack-internal:///(rsc)/./node_modules/drizzle-orm/query-promise.js:26:17)
at process.processTicksAndRejections..
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server