forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch provides crud [1] methods as request objects to support CRUD API. The following methods are supported: * `insert` * `insert_object` * `insert_many` * `insert_object_many` * `get` * `update` * `delete` * `replace` * `replace_object` * `replace_many` * `replace_object_many` * `upsert` * `upsert_object` * `upsert_many` * `upsert_object_many` * `select` * `min` * `max` * `truncate` * `len` * `storage_info` * `count` * `stats` * `unflatten_rows` 1. https://github.com/tarantool/crud Closes #108
- Loading branch information
Showing
28 changed files
with
3,125 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package crud | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tarantool/go-tarantool" | ||
) | ||
|
||
type baseRequest struct { | ||
impl *tarantool.CallRequest | ||
} | ||
|
||
func (req *baseRequest) initImpl(methodName string) { | ||
req.impl = tarantool.NewCall17Request(methodName) | ||
} | ||
|
||
// Code returns IPROTO code for CRUD request. | ||
func (req *baseRequest) Code() int32 { | ||
return req.impl.Code() | ||
} | ||
|
||
// Ctx returns a context of CRUD request. | ||
func (req *baseRequest) Ctx() context.Context { | ||
return req.impl.Ctx() | ||
} | ||
|
||
// Async returns is CRUD request expects a response. | ||
func (req *baseRequest) Async() bool { | ||
return req.impl.Async() | ||
} | ||
|
||
type spaceRequest struct { | ||
baseRequest | ||
space interface{} | ||
} | ||
|
||
func (req *spaceRequest) setSpace(space interface{}) { | ||
req.space = space | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package crud | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tarantool/go-tarantool" | ||
) | ||
|
||
// CountRequest helps you to create request | ||
// object to call `crud.count` for execution | ||
// by a Connection. | ||
type CountRequest struct { | ||
spaceRequest | ||
conditions interface{} | ||
opts interface{} | ||
} | ||
|
||
// NewCountRequest returns a new empty CountRequest. | ||
func NewCountRequest(space interface{}) *SelectRequest { | ||
req := new(SelectRequest) | ||
req.initImpl("crud.count") | ||
req.setSpace(space) | ||
req.conditions = []interface{}{} | ||
req.opts = map[string]interface{}{} | ||
return req | ||
} | ||
|
||
// Conditions sets the conditions for the CountRequest request. | ||
// Note: default value is nil. | ||
func (req *CountRequest) Conditions(conditions interface{}) *CountRequest { | ||
req.conditions = conditions | ||
return req | ||
} | ||
|
||
// Opts sets the options for the CountRequest request. | ||
// Note: default value is nil. | ||
func (req *CountRequest) Opts(opts interface{}) *CountRequest { | ||
req.opts = opts | ||
return req | ||
} | ||
|
||
// Body fills an encoder with the call request body. | ||
func (req *CountRequest) Body(res tarantool.SchemaResolver, enc *encoder) error { | ||
req.impl.Args([]interface{}{req.space, req.conditions, req.opts}) | ||
return req.impl.Body(res, enc) | ||
} | ||
|
||
// Context sets a passed context to CRUD request. | ||
func (req *CountRequest) Context(ctx context.Context) *CountRequest { | ||
req.impl = req.impl.Context(ctx) | ||
|
||
return req | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package crud | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tarantool/go-tarantool" | ||
) | ||
|
||
// DeleteRequest helps you to create request | ||
// object to call `crud.delete` for execution | ||
// by a Connection. | ||
type DeleteRequest struct { | ||
spaceRequest | ||
key interface{} | ||
opts interface{} | ||
} | ||
|
||
// NewDeleteRequest returns a new empty DeleteRequest. | ||
func NewDeleteRequest(space interface{}) *DeleteRequest { | ||
req := new(DeleteRequest) | ||
req.initImpl("crud.delete") | ||
req.setSpace(space) | ||
req.key = []interface{}{} | ||
req.opts = map[string]interface{}{} | ||
return req | ||
} | ||
|
||
// Key sets the key for the DeleteRequest request. | ||
// Note: default value is nil. | ||
func (req *DeleteRequest) Key(key interface{}) *DeleteRequest { | ||
req.key = key | ||
return req | ||
} | ||
|
||
// Opts sets the options for the DeleteRequest request. | ||
// Note: default value is nil. | ||
func (req *DeleteRequest) Opts(opts interface{}) *DeleteRequest { | ||
req.opts = opts | ||
return req | ||
} | ||
|
||
// Body fills an encoder with the call request body. | ||
func (req *DeleteRequest) Body(res tarantool.SchemaResolver, enc *encoder) error { | ||
req.impl.Args([]interface{}{req.space, req.key, req.opts}) | ||
return req.impl.Body(res, enc) | ||
} | ||
|
||
// Context sets a passed context to CRUD request. | ||
func (req *DeleteRequest) Context(ctx context.Context) *DeleteRequest { | ||
req.impl = req.impl.Context(ctx) | ||
|
||
return req | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package crud | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tarantool/go-tarantool" | ||
) | ||
|
||
// GetRequest helps you to create request | ||
// object to call `crud.get` for execution | ||
// by a Connection. | ||
type GetRequest struct { | ||
spaceRequest | ||
key interface{} | ||
opts interface{} | ||
} | ||
|
||
// NewGetRequest returns a new empty GetRequest. | ||
func NewGetRequest(space interface{}) *GetRequest { | ||
req := new(GetRequest) | ||
req.initImpl("crud.get") | ||
req.setSpace(space) | ||
req.key = []interface{}{} | ||
req.opts = map[string]interface{}{} | ||
return req | ||
} | ||
|
||
// Key sets the key for the GetRequest request. | ||
// Note: default value is nil. | ||
func (req *GetRequest) Key(key interface{}) *GetRequest { | ||
req.key = key | ||
return req | ||
} | ||
|
||
// Opts sets the options for the GetRequest request. | ||
// Note: default value is nil. | ||
func (req *GetRequest) Opts(opts interface{}) *GetRequest { | ||
req.opts = opts | ||
return req | ||
} | ||
|
||
// Body fills an encoder with the call request body. | ||
func (req *GetRequest) Body(res tarantool.SchemaResolver, enc *encoder) error { | ||
req.impl.Args([]interface{}{req.space, req.key, req.opts}) | ||
return req.impl.Body(res, enc) | ||
} | ||
|
||
// Context sets a passed context to CRUD request. | ||
func (req *GetRequest) Context(ctx context.Context) *GetRequest { | ||
req.impl = req.impl.Context(ctx) | ||
|
||
return req | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package crud | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/tarantool/go-tarantool" | ||
) | ||
|
||
// InsertRequest helps you to create request | ||
// object to call `crud.insert` for execution | ||
// by a Connection. | ||
type InsertRequest struct { | ||
spaceRequest | ||
tuple interface{} | ||
opts interface{} | ||
} | ||
|
||
// NewInsertRequest returns a new empty InsertRequest. | ||
func NewInsertRequest(space interface{}) *InsertRequest { | ||
req := new(InsertRequest) | ||
req.initImpl("crud.insert") | ||
req.setSpace(space) | ||
req.tuple = []interface{}{} | ||
req.opts = map[string]interface{}{} | ||
return req | ||
} | ||
|
||
// Tuple sets the tuple for the InsertRequest request. | ||
// Note: default value is nil. | ||
func (req *InsertRequest) Tuple(tuple interface{}) *InsertRequest { | ||
req.tuple = tuple | ||
return req | ||
} | ||
|
||
// Opts sets the options for the insert request. | ||
// Note: default value is nil. | ||
func (req *InsertRequest) Opts(opts interface{}) *InsertRequest { | ||
req.opts = opts | ||
return req | ||
} | ||
|
||
// Body fills an encoder with the call request body. | ||
func (req *InsertRequest) Body(res tarantool.SchemaResolver, enc *encoder) error { | ||
req.impl.Args([]interface{}{req.space, req.tuple, req.opts}) | ||
return req.impl.Body(res, enc) | ||
} | ||
|
||
// Context sets a passed context to CRUD request. | ||
func (req *InsertRequest) Context(ctx context.Context) *InsertRequest { | ||
req.impl = req.impl.Context(ctx) | ||
|
||
return req | ||
} | ||
|
||
// InsertObjectRequest helps you to create request | ||
// object to call `crud.insert_object` for execution | ||
// by a Connection. | ||
type InsertObjectRequest struct { | ||
spaceRequest | ||
object interface{} | ||
opts interface{} | ||
} | ||
|
||
// NewInsertObjectRequest returns a new empty InsertObjectRequest. | ||
func NewInsertObjectRequest(space interface{}) *InsertObjectRequest { | ||
req := new(InsertObjectRequest) | ||
req.initImpl("crud.insert_object") | ||
req.setSpace(space) | ||
req.object = map[string]interface{}{} | ||
req.opts = map[string]interface{}{} | ||
return req | ||
} | ||
|
||
// Object sets the tuple for the InsertObjectRequest request. | ||
// Note: default value is nil. | ||
func (req *InsertObjectRequest) Object(object interface{}) *InsertObjectRequest { | ||
req.object = object | ||
return req | ||
} | ||
|
||
// Opts sets the options for the InsertObjectRequest request. | ||
// Note: default value is nil. | ||
func (req *InsertObjectRequest) Opts(opts interface{}) *InsertObjectRequest { | ||
req.opts = opts | ||
return req | ||
} | ||
|
||
// Body fills an encoder with the call request body. | ||
func (req *InsertObjectRequest) Body(res tarantool.SchemaResolver, enc *encoder) error { | ||
req.impl.Args([]interface{}{req.space, req.object, req.opts}) | ||
return req.impl.Body(res, enc) | ||
} | ||
|
||
// Context sets a passed context to CRUD request. | ||
func (req *InsertObjectRequest) Context(ctx context.Context) *InsertObjectRequest { | ||
req.impl = req.impl.Context(ctx) | ||
|
||
return req | ||
} |
Oops, something went wrong.