Skip to content

Commit 1d890bc

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

21 files changed

+518
-2
lines changed

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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package crud
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
// CrudError describes CRUD error object.
8+
type CrudError struct {
9+
// ClassName is an error class that implies its source (for example, "CountError").
10+
ClassName string
11+
// Err is the text of reason.
12+
Err string
13+
// File is a source code file where the error was caught.
14+
File string
15+
// Line is a number of line in the source code file where the error was caught.
16+
Line uint64
17+
// Stack is an information about the call stack when an error
18+
// occurs in a string format.
19+
Stack string
20+
// Str is the text of reason with error class.
21+
Str string
22+
}
23+
24+
// NewCrudError creates new CRUD error.
25+
func NewCrudError(rawErr interface{}) (*CrudError, error) {
26+
var (
27+
mapErr map[interface{}]interface{}
28+
ok bool
29+
)
30+
31+
crudErr := CrudError{}
32+
33+
if mapErr, ok = rawErr.(map[interface{}]interface{}); !ok {
34+
return nil, fmt.Errorf("Unexpected CRUD error format: %#v", rawErr)
35+
}
36+
37+
if value, ok := mapErr["class_name"]; ok {
38+
if className, ok := value.(string); ok {
39+
crudErr.ClassName = className
40+
}
41+
}
42+
43+
if value, ok := mapErr["err"]; ok {
44+
if err, ok := value.(string); ok {
45+
crudErr.Err = err
46+
}
47+
}
48+
49+
if value, ok := mapErr["file"]; ok {
50+
if file, ok := value.(string); ok {
51+
crudErr.File = file
52+
}
53+
}
54+
55+
if value, ok := mapErr["line"]; ok {
56+
if line, ok := value.(uint64); ok {
57+
crudErr.Line = line
58+
}
59+
}
60+
61+
if value, ok := mapErr["stack"]; ok {
62+
if stack, ok := value.(string); ok {
63+
crudErr.Stack = stack
64+
}
65+
}
66+
67+
if value, ok := mapErr["str"]; ok {
68+
if str, ok := value.(string); ok {
69+
crudErr.Str = str
70+
}
71+
}
72+
73+
return &crudErr, nil
74+
}
75+
76+
// Error converts an CrudError to a string.
77+
func (err CrudError) Error() string {
78+
return err.Str
79+
}

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 = Result
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 = Result
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 {

0 commit comments

Comments
 (0)