You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: rewrite list queries with comment-marker placeholders
Replaces the sqlc.narg(filter)::void and cursor machinery in List
queries with SQL comment placeholders (/* query.cursor AND */,
/* query.filter AND */, /* query.order , */) that a runtime rewriter
(e.g. sqlc-gen-template) substitutes before execution.
When left unreplaced they remain SQL comments, so the query runs as
an offset-paginated scan ordered by primary key. Removes page_start
from the generator; keeps page_order for the default ORDER BY tie-breaker.
-- List{{table_name $.Table.Name"many"}}{{query_index $key}} retrieves a paginated list of rows from '{{$.Table.Name}}'{{if$key.Name}} filtered by {{$key.Name}}{{end}}.
305
299
--
306
-
-- Filtering:
307
-
-- The 'filter' parameter enables dynamic WHERE clauses for flexible querying.
308
-
-- Pass NULL for no filtering, or use a query builder (e.g., pgxmql.WhereClause)
309
-
-- to construct runtime conditions. The void type cast allows query rewriting.
310
-
-- Example: filter can add conditions like "status = 'active' AND created_at > '2024-01-01'"
300
+
-- Filtering, cursor, and ordering:
301
+
-- The commented markers in WHERE and ORDER BY are placeholders for a runtime
302
+
-- query rewriter (e.g. sqlc-gen-template) to substitute cursor, filter, and
303
+
-- order expressions. When left unreplaced they remain SQL comments, so the
304
+
-- query returns all matching rows ordered by primary key.
311
305
--
312
-
-- Pagination:
313
-
-- Cursor-based: Use page_start (ID of last item from previous page) + page_limit.
314
-
-- Returns items AFTER the cursor. Set page_start to the last item's ID from current page as next cursor.
315
-
-- Offset-based: Use page_offset + page_limit for traditional page number pagination.
306
+
-- Offset pagination:
307
+
-- Use offset + limit for traditional page number pagination.
316
308
-- name: {{$query_name}} :many
317
309
SELECT
318
310
*
319
311
FROM
320
312
{{$.Table.Name}}
321
313
{{- $condition:= query_condition $.Table$key}}
322
-
{{- $page_start:= page_start $.Table}}
323
-
{{- $page_order:= page_order $.Table}}
324
-
{{- if$condition}}
325
-
WHERE
326
-
{{$condition}}
327
-
{{- if$page_start}}
328
-
AND {{$page_start}}
329
-
{{- end}}
330
-
{{- elseif$page_start}}
331
314
WHERE
332
-
{{$page_start}}
333
-
{{- end}}
334
-
{{- if$page_order}}
315
+
/* query.cursor AND *//* query.filter AND */ {{if$condition}}{{$condition}}{{else}}TRUE{{end}}
0 commit comments