Skip to content

Commit 7c99521

Browse files
committed
crud: allow any type as Tuple
This is necessary to use a custom types with custom encoders as tuples. Part of #271
1 parent d9a6049 commit 7c99521

10 files changed

+14
-17
lines changed

crud/common.go

-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ import (
5959
"github.com/tarantool/go-tarantool"
6060
)
6161

62-
// Tuple is a type to describe tuple for CRUD methods.
63-
type Tuple = []interface{}
64-
6562
type baseRequest struct {
6663
impl *tarantool.CallRequest
6764
}

crud/delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewDeleteRequest(space string) *DeleteRequest {
2929
req := new(DeleteRequest)
3030
req.initImpl("crud.delete")
3131
req.setSpace(space)
32-
req.key = Tuple{}
32+
req.key = []interface{}{}
3333
req.opts = DeleteOpts{}
3434
return req
3535
}

crud/get.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func NewGetRequest(space string) *GetRequest {
6464
req := new(GetRequest)
6565
req.initImpl("crud.get")
6666
req.setSpace(space)
67-
req.key = Tuple{}
67+
req.key = []interface{}{}
6868
req.opts = GetOpts{}
6969
return req
7070
}

crud/insert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewInsertRequest(space string) *InsertRequest {
2929
req := new(InsertRequest)
3030
req.initImpl("crud.insert")
3131
req.setSpace(space)
32-
req.tuple = Tuple{}
32+
req.tuple = []interface{}{}
3333
req.opts = InsertOpts{}
3434
return req
3535
}

crud/replace.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewReplaceRequest(space string) *ReplaceRequest {
2929
req := new(ReplaceRequest)
3030
req.initImpl("crud.replace")
3131
req.setSpace(space)
32-
req.tuple = Tuple{}
32+
req.tuple = []interface{}{}
3333
req.opts = ReplaceOpts{}
3434
return req
3535
}

crud/tarantool_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ var testGenerateDataCases = []struct {
347347
func generateTuples() []crud.Tuple {
348348
tpls := []crud.Tuple{}
349349
for i := 1010; i < 1020; i++ {
350-
tpls = append(tpls, crud.Tuple{uint(i), nil, "bla"})
350+
tpls = append(tpls, []interface{}{uint(i), nil, "bla"})
351351
}
352352

353353
return tpls

crud/tuple.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package crud
2+
3+
// Tuple is a type to describe tuple for CRUD methods. It can be any type that
4+
// msgpask can encode.
5+
type Tuple = interface{}

crud/unflatten_rows.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@ import (
88
func UnflattenRows(tuples []interface{}, format []interface{}) ([]MapObject, error) {
99
var (
1010
ok bool
11-
tuple Tuple
1211
fieldName string
1312
fieldInfo map[interface{}]interface{}
1413
)
1514

1615
objects := []MapObject{}
1716

18-
for _, rawTuple := range tuples {
17+
for _, tuple := range tuples {
1918
object := make(map[string]interface{})
20-
if tuple, ok = rawTuple.(Tuple); !ok {
21-
return nil, fmt.Errorf("Unexpected tuple format: %q", rawTuple)
22-
}
23-
24-
for fieldIdx, field := range tuple {
19+
for fieldIdx, field := range tuple.([]interface{}) {
2520
if fieldInfo, ok = format[fieldIdx].(map[interface{}]interface{}); !ok {
2621
return nil, fmt.Errorf("Unexpected space format: %q", format)
2722
}

crud/update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func NewUpdateRequest(space string) *UpdateRequest {
3131
req := new(UpdateRequest)
3232
req.initImpl("crud.update")
3333
req.setSpace(space)
34-
req.key = Tuple{}
34+
req.key = []interface{}{}
3535
req.operations = []Operation{}
3636
req.opts = UpdateOpts{}
3737
return req

crud/upsert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func NewUpsertRequest(space string) *UpsertRequest {
3131
req := new(UpsertRequest)
3232
req.initImpl("crud.upsert")
3333
req.setSpace(space)
34-
req.tuple = Tuple{}
34+
req.tuple = []interface{}{}
3535
req.operations = []Operation{}
3636
req.opts = UpsertOpts{}
3737
return req

0 commit comments

Comments
 (0)