Skip to content

Commit 129c2ea

Browse files
Add cursor fragment splice example (#4735)
* fragment splice cursor example * update image * update other image * update alpine * update alpine * update alpine
1 parent b4b8996 commit 129c2ea

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- elixir: "1.18.1"
2626
otp: "27.2"
2727
- elixir: "1.17.3"
28-
otp: "27.1"
28+
otp: "27.2"
2929
- elixir: "1.17.3"
3030
otp: "25.0.4"
3131
- elixir: "1.14.5"

lib/ecto/query/api.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,18 @@ defmodule Ecto.Query.API do
554554
from p in Post, select: concat_ws(":", [p.author, ^year, p.title])
555555
from s in Sequences, select: concat_ws(".", ["public", s.relname])
556556
557+
Or you may want to create re-usable macros for [Postgres's row constructor
558+
comparison syntax](https://www.postgresql.org/docs/current/functions-comparisons.html#ROW-WISE-COMPARISON)
559+
to support multi-column cursor-based pagination:
560+
561+
defmacro row_gt(columns, values) do
562+
quote do
563+
fragment("(?) >= (?)", splice(unquote(columns)), splice(unquote(values)))
564+
end
565+
end
566+
567+
from(p in Post, where: row_gt([p.visits, p.id], [^lower_visits, ^lower_id]))
568+
557569
You may nest others splices and fragment modifiers such as `identifier/1` and
558570
`constant/1` inside of compile-time splices
559571

0 commit comments

Comments
 (0)