Skip to content

Commit

Permalink
crud: fix options for SelectRequest
Browse files Browse the repository at this point in the history
The patch fixes a typo that made it impossible to setup
SelectOpts.After, SelectOpts.BatchSize and SelectOpts.ForceMapCall.

Part of #320

(cherry picked from f56fb90)
  • Loading branch information
oleg-jukovec committed Aug 3, 2023
1 parent 317d100 commit bd36edb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 @@ -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[:])
}
Expand Down

0 comments on commit bd36edb

Please sign in to comment.