| 114 | const orderByClause = (expr: SQL): SQL => sql`${dir(expr)} ${nullsLast}` |
| 115 | |
| 116 | const buildCursorCondition = (sortExpr: unknown, idCol: unknown): SQL | undefined => { |
| 117 | if (!cursor) return undefined |
| 118 | const v = cursor.v |
| 119 | const id = cursor.id |
| 120 | const cmp = sortOrder === 'asc' ? sql`>` : sql`<` |
| 121 | if (v === null) { |
| 122 | return sql`(${sortExpr} IS NULL AND ${idCol} ${cmp} ${id})` |
| 123 | } |
| 124 | return sql`((${sortExpr} IS NOT NULL AND ${sortExpr} ${cmp} ${v}) OR (${sortExpr} = ${v} AND ${idCol} ${cmp} ${id}) OR ${sortExpr} IS NULL)` |
| 125 | } |
| 126 | |
| 127 | const fetchSize = p.limit + 1 |
| 128 | |