diff --git a/CHANGELOG.md b/CHANGELOG.md index b4a7bc821..ae52394b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,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 diff --git a/crud/example_test.go b/crud/example_test.go index 2b80212ca..b16fe0053 100644 --- a/crud/example_test.go +++ b/crud/example_test.go @@ -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]] +} diff --git a/crud/select.go b/crud/select.go index 97048a365..4e33c0b03 100644 --- a/crud/select.go +++ b/crud/select.go @@ -61,9 +61,9 @@ func (opts SelectOpts) EncodeMsgpack(enc *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[:]) }