Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crud: fix options for SelectRequest #323

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
- Flaky decimal/TestSelect (#300)
- Race condition at roundRobinStrategy.GetNextConnection() (#309)
- Incorrect decoding of an MP_DECIMAL when the `scale` value is negative (#314)
- Incorrect options (`after`, `batch_size` and `force_map_call`) setup for
crud.SelectRequest (#320)

## [1.12.0] - 2023-06-07

Expand Down
38 changes: 38 additions & 0 deletions crud/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,41 @@ func ExampleResult_errorMany() {
// Output:
// Failed to execute request: CallError:
}

func ExampleSelectRequest_pagination() {
conn := exampleConnect()

const (
fromTuple = 5
allTuples = 10
)
var tuple interface{}
for i := 0; i < allTuples; i++ {
req := crud.MakeReplaceRequest(exampleSpace).
Tuple([]interface{}{uint(3000 + i), nil, "bla"})
ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
fmt.Printf("Failed to initialize the example: %s\n", err)
return
}
if i == fromTuple {
tuple = ret.Rows.([]interface{})[0]
}
}

req := crud.MakeSelectRequest(exampleSpace).
Opts(crud.SelectOpts{
First: crud.MakeOptInt(2),
After: crud.MakeOptTuple(tuple),
})
ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
fmt.Printf("Failed to execute request: %s", err)
return
}
fmt.Println(ret.Metadata)
fmt.Println(ret.Rows)
// Output:
// [{id unsigned false} {bucket_id unsigned true} {name string false}]
// [[3006 32 bla] [3007 33 bla]]
}
6 changes: 3 additions & 3 deletions crud/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ func (opts SelectOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
values[6], exists[6] = opts.Balance.Get()
values[7], exists[7] = opts.First.Get()
values[8], exists[8] = opts.After.Get()
values[8], exists[8] = opts.BatchSize.Get()
values[8], exists[8] = opts.ForceMapCall.Get()
values[8], exists[8] = opts.Fullscan.Get()
values[9], exists[9] = opts.BatchSize.Get()
values[10], exists[10] = opts.ForceMapCall.Get()
values[11], exists[11] = opts.Fullscan.Get()

return encodeOptions(enc, names[:], values[:], exists[:])
}
Expand Down