toKeysetWhereSql
function toKeysetWhereSql( where, columns, options?): KeysetSqlFragment;Defined in: keyset.ts:331
Render a KeysetWhere AST as a parameterized SQL WHERE clause.
Returns { sql: "", params: [] } for first page (where is null).
Column names are taken from columns (logical key → SQL identifier or
keysetSqlExpression); cursor values are always bind parameters.
The returned sql does not include the leading WHERE, so callers can omit
it for first-page queries.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
where |
| KeysetWhere | null |
columns |
KeysetSqlColumns |
options? |
ToKeysetSqlOptions |
Returns
Section titled “Returns”Examples
Section titled “Examples”PostgreSQL-style placeholders
const where = toKeysetWhereSql(keyset.where(cursor), { createdAt: "created_at", id: "id",});
await pg.query( `SELECT * FROM posts WHERE ${where.sql} ORDER BY created_at ASC, id ASC`, where.params,);MySQL/SQLite-style placeholders
toKeysetWhereSql(where, columns, { placeholder: () => "?" });Throws
Section titled “Throws”If a key is missing from columns or a column identifier is unsafe.