Fold WalkLoader into Loader with slice constraint
Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
@@ -33,14 +33,11 @@ import (
|
|||||||
const MaxLoadAllPages = 20
|
const MaxLoadAllPages = 20
|
||||||
|
|
||||||
// Loader runs one paginated query for the given cursor and returns the
|
// Loader runs one paginated query for the given cursor and returns the
|
||||||
// rows it loaded. Callers bind the connection, scope, parent key and
|
// rows it loaded. S may be []T or a coredata collection type with underlying
|
||||||
// filter in a closure, exposing only ctx and cursor (typically a coredata
|
// type []T (e.g. AuditLogEntries). Callers bind the connection, scope, parent
|
||||||
// LoadBy* on a fresh receiver).
|
// key and filter in a closure, exposing only ctx and cursor (typically a
|
||||||
type Loader[T Paginable[U], U OrderField] func(ctx context.Context, cursor *Cursor[U]) ([]T, error)
|
// coredata LoadBy* on a fresh receiver).
|
||||||
|
type Loader[T Paginable[U], U OrderField, S ~[]T] func(ctx context.Context, cursor *Cursor[U]) (S, error)
|
||||||
// WalkLoader is like Loader but allows coredata collection types (e.g.
|
|
||||||
// AuditLogEntries) whose underlying type is []T.
|
|
||||||
type WalkLoader[T Paginable[U], U OrderField, S ~[]T] func(ctx context.Context, cursor *Cursor[U]) (S, error)
|
|
||||||
|
|
||||||
// WalkAll walks every matching row via keyset pagination, advancing a
|
// WalkAll walks every matching row via keyset pagination, advancing a
|
||||||
// MaxCursorSize forward cursor until no rows remain, and invokes walk with
|
// MaxCursorSize forward cursor until no rows remain, and invokes walk with
|
||||||
@@ -48,7 +45,7 @@ type WalkLoader[T Paginable[U], U OrderField, S ~[]T] func(ctx context.Context,
|
|||||||
func WalkAll[T Paginable[U], U OrderField, S ~[]T](
|
func WalkAll[T Paginable[U], U OrderField, S ~[]T](
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
orderBy OrderBy[U],
|
orderBy OrderBy[U],
|
||||||
fetch WalkLoader[T, U, S],
|
fetch Loader[T, U, S],
|
||||||
walk func(rows S) error,
|
walk func(rows S) error,
|
||||||
) error {
|
) error {
|
||||||
var key *CursorKey
|
var key *CursorKey
|
||||||
@@ -82,7 +79,7 @@ func WalkAll[T Paginable[U], U OrderField, S ~[]T](
|
|||||||
func LoadAll[T Paginable[U], U OrderField](
|
func LoadAll[T Paginable[U], U OrderField](
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
orderBy OrderBy[U],
|
orderBy OrderBy[U],
|
||||||
fetch Loader[T, U],
|
fetch Loader[T, U, []T],
|
||||||
) ([]T, error) {
|
) ([]T, error) {
|
||||||
var (
|
var (
|
||||||
all []T
|
all []T
|
||||||
|
|||||||
Reference in New Issue
Block a user