Skip to content

Commit 6a6747c

Browse files
committed
crud: fix options for SelectRequest
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)
1 parent d44ecef commit 6a6747c

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
2121
- Flaky decimal/TestSelect (#300)
2222
- Race condition at roundRobinStrategy.GetNextConnection() (#309)
2323
- Incorrect decoding of an MP_DECIMAL when the `scale` value is negative (#314)
24+
- Incorrect options (`after`, `batch_size` and `force_map_call`) setup for
25+
crud.SelectRequest (#320)
2426

2527
## [1.12.0] - 2023-06-07
2628

crud/example_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,41 @@ func ExampleResult_errorMany() {
148148
// Output:
149149
// Failed to execute request: CallError:
150150
}
151+
152+
func ExampleSelectRequest_pagination() {
153+
conn := exampleConnect()
154+
155+
const (
156+
fromTuple = 5
157+
allTuples = 10
158+
)
159+
var tuple interface{}
160+
for i := 0; i < allTuples; i++ {
161+
req := crud.MakeReplaceRequest(exampleSpace).
162+
Tuple([]interface{}{uint(3000 + i), nil, "bla"})
163+
ret := crud.Result{}
164+
if err := conn.Do(req).GetTyped(&ret); err != nil {
165+
fmt.Printf("Failed to initialize the example: %s\n", err)
166+
return
167+
}
168+
if i == fromTuple {
169+
tuple = ret.Rows.([]interface{})[0]
170+
}
171+
}
172+
173+
req := crud.MakeSelectRequest(exampleSpace).
174+
Opts(crud.SelectOpts{
175+
First: crud.MakeOptInt(2),
176+
After: crud.MakeOptTuple(tuple),
177+
})
178+
ret := crud.Result{}
179+
if err := conn.Do(req).GetTyped(&ret); err != nil {
180+
fmt.Printf("Failed to execute request: %s", err)
181+
return
182+
}
183+
fmt.Println(ret.Metadata)
184+
fmt.Println(ret.Rows)
185+
// Output:
186+
// [{id unsigned false} {bucket_id unsigned true} {name string false}]
187+
// [[3006 32 bla] [3007 33 bla]]
188+
}

crud/select.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func (opts SelectOpts) EncodeMsgpack(enc *encoder) error {
6161
values[6], exists[6] = opts.Balance.Get()
6262
values[7], exists[7] = opts.First.Get()
6363
values[8], exists[8] = opts.After.Get()
64-
values[8], exists[8] = opts.BatchSize.Get()
65-
values[8], exists[8] = opts.ForceMapCall.Get()
66-
values[8], exists[8] = opts.Fullscan.Get()
64+
values[9], exists[9] = opts.BatchSize.Get()
65+
values[10], exists[10] = opts.ForceMapCall.Get()
66+
values[11], exists[11] = opts.Fullscan.Get()
6767

6868
return encodeOptions(enc, names[:], values[:], exists[:])
6969
}

0 commit comments

Comments
 (0)