feat: add scroll / iteration helpers

This commit is contained in:
Milas Bowman 2025-03-10 21:31:07 -04:00
parent 7d1910919c
commit 6eb7e62a0c
Signed by: milas
SSH key fingerprint: SHA256:ek2D5l1HA34B3wbdErz0QOXm1E46CVvyf/nM4Fwfx/U
6 changed files with 196 additions and 11 deletions

View file

@ -10,7 +10,7 @@ import (
"net/url"
)
type ReadBatchSearch struct {
type BatchSearch struct {
PartitionKey string `json:"partitionKey"`
// Prefix restricts listing to partition keys that start with this value.
@ -59,7 +59,7 @@ type SearchResultItem struct {
Values []Item `json:"v"`
}
func (c *Client) ReadBatch(ctx context.Context, b Bucket, q []ReadBatchSearch) ([]BatchSearchResult, error) {
func (c *Client) ReadBatch(ctx context.Context, b Bucket, q []BatchSearch) ([]*BatchSearchResult, error) {
u, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
@ -91,7 +91,7 @@ func (c *Client) ReadBatch(ctx context.Context, b Bucket, q []ReadBatchSearch) (
return nil, fmt.Errorf("http status code %d: %s", resp.StatusCode, body)
}
var items []BatchSearchResult
var items []*BatchSearchResult
if err := json.Unmarshal(body, &items); err != nil {
return nil, err
}
@ -112,9 +112,9 @@ type BulkGetItem struct {
}
func BulkGet(ctx context.Context, cli *Client, b Bucket, keys []ItemKey) ([]BulkGetItem, error) {
q := make([]ReadBatchSearch, len(keys))
q := make([]BatchSearch, len(keys))
for i := range keys {
q[i] = ReadBatchSearch{
q[i] = BatchSearch{
PartitionKey: keys[i].PartitionKey,
Start: keys[i].SortKey,
SingleItem: true,