listAll[T] working
This commit is contained in:
19
client.go
19
client.go
@@ -125,18 +125,11 @@ func listAll[T any](ctx context.Context, c *Client, db, table string, params url
|
|||||||
for {
|
for {
|
||||||
resp := map[string]any{}
|
resp := map[string]any{}
|
||||||
|
|
||||||
err := c.get(ctx, db, table, "", params, resp)
|
err := c.get(ctx, db, table, "", params, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
off, found := resp["offset"]
|
|
||||||
if !found {
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
params.Set("offset", off.(string))
|
|
||||||
|
|
||||||
subresp, err := json.Marshal(resp[key])
|
subresp, err := json.Marshal(resp[key])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -144,11 +137,19 @@ func listAll[T any](ctx context.Context, c *Client, db, table string, params url
|
|||||||
|
|
||||||
obj := []*T{}
|
obj := []*T{}
|
||||||
|
|
||||||
err = json.Unmarshal(subresp, obj)
|
err = json.Unmarshal(subresp, &obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = append(ret, obj...)
|
ret = append(ret, obj...)
|
||||||
|
|
||||||
|
off, found := resp["offset"]
|
||||||
|
if !found {
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
params.Set("offset", off.(string))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user