Skip to content

Commit 1af7a63

Browse files
committed
api: add structures to describe CRUD response
1 parent 735b0a7 commit 1af7a63

22 files changed

+715
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ clean:
2727
.PHONY: deps
2828
deps: clean
2929
( cd ./queue/testdata; $(TTCTL) rocks install queue 1.2.1 )
30-
( cd ./crud/testdata; $(TTCTL) rocks install crud 0.14.1 )
30+
( cd ./crud/testdata; $(TTCTL) rocks install crud 1.0.0 )
3131

3232
.PHONY: datetime-timezones
3333
datetime-timezones:

crud/count.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// CountResult describes result for `crud.count` method.
10+
type CountResult = NumberResult
11+
912
// CountOpts describes options for `crud.count` method.
1013
type CountOpts struct {
1114
// Timeout is a `vshard.call` timeout and vshard

crud/delete.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// DeleteResult describes result for `crud.delete` method.
10+
type DeleteResult = Result
11+
912
// DeleteOpts describes options for `crud.delete` method.
1013
type DeleteOpts = SimpleOperationOpts
1114

crud/error.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package crud
2+
3+
// Error describes CRUD error object.
4+
type Error struct {
5+
// ClassName is an error class that implies its source (for example, "CountError").
6+
ClassName string
7+
// Err is the text of reason.
8+
Err string
9+
// File is a source code file where the error was caught.
10+
File string
11+
// Line is a number of line in the source code file where the error was caught.
12+
Line uint64
13+
// Stack is an information about the call stack when an error
14+
// occurs in a string format.
15+
Stack string
16+
// Str is the text of reason with error class.
17+
Str string
18+
}
19+
20+
// DecodeMsgpack provides custom msgpack decoder.
21+
func (crudErr *Error) DecodeMsgpack(d *decoder) error {
22+
l, err := d.DecodeMapLen()
23+
if err != nil {
24+
return err
25+
}
26+
for i := 0; i < l; i++ {
27+
key, err := d.DecodeString()
28+
if err != nil {
29+
return err
30+
}
31+
switch key {
32+
case "class_name":
33+
if crudErr.ClassName, err = d.DecodeString(); err != nil {
34+
return err
35+
}
36+
case "err":
37+
if crudErr.Err, err = d.DecodeString(); err != nil {
38+
return err
39+
}
40+
case "file":
41+
if crudErr.File, err = d.DecodeString(); err != nil {
42+
return err
43+
}
44+
case "line":
45+
if crudErr.Line, err = d.DecodeUint64(); err != nil {
46+
return err
47+
}
48+
case "stack":
49+
if crudErr.Stack, err = d.DecodeString(); err != nil {
50+
return err
51+
}
52+
case "str":
53+
if crudErr.Str, err = d.DecodeString(); err != nil {
54+
return err
55+
}
56+
default:
57+
if err := d.Skip(); err != nil {
58+
return err
59+
}
60+
}
61+
}
62+
63+
return nil
64+
}
65+
66+
// Error converts an Error to a string.
67+
func (err Error) Error() string {
68+
return err.Str
69+
}
70+
71+
// ErrorMany describes CRUD error object for `_many` methods.
72+
type ErrorMany struct {
73+
Errors []Error
74+
}
75+
76+
// Error converts an Error to a string.
77+
func (errs ErrorMany) Error() string {
78+
str := ""
79+
for _, err := range errs.Errors {
80+
str += err.Str
81+
}
82+
83+
return str
84+
}

crud/get.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// GetResult describes result for `crud.get` method.
10+
type GetResult = Result
11+
912
// GetOpts describes options for `crud.get` method.
1013
type GetOpts struct {
1114
// Timeout is a `vshard.call` timeout and vshard

crud/insert.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// InsertResult describes result for `crud.insert` method.
10+
type InsertResult = Result
11+
912
// InsertOpts describes options for `crud.insert` method.
1013
type InsertOpts = SimpleOperationOpts
1114

@@ -62,6 +65,9 @@ func (req *InsertRequest) Context(ctx context.Context) *InsertRequest {
6265
return req
6366
}
6467

68+
// InsertObjectResult describes result for `crud.insert_object` method.
69+
type InsertObjectResult = Result
70+
6571
// InsertObjectOpts describes options for `crud.insert_object` method.
6672
type InsertObjectOpts = SimpleOperationObjectOpts
6773

crud/insert_many.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// InsertManyResult describes result for `crud.insert_many` method.
10+
type InsertManyResult = ResultMany
11+
912
// InsertManyOpts describes options for `crud.insert_many` method.
1013
type InsertManyOpts = OperationManyOpts
1114

@@ -62,7 +65,10 @@ func (req *InsertManyRequest) Context(ctx context.Context) *InsertManyRequest {
6265
return req
6366
}
6467

65-
// InsertManyOpts describes options for `crud.insert_object_many` method.
68+
// InsertObjectManyResult describes result for `crud.insert_object_many` method.
69+
type InsertObjectManyResult = ResultMany
70+
71+
// InsertObjectManyOpts describes options for `crud.insert_object_many` method.
6672
type InsertObjectManyOpts = OperationObjectManyOpts
6773

6874
// InsertObjectManyRequest helps you to create request object to call

crud/len.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// LenResult describes result for `crud.len` method.
10+
type LenResult = NumberResult
11+
912
// LenOpts describes options for `crud.len` method.
1013
type LenOpts = BaseOpts
1114

crud/max.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// MaxResult describes result for `crud.max` method.
10+
type MaxResult = Result
11+
912
// MaxOpts describes options for `crud.max` method.
1013
type MaxOpts = BorderOpts
1114

crud/min.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// MinResult describes result for `crud.min` method.
10+
type MinResult = Result
11+
912
// MinOpts describes options for `crud.min` method.
1013
type MinOpts = BorderOpts
1114

crud/msgpack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
type encoder = msgpack.Encoder
13+
type decoder = msgpack.Decoder
1314

1415
// Object is an interface to describe object for CRUD methods.
1516
type Object interface {

crud/msgpack_v5.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
type encoder = msgpack.Encoder
13+
type decoder = msgpack.Decoder
1314

1415
// Object is an interface to describe object for CRUD methods.
1516
type Object interface {

crud/replace.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// ReplaceResult describes result for `crud.replace` method.
10+
type ReplaceResult = Result
11+
912
// ReplaceOpts describes options for `crud.replace` method.
1013
type ReplaceOpts = SimpleOperationOpts
1114

@@ -62,6 +65,9 @@ func (req *ReplaceRequest) Context(ctx context.Context) *ReplaceRequest {
6265
return req
6366
}
6467

68+
// ReplaceObjectResult describes result for `crud.replace_object` method.
69+
type ReplaceObjectResult = Result
70+
6571
// ReplaceObjectOpts describes options for `crud.replace_object` method.
6672
type ReplaceObjectOpts = SimpleOperationObjectOpts
6773

crud/replace_many.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"github.com/tarantool/go-tarantool"
77
)
88

9+
// ReplaceManyResult describes result for `crud.replace_many` method.
10+
type ReplaceManyResult = ResultMany
11+
912
// ReplaceManyOpts describes options for `crud.replace_many` method.
1013
type ReplaceManyOpts = OperationManyOpts
1114

@@ -62,6 +65,9 @@ func (req *ReplaceManyRequest) Context(ctx context.Context) *ReplaceManyRequest
6265
return req
6366
}
6467

68+
// ReplaceObjectManyResult describes result for `crud.replace_object_many` method.
69+
type ReplaceObjectManyResult = ResultMany
70+
6571
// ReplaceObjectManyOpts describes options for `crud.replace_object_many` method.
6672
type ReplaceObjectManyOpts = OperationObjectManyOpts
6773

0 commit comments

Comments
 (0)