| 1 | diff --git a/internal/storage/query.go b/internal/storage/query.go |
| 2 | index cf777c2..bd71504 100644 |
| 3 | --- a/internal/storage/query.go |
| 4 | +++ b/internal/storage/query.go |
| 5 | @@ -19,6 +19,13 @@ type QueryOptions struct { |
| 6 | Now int64 |
| 7 | Access Access |
| 8 | Limit int |
| 9 | + Before *EventCursor |
| 10 | +} |
| 11 | + |
| 12 | +// EventCursor follows the stable newest-first query order. |
| 13 | +type EventCursor struct { |
| 14 | + CreatedAt int64 |
| 15 | + ID string |
| 16 | } |
| 17 | type QueryResult struct { |
| 18 | Events []event.Event |
| 19 | @@ -46,6 +53,9 @@ func (p *predicate) list(column string, value any) error { |
| 20 | |
| 21 | func where(f event.Filter, opts QueryOptions) (predicate, error) { |
| 22 | var p predicate |
| 23 | + if opts.Before != nil { |
| 24 | + p.add("(created_at<? OR (created_at=? AND id>?))", opts.Before.CreatedAt, opts.Before.CreatedAt, opts.Before.ID) |
| 25 | + } |
| 26 | if f.IDs != nil { |
| 27 | if err := p.list("id", f.IDs); err != nil { |
| 28 | return p, err |