Skip to content

Commit f2c9c14

Browse files
author
New year
committed
crud: refactor optional types to use go-option
- Remove: OptUint, OptInt, OptFloat64, OptString, OptBool, OptTuple. - Remove: MakeOptUint, MakeOptInt, MakeOptFloat64, MakeOptString, MakeOptBool, MakeOptTuple. - Update: All option structs to use option.* types. - Add type Any from go-option. - Fix: Test type inconsistencies. Closes #492
1 parent eec84ad commit f2c9c14

File tree

13 files changed

+172
-270
lines changed

13 files changed

+172
-270
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
2626
and Future.GetIterator() methods, ResponseIterator and TimeoutResponseIterator types,
2727
Future.pushes[] (#480).
2828
* `LogAppendPushFailed` replaced with `LogBoxSessionPushUnsupported` (#480)
29+
* Replaced the use of optional types in crud with go-option library (#492).
2930

3031
### Fixed
3132

@@ -48,7 +49,6 @@ flag handling, and fixes watcher panic.
4849
- Implemented support for `IPROTO_IS_SYNC` flag in stream transactions,
4950
added `IsSync(bool)` method for `BeginRequest`/`CommitRequest` (#447).
5051

51-
5252
### Fixed
5353

5454
- Fixed panic when calling NewWatcher() during reconnection or after

crud/count.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/vmihailenco/msgpack/v5"
77

8+
"github.com/tarantool/go-option"
89
"github.com/tarantool/go-tarantool/v3"
910
)
1011

@@ -15,30 +16,30 @@ type CountResult = NumberResult
1516
type CountOpts struct {
1617
// Timeout is a `vshard.call` timeout and vshard
1718
// master discovery timeout (in seconds).
18-
Timeout OptFloat64
19+
Timeout option.Float64
1920
// VshardRouter is cartridge vshard group name or
2021
// vshard router instance.
21-
VshardRouter OptString
22+
VshardRouter option.String
2223
// Mode is a parameter with `write`/`read` possible values,
2324
// if `write` is specified then operation is performed on master.
24-
Mode OptString
25+
Mode option.String
2526
// PreferReplica is a parameter to specify preferred target
2627
// as one of the replicas.
27-
PreferReplica OptBool
28+
PreferReplica option.Bool
2829
// Balance is a parameter to use replica according to vshard
2930
// load balancing policy.
30-
Balance OptBool
31+
Balance option.Bool
3132
// YieldEvery describes number of tuples processed to yield after.
3233
// Should be positive.
33-
YieldEvery OptUint
34+
YieldEvery option.Uint
3435
// BucketId is a bucket ID.
35-
BucketId OptUint
36+
BucketId option.Uint
3637
// ForceMapCall describes the map call is performed without any
3738
// optimizations even if full primary key equal condition is specified.
38-
ForceMapCall OptBool
39+
ForceMapCall option.Bool
3940
// Fullscan describes if a critical log entry will be skipped on
4041
// potentially long count.
41-
Fullscan OptBool
42+
Fullscan option.Bool
4243
}
4344

4445
// EncodeMsgpack provides custom msgpack encoder.

crud/example_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"reflect"
77
"time"
88

9+
"github.com/tarantool/go-option"
910
"github.com/tarantool/go-tarantool/v3"
1011
"github.com/tarantool/go-tarantool/v3/crud"
1112
)
@@ -288,7 +289,7 @@ func ExampleResult_noreturn() {
288289
[]interface{}{uint(2011), nil, "bla"},
289290
}).
290291
Opts(crud.ReplaceManyOpts{
291-
Noreturn: crud.MakeOptBool(true),
292+
Noreturn: option.SomeBool(true),
292293
})
293294

294295
ret := crud.Result{}
@@ -375,8 +376,8 @@ func ExampleSelectRequest_pagination() {
375376

376377
req := crud.MakeSelectRequest(exampleSpace).
377378
Opts(crud.SelectOpts{
378-
First: crud.MakeOptInt(2),
379-
After: crud.MakeOptTuple(tuple),
379+
First: option.SomeInt64(2),
380+
After: option.SomeAny(tuple),
380381
})
381382
ret := crud.Result{}
382383
if err := conn.Do(req).GetTyped(&ret); err != nil {

crud/get.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,36 @@ import (
55

66
"github.com/vmihailenco/msgpack/v5"
77

8+
"github.com/tarantool/go-option"
89
"github.com/tarantool/go-tarantool/v3"
910
)
1011

1112
// GetOpts describes options for `crud.get` method.
1213
type GetOpts struct {
1314
// Timeout is a `vshard.call` timeout and vshard
1415
// master discovery timeout (in seconds).
15-
Timeout OptFloat64
16+
Timeout option.Float64
1617
// VshardRouter is cartridge vshard group name or
1718
// vshard router instance.
18-
VshardRouter OptString
19+
VshardRouter option.String
1920
// Fields is field names for getting only a subset of fields.
20-
Fields OptTuple
21+
Fields option.Any
2122
// BucketId is a bucket ID.
22-
BucketId OptUint
23+
BucketId option.Uint
2324
// Mode is a parameter with `write`/`read` possible values,
2425
// if `write` is specified then operation is performed on master.
25-
Mode OptString
26+
Mode option.String
2627
// PreferReplica is a parameter to specify preferred target
2728
// as one of the replicas.
28-
PreferReplica OptBool
29+
PreferReplica option.Bool
2930
// Balance is a parameter to use replica according to vshard
3031
// load balancing policy.
31-
Balance OptBool
32+
Balance option.Bool
3233
// FetchLatestMetadata guarantees the up-to-date metadata (space format)
3334
// in first return value, otherwise it may not take into account
3435
// the latest migration of the data format. Performance overhead is up to 15%.
3536
// Disabled by default.
36-
FetchLatestMetadata OptBool
37+
FetchLatestMetadata option.Bool
3738
}
3839

3940
// EncodeMsgpack provides custom msgpack encoder.

crud/insert.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package crud
33
import (
44
"context"
55

6-
"github.com/vmihailenco/msgpack/v5"
7-
86
"github.com/tarantool/go-tarantool/v3"
7+
"github.com/vmihailenco/msgpack/v5"
98
)
109

1110
// InsertOpts describes options for `crud.insert` method.

0 commit comments

Comments
 (0)