add function for ListWithCount
This commit is contained in:
parent
da52bb5c90
commit
de2ca763c1
@ -116,3 +116,17 @@ func (c *Coll[TData]) Count(ctx context.Context, filter ct.Filter) (int64, error
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (c *Coll[TData]) ListWithCount(ctx context.Context, filter ct.Filter, pageSize *int, inTok ct.CursorToken) ([]TData, ct.CursorToken, int64, error) {
|
||||
// NOTE: Possible optimasation: Cache count in CursorToken, then fetch count only on first page.
|
||||
count, err := c.Count(ctx, filter)
|
||||
if err != nil {
|
||||
return nil, ct.CursorToken{}, 0, err
|
||||
}
|
||||
|
||||
data, token, err := c.List(ctx, filter, pageSize, inTok)
|
||||
if err != nil {
|
||||
return nil, ct.CursorToken{}, 0, err
|
||||
}
|
||||
return data, token, count, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user