Skip to content

Commit 6d6aa77

Browse files
author
New year
committed
crud: replace usage of optional types in crud with go-option
Code is formatted. fixed #492
1 parent 2980a09 commit 6d6aa77

File tree

10 files changed

+22
-21
lines changed

10 files changed

+22
-21
lines changed

crud/compile_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
package crud
33

44
import (
5-
"testing"
65
"github.com/tarantool/go-option"
6+
"testing"
77
)
88

99
// TestOptionTypesCompilation проверяет что все типы option компилируются правильно
@@ -13,7 +13,7 @@ func TestOptionTypesCompilation(t *testing.T) {
1313
Timeout: option.SomeFloat64(1.5),
1414
VshardRouter: option.SomeString("router"),
1515
}
16-
16+
1717
// Проверяем что Get() работает
1818
if timeout, exists := baseOpts.Timeout.Get(); !exists || timeout != 1.5 {
1919
t.Errorf("BaseOpts.Timeout.Get() failed")
@@ -24,7 +24,7 @@ func TestOptionTypesCompilation(t *testing.T) {
2424
Timeout: option.SomeFloat64(2.0),
2525
VshardRouter: option.SomeString("router2"),
2626
Fields: MakeOptAny([]interface{}{"field1", "field2"}),
27-
BucketId: option.SomeUint(456), // Теперь это правильный тип
27+
BucketId: option.SomeUint(456), // Теперь это правильный тип
2828
FetchLatestMetadata: option.SomeBool(true),
2929
Noreturn: option.SomeBool(false),
3030
}
@@ -33,14 +33,14 @@ func TestOptionTypesCompilation(t *testing.T) {
3333
if bucket, exists := simpleOpts.BucketId.Get(); !exists || bucket != 456 {
3434
t.Errorf("BucketId.Get() failed: got %v, %v", bucket, exists)
3535
}
36-
36+
3737
if fields, exists := simpleOpts.Fields.Get(); !exists {
3838
t.Errorf("Fields.Get() failed")
3939
} else {
4040
t.Logf("Fields: %v", fields)
4141
}
4242

43-
// Test OperationManyOpts
43+
// Test OperationManyOpts
4444
manyOpts := OperationManyOpts{
4545
Timeout: option.SomeFloat64(3.0),
4646
StopOnError: option.SomeBool(true),
@@ -103,4 +103,4 @@ func TestMakeOptAny(t *testing.T) {
103103
t.Logf("Slice test passed: %v", valSlice)
104104
}
105105
})
106-
}
106+
}

crud/count.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

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

8-
"github.com/tarantool/go-tarantool/v3"
98
"github.com/tarantool/go-option"
9+
"github.com/tarantool/go-tarantool/v3"
1010
)
1111

1212
// CountResult describes result for `crud.count` method.

crud/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

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

8-
"github.com/tarantool/go-tarantool/v3"
98
"github.com/tarantool/go-option"
9+
"github.com/tarantool/go-tarantool/v3"
1010
)
1111

1212
// GetOpts describes options for `crud.get` method.

crud/insert.go

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

6-
"github.com/vmihailenco/msgpack/v5"
76
"github.com/tarantool/go-tarantool/v3"
7+
"github.com/vmihailenco/msgpack/v5"
88
)
99

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

crud/options.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package crud
22

33
import (
4-
"github.com/vmihailenco/msgpack/v5"
54
"github.com/tarantool/go-option"
5+
"github.com/vmihailenco/msgpack/v5"
66
)
77

88
const (
@@ -27,7 +27,7 @@ const (
2727
cachedOptName = "cached"
2828
)
2929

30-
// OptUint is an optional uint. Old local optional type.
30+
// OptUint is an optional uint. Old local optional type.
3131
/* type OptUint struct {
3232
value uint
3333
exist bool
@@ -45,7 +45,7 @@ const (
4545
func (opt OptUint) Get() (uint, bool) {
4646
return opt.value, opt.exist // Method Get() from go-options is same.
4747
}
48-
*/
48+
*/
4949
/* // OptInt is an optional int.
5050
type OptInt struct {
5151
value int
@@ -136,18 +136,19 @@ func MakeOptTuple(tuple interface{}) OptTuple {
136136
func (o *OptTuple) Get() (interface{}, bool) {
137137
return o.tuple, o.tuple != nil
138138
}
139-
*/
139+
*/
140140

141-
// Defining an alias for Generic[interface{}] to replace OptTuple
142-
type OptAny = option.Generic[interface{}]
141+
// Defining an alias for Generic[interface{}] to replace OptTuple
142+
type OptAny = option.Generic[interface{}]
143143

144-
// MakeOptAny creates an optional value from interface{} (replacing MakeOptTuple).
144+
// MakeOptAny creates an optional value from interface{} (replacing MakeOptTuple).
145145
func MakeOptAny(value interface{}) OptAny {
146146
if value == nil {
147147
return option.None[interface{}]()
148148
}
149149
return option.Some[interface{}](value)
150150
}
151+
151152
// BaseOpts describes base options for CRUD operations.
152153
type BaseOpts struct {
153154
// Timeout is a `vshard.call` timeout and vshard

crud/request_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"github.com/tarantool/go-iproto"
1010
"github.com/vmihailenco/msgpack/v5"
1111

12+
"github.com/tarantool/go-option"
1213
"github.com/tarantool/go-tarantool/v3"
1314
"github.com/tarantool/go-tarantool/v3/crud"
14-
"github.com/tarantool/go-option"
1515
)
1616

1717
const validSpace = "test" // Any valid value != default.

crud/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"github.com/vmihailenco/msgpack/v5"
88
"github.com/vmihailenco/msgpack/v5/msgpcode"
99

10-
"github.com/tarantool/go-tarantool/v3"
1110
"github.com/tarantool/go-option"
11+
"github.com/tarantool/go-tarantool/v3"
1212
)
1313

1414
func msgpackIsMap(code byte) bool {

crud/select.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

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

8-
"github.com/tarantool/go-tarantool/v3"
98
"github.com/tarantool/go-option"
9+
"github.com/tarantool/go-tarantool/v3"
1010
)
1111

1212
// SelectOpts describes options for `crud.select` method.

crud/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

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

8-
"github.com/tarantool/go-tarantool/v3"
98
"github.com/tarantool/go-option"
9+
"github.com/tarantool/go-tarantool/v3"
1010
)
1111

1212
// StatsRequest helps you to create request object to call `crud.stats`

crud/tarantool_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"github.com/stretchr/testify/require"
1111
"github.com/tarantool/go-iproto"
1212

13+
"github.com/tarantool/go-option"
1314
"github.com/tarantool/go-tarantool/v3"
1415
"github.com/tarantool/go-tarantool/v3/crud"
1516
"github.com/tarantool/go-tarantool/v3/test_helpers"
16-
"github.com/tarantool/go-option"
1717
)
1818

1919
var server = "127.0.0.1:3013"

0 commit comments

Comments
 (0)