crud

package
v2.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2025 License: BSD-2-Clause Imports: 9 Imported by: 1

Documentation

Overview

Package crud with support of API of Tarantool's CRUD module.

Supported CRUD methods:

  • 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

Since: 1.11.0.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseOpts

type BaseOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
}

BaseOpts describes base options for CRUD operations.

func (BaseOpts) EncodeMsgpack

func (opts BaseOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type BoolResult

type BoolResult struct {
	Value bool
}

BoolResult describes CRUD result as an object containing bool.

func (*BoolResult) DecodeMsgpack

func (r *BoolResult) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

type BorderOpts

type BorderOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
	// Fields is field names for getting only a subset of fields.
	Fields OptTuple
	// FetchLatestMetadata guarantees the up-to-date metadata (space format)
	// in first return value, otherwise it may not take into account
	// the latest migration of the data format. Performance overhead is up to 15%.
	// Disabled by default.
	FetchLatestMetadata OptBool
}

BorderOpts describes options for `crud.min` and `crud.max`.

func (BorderOpts) EncodeMsgpack

func (opts BorderOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type Condition

type Condition struct {
	Operator Operator
	Field    string // Field name or index name.
	Value    interface{}
	// contains filtered or unexported fields
}

Condition describes CRUD condition as a table {operator, field-identifier, value}.

type CountOpts

type CountOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
	// Mode is a parameter with `write`/`read` possible values,
	// if `write` is specified then operation is performed on master.
	Mode OptString
	// PreferReplica is a parameter to specify preferred target
	// as one of the replicas.
	PreferReplica OptBool
	// Balance is a parameter to use replica according to vshard
	// load balancing policy.
	Balance OptBool
	// YieldEvery describes number of tuples processed to yield after.
	// Should be positive.
	YieldEvery OptUint
	// BucketId is a bucket ID.
	BucketId OptUint
	// ForceMapCall describes the map call is performed without any
	// optimizations even if full primary key equal condition is specified.
	ForceMapCall OptBool
	// Fullscan describes if a critical log entry will be skipped on
	// potentially long count.
	Fullscan OptBool
}

CountOpts describes options for `crud.count` method.

func (CountOpts) EncodeMsgpack

func (opts CountOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type CountRequest

type CountRequest struct {
	// contains filtered or unexported fields
}

CountRequest helps you to create request object to call `crud.count` for execution by a Connection.

func MakeCountRequest

func MakeCountRequest(space string) CountRequest

MakeCountRequest returns a new empty CountRequest.

func (CountRequest) Body

func (req CountRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (CountRequest) Conditions

func (req CountRequest) Conditions(conditions []Condition) CountRequest

Conditions sets the conditions for the CountRequest request. Note: default value is nil.

func (CountRequest) Context

func (req CountRequest) Context(ctx context.Context) CountRequest

Context sets a passed context to CRUD request.

func (CountRequest) Opts

func (req CountRequest) Opts(opts CountOpts) CountRequest

Opts sets the options for the CountRequest request. Note: default value is nil.

type CountResult

type CountResult = NumberResult

CountResult describes result for `crud.count` method.

type DeleteOpts

type DeleteOpts = SimpleOperationOpts

DeleteOpts describes options for `crud.delete` method.

type DeleteRequest

type DeleteRequest struct {
	// contains filtered or unexported fields
}

DeleteRequest helps you to create request object to call `crud.delete` for execution by a Connection.

func MakeDeleteRequest

func MakeDeleteRequest(space string) DeleteRequest

MakeDeleteRequest returns a new empty DeleteRequest.

func (DeleteRequest) Body

func (req DeleteRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (DeleteRequest) Context

func (req DeleteRequest) Context(ctx context.Context) DeleteRequest

Context sets a passed context to CRUD request.

func (DeleteRequest) Key

func (req DeleteRequest) Key(key Tuple) DeleteRequest

Key sets the key for the DeleteRequest request. Note: default value is nil.

func (DeleteRequest) Opts

func (req DeleteRequest) Opts(opts DeleteOpts) DeleteRequest

Opts sets the options for the DeleteRequest request. Note: default value is nil.

type Error

type Error struct {
	// ClassName is an error class that implies its source (for example, "CountError").
	ClassName string
	// Err is the text of reason.
	Err string
	// File is a source code file where the error was caught.
	File string
	// Line is a number of line in the source code file where the error was caught.
	Line uint64
	// Stack is an information about the call stack when an error
	// occurs in a string format.
	Stack string
	// Str is the text of reason with error class.
	Str string
	// OperationData is the object/tuple with which an error occurred.
	OperationData interface{}
	// contains filtered or unexported fields
}

Error describes CRUD error object.

func (*Error) DecodeMsgpack

func (e *Error) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

func (Error) Error

func (e Error) Error() string

Error converts an Error to a string.

type ErrorMany

type ErrorMany struct {
	Errors []Error
	// contains filtered or unexported fields
}

ErrorMany describes CRUD error object for `_many` methods.

func (*ErrorMany) DecodeMsgpack

func (e *ErrorMany) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

func (ErrorMany) Error

func (e ErrorMany) Error() string

Error converts an Error to a string.

type FieldFormat

type FieldFormat struct {
	Name       string
	Type       string
	IsNullable bool
}

FieldFormat contains field definition: {name='...',type='...'[,is_nullable=...]}.

func (*FieldFormat) DecodeMsgpack

func (format *FieldFormat) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

type GetOpts

type GetOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
	// Fields is field names for getting only a subset of fields.
	Fields OptTuple
	// BucketId is a bucket ID.
	BucketId OptUint
	// Mode is a parameter with `write`/`read` possible values,
	// if `write` is specified then operation is performed on master.
	Mode OptString
	// PreferReplica is a parameter to specify preferred target
	// as one of the replicas.
	PreferReplica OptBool
	// Balance is a parameter to use replica according to vshard
	// load balancing policy.
	Balance OptBool
	// FetchLatestMetadata guarantees the up-to-date metadata (space format)
	// in first return value, otherwise it may not take into account
	// the latest migration of the data format. Performance overhead is up to 15%.
	// Disabled by default.
	FetchLatestMetadata OptBool
}

GetOpts describes options for `crud.get` method.

func (GetOpts) EncodeMsgpack

func (opts GetOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type GetRequest

type GetRequest struct {
	// contains filtered or unexported fields
}

GetRequest helps you to create request object to call `crud.get` for execution by a Connection.

func MakeGetRequest

func MakeGetRequest(space string) GetRequest

MakeGetRequest returns a new empty GetRequest.

func (GetRequest) Body

func (req GetRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (GetRequest) Context

func (req GetRequest) Context(ctx context.Context) GetRequest

Context sets a passed context to CRUD request.

func (GetRequest) Key

func (req GetRequest) Key(key Tuple) GetRequest

Key sets the key for the GetRequest request. Note: default value is nil.

func (GetRequest) Opts

func (req GetRequest) Opts(opts GetOpts) GetRequest

Opts sets the options for the GetRequest request. Note: default value is nil.

type Index

type Index struct {
	Id     uint32      `msgpack:"id"`
	Name   string      `msgpack:"name"`
	Type   string      `msgpack:"type"`
	Unique bool        `msgpack:"unique"`
	Parts  []IndexPart `msgpack:"parts"`
}

Index contains a CRUD space index definition.

type IndexPart

type IndexPart struct {
	Fieldno     uint32 `msgpack:"fieldno"`
	Type        string `msgpack:"type"`
	ExcludeNull bool   `msgpack:"exclude_null"`
	IsNullable  bool   `msgpack:"is_nullable"`
}

IndexField contains a CRUD space index part definition.

type InsertManyOpts

type InsertManyOpts = OperationManyOpts

InsertManyOpts describes options for `crud.insert_many` method.

type InsertManyRequest

type InsertManyRequest struct {
	// contains filtered or unexported fields
}

InsertManyRequest helps you to create request object to call `crud.insert_many` for execution by a Connection.

func MakeInsertManyRequest

func MakeInsertManyRequest(space string) InsertManyRequest

MakeInsertManyRequest returns a new empty InsertManyRequest.

func (InsertManyRequest) Body

func (req InsertManyRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (InsertManyRequest) Context

Context sets a passed context to CRUD request.

func (InsertManyRequest) Opts

Opts sets the options for the InsertManyRequest request. Note: default value is nil.

func (InsertManyRequest) Tuples

func (req InsertManyRequest) Tuples(tuples Tuples) InsertManyRequest

Tuples sets the tuples for the InsertManyRequest request. Note: default value is nil.

type InsertObjectManyOpts

type InsertObjectManyOpts = OperationObjectManyOpts

InsertObjectManyOpts describes options for `crud.insert_object_many` method.

type InsertObjectManyRequest

type InsertObjectManyRequest struct {
	// contains filtered or unexported fields
}

InsertObjectManyRequest helps you to create request object to call `crud.insert_object_many` for execution by a Connection.

func MakeInsertObjectManyRequest

func MakeInsertObjectManyRequest(space string) InsertObjectManyRequest

MakeInsertObjectManyRequest returns a new empty InsertObjectManyRequest.

func (InsertObjectManyRequest) Body

func (req InsertObjectManyRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (InsertObjectManyRequest) Context

Context sets a passed context to CRUD request.

func (InsertObjectManyRequest) Objects

Objects sets the objects for the InsertObjectManyRequest request. Note: default value is nil.

func (InsertObjectManyRequest) Opts

Opts sets the options for the InsertObjectManyRequest request. Note: default value is nil.

type InsertObjectOpts

type InsertObjectOpts = SimpleOperationObjectOpts

InsertObjectOpts describes options for `crud.insert_object` method.

type InsertObjectRequest

type InsertObjectRequest struct {
	// contains filtered or unexported fields
}

InsertObjectRequest helps you to create request object to call `crud.insert_object` for execution by a Connection.

func MakeInsertObjectRequest

func MakeInsertObjectRequest(space string) InsertObjectRequest

MakeInsertObjectRequest returns a new empty InsertObjectRequest.

func (InsertObjectRequest) Body

func (req InsertObjectRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (InsertObjectRequest) Context

Context sets a passed context to CRUD request.

func (InsertObjectRequest) Object

func (req InsertObjectRequest) Object(object Object) InsertObjectRequest

Object sets the tuple for the InsertObjectRequest request. Note: default value is nil.

func (InsertObjectRequest) Opts

Opts sets the options for the InsertObjectRequest request. Note: default value is nil.

type InsertOpts

type InsertOpts = SimpleOperationOpts

InsertOpts describes options for `crud.insert` method.

type InsertRequest

type InsertRequest struct {
	// contains filtered or unexported fields
}

InsertRequest helps you to create request object to call `crud.insert` for execution by a Connection.

func MakeInsertRequest

func MakeInsertRequest(space string) InsertRequest

MakeInsertRequest returns a new empty InsertRequest.

func (InsertRequest) Body

func (req InsertRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (InsertRequest) Context

func (req InsertRequest) Context(ctx context.Context) InsertRequest

Context sets a passed context to CRUD request.

func (InsertRequest) Opts

func (req InsertRequest) Opts(opts InsertOpts) InsertRequest

Opts sets the options for the insert request. Note: default value is nil.

func (InsertRequest) Tuple

func (req InsertRequest) Tuple(tuple Tuple) InsertRequest

Tuple sets the tuple for the InsertRequest request. Note: default value is nil.

type LenOpts

type LenOpts = BaseOpts

LenOpts describes options for `crud.len` method.

type LenRequest

type LenRequest struct {
	// contains filtered or unexported fields
}

LenRequest helps you to create request object to call `crud.len` for execution by a Connection.

func MakeLenRequest

func MakeLenRequest(space string) LenRequest

MakeLenRequest returns a new empty LenRequest.

func (LenRequest) Body

func (req LenRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (LenRequest) Context

func (req LenRequest) Context(ctx context.Context) LenRequest

Context sets a passed context to CRUD request.

func (LenRequest) Opts

func (req LenRequest) Opts(opts LenOpts) LenRequest

Opts sets the options for the LenRequest request. Note: default value is nil.

type LenResult

type LenResult = NumberResult

LenResult describes result for `crud.len` method.

type MapObject

type MapObject map[string]interface{}

MapObject is a type to describe object as a map.

func UnflattenRows

func UnflattenRows(tuples []interface{}, format []interface{}) ([]MapObject, error)

UnflattenRows can be used to convert received tuples to objects.

func (MapObject) EncodeMsgpack

func (o MapObject) EncodeMsgpack(enc *msgpack.Encoder)

type MaxOpts

type MaxOpts = BorderOpts

MaxOpts describes options for `crud.max` method.

type MaxRequest

type MaxRequest struct {
	// contains filtered or unexported fields
}

MaxRequest helps you to create request object to call `crud.max` for execution by a Connection.

func MakeMaxRequest

func MakeMaxRequest(space string) MaxRequest

MakeMaxRequest returns a new empty MaxRequest.

func (MaxRequest) Body

func (req MaxRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (MaxRequest) Context

func (req MaxRequest) Context(ctx context.Context) MaxRequest

Context sets a passed context to CRUD request.

func (MaxRequest) Index

func (req MaxRequest) Index(index interface{}) MaxRequest

Index sets the index name/id for the MaxRequest request. Note: default value is nil.

func (MaxRequest) Opts

func (req MaxRequest) Opts(opts MaxOpts) MaxRequest

Opts sets the options for the MaxRequest request. Note: default value is nil.

type MinOpts

type MinOpts = BorderOpts

MinOpts describes options for `crud.min` method.

type MinRequest

type MinRequest struct {
	// contains filtered or unexported fields
}

MinRequest helps you to create request object to call `crud.min` for execution by a Connection.

func MakeMinRequest

func MakeMinRequest(space string) MinRequest

MakeMinRequest returns a new empty MinRequest.

func (MinRequest) Body

func (req MinRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (MinRequest) Context

func (req MinRequest) Context(ctx context.Context) MinRequest

Context sets a passed context to CRUD request.

func (MinRequest) Index

func (req MinRequest) Index(index interface{}) MinRequest

Index sets the index name/id for the MinRequest request. Note: default value is nil.

func (MinRequest) Opts

func (req MinRequest) Opts(opts MinOpts) MinRequest

Opts sets the options for the MinRequest request. Note: default value is nil.

type NumberResult

type NumberResult struct {
	Value uint64
}

NumberResult describes CRUD result as an object containing number.

func (*NumberResult) DecodeMsgpack

func (r *NumberResult) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

type Object

type Object = interface{}

Object is an interface to describe object for CRUD methods. It can be any type that msgpack can encode as a map.

type ObjectOperationsData

type ObjectOperationsData struct {
	Object     Object
	Operations []Operation
	// contains filtered or unexported fields
}

ObjectOperationsData contains object with operations to be applied to object.

type Objects

type Objects = interface{}

Objects is a type to describe an array of object for CRUD methods. It can be any type that msgpack can encode, but encoded data must be an array of objects.

See the reason why not just []Object: https://github.com/tarantool/go-tarantool/issues/365

Example (CustomType)

ExampleObjects_customType demonstrates how to use a slice of objects of a custom type as Objects to make a ReplaceObjectManyRequest.

conn := exampleConnect()

// The type will be encoded/decoded as a map.
type Tuple struct {
	Id       uint64  `msgpack:"id,omitempty"`
	BucketId *uint64 `msgpack:"bucket_id,omitempty"`
	Name     string  `msgpack:"name,omitempty"`
}
req := crud.MakeReplaceObjectManyRequest(exampleSpace).Objects([]Tuple{
	Tuple{
		Id:       2010,
		BucketId: nil,
		Name:     "bla",
	},
})

ret := crud.MakeResult(reflect.TypeOf(Tuple{}))
if err := conn.Do(req).GetTyped(&ret); err != nil {
	fmt.Printf("Failed to execute request: %s", err)
	return
}

fmt.Println(ret.Metadata)
rows := ret.Rows.([]Tuple)
if len(rows) == 1 {
	fmt.Println(rows[0].Id)
	fmt.Println(*rows[0].BucketId)
	fmt.Println(rows[0].Name)
} else {
	fmt.Printf("Unexpected result tuples count: %d", len(rows))
}
Output:

[{id unsigned false} {bucket_id unsigned true} {name string false}]
2010
45
bla

type Operation

type Operation struct {
	Operator Operator
	Field    interface{} // Number or string.
	Value    interface{}
	// Pos, Len, Replace fields used in the Splice operation.
	Pos     int
	Len     int
	Replace string
}

Operation describes CRUD operation as a table {operator, field_identifier, value}. Splice operation described as a table {operator, field_identifier, position, length, replace_string}.

func (Operation) EncodeMsgpack

func (o Operation) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack encodes Operation.

type OperationManyOpts

type OperationManyOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
	// Fields is field names for getting only a subset of fields.
	Fields OptTuple
	// StopOnError is a parameter to stop on a first error and report
	// error regarding the failed operation and error about what tuples
	// were not performed.
	StopOnError OptBool
	// RollbackOnError is a parameter because of what any failed operation
	// will lead to rollback on a storage, where the operation is failed.
	RollbackOnError OptBool
	// FetchLatestMetadata guarantees the up-to-date metadata (space format)
	// in first return value, otherwise it may not take into account
	// the latest migration of the data format. Performance overhead is up to 15%.
	// Disabled by default.
	FetchLatestMetadata OptBool
	// Noreturn suppresses successfully processed data (first return value is `nil`).
	// Disabled by default.
	Noreturn OptBool
}

OperationManyOpts describes options for CRUD operations with many tuples. It also covers `upsert_object_many` options.

func (OperationManyOpts) EncodeMsgpack

func (opts OperationManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type OperationObjectManyOpts

type OperationObjectManyOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
	// Fields is field names for getting only a subset of fields.
	Fields OptTuple
	// StopOnError is a parameter to stop on a first error and report
	// error regarding the failed operation and error about what tuples
	// were not performed.
	StopOnError OptBool
	// RollbackOnError is a parameter because of what any failed operation
	// will lead to rollback on a storage, where the operation is failed.
	RollbackOnError OptBool
	// SkipNullabilityCheckOnFlatten is a parameter to allow
	// setting null values to non-nullable fields.
	SkipNullabilityCheckOnFlatten OptBool
	// FetchLatestMetadata guarantees the up-to-date metadata (space format)
	// in first return value, otherwise it may not take into account
	// the latest migration of the data format. Performance overhead is up to 15%.
	// Disabled by default.
	FetchLatestMetadata OptBool
	// Noreturn suppresses successfully processed data (first return value is `nil`).
	// Disabled by default.
	Noreturn OptBool
}

OperationObjectManyOpts describes options for CRUD operations with many objects. It doesn't cover `upsert_object_many` options.

func (OperationObjectManyOpts) EncodeMsgpack

func (opts OperationObjectManyOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type Operator

type Operator string

Operator is a type to describe operator of operation.

const (
	// Eq - comparison operator for "equal".
	Eq Operator = "="
	// Lt - comparison operator for "less than".
	Lt Operator = "<"
	// Le - comparison operator for "less than or equal".
	Le Operator = "<="
	// Gt - comparison operator for "greater than".
	Gt Operator = ">"
	// Ge - comparison operator for "greater than or equal".
	Ge Operator = ">="
)
const (
	// Add - operator for addition.
	Add Operator = "+"
	// Sub - operator for subtraction.
	Sub Operator = "-"
	// And - operator for bitwise AND.
	And Operator = "&"
	// Or - operator for bitwise OR.
	Or Operator = "|"
	// Xor - operator for bitwise XOR.
	Xor Operator = "^"
	// Splice - operator for string splice.
	Splice Operator = ":"
	// Insert - operator for insertion of a new field.
	Insert Operator = "!"
	// Delete - operator for deletion.
	Delete Operator = "#"
	// Assign - operator for assignment.
	Assign Operator = "="
)

type OptBool

type OptBool struct {
	// contains filtered or unexported fields
}

OptBool is an optional bool.

func MakeOptBool

func MakeOptBool(value bool) OptBool

MakeOptBool creates an optional bool from value.

func (OptBool) Get

func (opt OptBool) Get() (bool, bool)

Get returns the boolean value or an error if not present.

type OptFloat64

type OptFloat64 struct {
	// contains filtered or unexported fields
}

OptFloat64 is an optional float64.

func MakeOptFloat64

func MakeOptFloat64(value float64) OptFloat64

MakeOptFloat64 creates an optional float64 from value.

func (OptFloat64) Get

func (opt OptFloat64) Get() (float64, bool)

Get returns the float64 value or an error if not present.

type OptInt

type OptInt struct {
	// contains filtered or unexported fields
}

OptInt is an optional int.

func MakeOptInt

func MakeOptInt(value int) OptInt

MakeOptInt creates an optional int from value.

func (OptInt) Get

func (opt OptInt) Get() (int, bool)

Get returns the integer value or an error if not present.

type OptString

type OptString struct {
	// contains filtered or unexported fields
}

OptString is an optional string.

func MakeOptString

func MakeOptString(value string) OptString

MakeOptString creates an optional string from value.

func (OptString) Get

func (opt OptString) Get() (string, bool)

Get returns the string value or an error if not present.

type OptTuple

type OptTuple struct {
	// contains filtered or unexported fields
}

OptTuple is an optional tuple.

func MakeOptTuple

func MakeOptTuple(tuple interface{}) OptTuple

MakeOptTuple creates an optional tuple from tuple.

func (*OptTuple) Get

func (o *OptTuple) Get() (interface{}, bool)

Get returns the tuple value or an error if not present.

type OptUint

type OptUint struct {
	// contains filtered or unexported fields
}

OptUint is an optional uint.

func MakeOptUint

func MakeOptUint(value uint) OptUint

MakeOptUint creates an optional uint from value.

func (OptUint) Get

func (opt OptUint) Get() (uint, bool)

Get returns the integer value or an error if not present.

type ReplaceManyOpts

type ReplaceManyOpts = OperationManyOpts

ReplaceManyOpts describes options for `crud.replace_many` method.

type ReplaceManyRequest

type ReplaceManyRequest struct {
	// contains filtered or unexported fields
}

ReplaceManyRequest helps you to create request object to call `crud.replace_many` for execution by a Connection.

func MakeReplaceManyRequest

func MakeReplaceManyRequest(space string) ReplaceManyRequest

MakeReplaceManyRequest returns a new empty ReplaceManyRequest.

func (ReplaceManyRequest) Body

func (req ReplaceManyRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (ReplaceManyRequest) Context

Context sets a passed context to CRUD request.

func (ReplaceManyRequest) Opts

Opts sets the options for the ReplaceManyRequest request. Note: default value is nil.

func (ReplaceManyRequest) Tuples

func (req ReplaceManyRequest) Tuples(tuples Tuples) ReplaceManyRequest

Tuples sets the tuples for the ReplaceManyRequest request. Note: default value is nil.

type ReplaceObjectManyOpts

type ReplaceObjectManyOpts = OperationObjectManyOpts

ReplaceObjectManyOpts describes options for `crud.replace_object_many` method.

type ReplaceObjectManyRequest

type ReplaceObjectManyRequest struct {
	// contains filtered or unexported fields
}

ReplaceObjectManyRequest helps you to create request object to call `crud.replace_object_many` for execution by a Connection.

func MakeReplaceObjectManyRequest

func MakeReplaceObjectManyRequest(space string) ReplaceObjectManyRequest

MakeReplaceObjectManyRequest returns a new empty ReplaceObjectManyRequest.

func (ReplaceObjectManyRequest) Body

func (req ReplaceObjectManyRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (ReplaceObjectManyRequest) Context

Context sets a passed context to CRUD request.

func (ReplaceObjectManyRequest) Objects

Objects sets the tuple for the ReplaceObjectManyRequest request. Note: default value is nil.

func (ReplaceObjectManyRequest) Opts

Opts sets the options for the ReplaceObjectManyRequest request. Note: default value is nil.

type ReplaceObjectOpts

type ReplaceObjectOpts = SimpleOperationObjectOpts

ReplaceObjectOpts describes options for `crud.replace_object` method.

type ReplaceObjectRequest

type ReplaceObjectRequest struct {
	// contains filtered or unexported fields
}

ReplaceObjectRequest helps you to create request object to call `crud.replace_object` for execution by a Connection.

func MakeReplaceObjectRequest

func MakeReplaceObjectRequest(space string) ReplaceObjectRequest

MakeReplaceObjectRequest returns a new empty ReplaceObjectRequest.

func (ReplaceObjectRequest) Body

func (req ReplaceObjectRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (ReplaceObjectRequest) Context

Context sets a passed context to CRUD request.

func (ReplaceObjectRequest) Object

Object sets the tuple for the ReplaceObjectRequest request. Note: default value is nil.

func (ReplaceObjectRequest) Opts

Opts sets the options for the ReplaceObjectRequest request. Note: default value is nil.

type ReplaceOpts

type ReplaceOpts = SimpleOperationOpts

ReplaceOpts describes options for `crud.replace` method.

type ReplaceRequest

type ReplaceRequest struct {
	// contains filtered or unexported fields
}

ReplaceRequest helps you to create request object to call `crud.replace` for execution by a Connection.

func MakeReplaceRequest

func MakeReplaceRequest(space string) ReplaceRequest

MakeReplaceRequest returns a new empty ReplaceRequest.

func (ReplaceRequest) Body

func (req ReplaceRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (ReplaceRequest) Context

func (req ReplaceRequest) Context(ctx context.Context) ReplaceRequest

Context sets a passed context to CRUD request.

func (ReplaceRequest) Opts

func (req ReplaceRequest) Opts(opts ReplaceOpts) ReplaceRequest

Opts sets the options for the ReplaceRequest request. Note: default value is nil.

func (ReplaceRequest) Tuple

func (req ReplaceRequest) Tuple(tuple Tuple) ReplaceRequest

Tuple sets the tuple for the ReplaceRequest request. Note: default value is nil.

type Result

type Result struct {
	Metadata []FieldFormat
	Rows     interface{}
	// contains filtered or unexported fields
}

Result describes CRUD result as an object containing metadata and rows.

Example (Error)

ExampleResult_error demonstrates how to use a helper type Result to handle a crud error.

conn := exampleConnect()
req := crud.MakeReplaceRequest("not_exist").
	Tuple([]interface{}{uint(2010), nil, "bla"})

ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
	crudErr := err.(crud.Error)
	fmt.Printf("Failed to execute request: %s", crudErr)
} else {
	fmt.Println(ret.Metadata)
	fmt.Println(ret.Rows)
}
Output:

Failed to execute request: ReplaceError: Space "not_exist" doesn't exist
Example (ErrorMany)

ExampleResult_errorMany demonstrates how to use a helper type Result to handle a crud error for a *ManyRequest.

conn := exampleConnect()
initReq := crud.MakeReplaceRequest("not_exist").
	Tuple([]interface{}{uint(2010), nil, "bla"})
if _, err := conn.Do(initReq).Get(); err != nil {
	fmt.Printf("Failed to initialize the example: %s\n", err)
}

req := crud.MakeInsertManyRequest(exampleSpace).
	Tuples([]crud.Tuple{
		[]interface{}{uint(2010), nil, "bla"},
		[]interface{}{uint(2010), nil, "bla"},
	})
ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
	crudErr := err.(crud.ErrorMany)
	// We need to trim the error message to make the example repeatable.
	errmsg := crudErr.Error()[:10]
	fmt.Printf("Failed to execute request: %s", errmsg)
} else {
	fmt.Println(ret.Metadata)
	fmt.Println(ret.Rows)
}
Output:

Failed to execute request: CallError:
Example (Many)

ExampleResult_many demonstrates that there is no difference in a response from *ManyRequest.

conn := exampleConnect()
req := crud.MakeReplaceManyRequest(exampleSpace).
	Tuples([]crud.Tuple{
		[]interface{}{uint(2010), nil, "bla"},
		[]interface{}{uint(2011), nil, "bla"},
	})

ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
	fmt.Printf("Failed to execute request: %s", err)
	return
}

fmt.Println(ret.Metadata)
fmt.Println(ret.Rows)
Output:

[{id unsigned false} {bucket_id unsigned true} {name string false}]
[[2010 45 bla] [2011 4 bla]]
Example (Noreturn)

ExampleResult_noreturn demonstrates noreturn request: a data change request where you don't need to retrieve the result, just want to know whether it was successful or not.

conn := exampleConnect()
req := crud.MakeReplaceManyRequest(exampleSpace).
	Tuples([]crud.Tuple{
		[]interface{}{uint(2010), nil, "bla"},
		[]interface{}{uint(2011), nil, "bla"},
	}).
	Opts(crud.ReplaceManyOpts{
		Noreturn: crud.MakeOptBool(true),
	})

ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
	fmt.Printf("Failed to execute request: %s", err)
	return
}

fmt.Println(ret.Metadata)
fmt.Println(ret.Rows)
Output:

[]
<nil>
Example (OperationData)

ExampleResult_operationData demonstrates how to obtain information about erroneous objects from crud.Error using `OperationData` field.

conn := exampleConnect()
req := crud.MakeInsertObjectManyRequest(exampleSpace).Objects([]crud.Object{
	crud.MapObject{
		"id":        2,
		"bucket_id": 3,
		"name":      "Makar",
	},
	crud.MapObject{
		"id":        2,
		"bucket_id": 3,
		"name":      "Vasya",
	},
	crud.MapObject{
		"id":        3,
		"bucket_id": 5,
	},
})

ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
	crudErrs := err.(crud.ErrorMany)
	fmt.Println("Erroneous data:")
	for _, crudErr := range crudErrs.Errors {
		fmt.Println(crudErr.OperationData)
	}
} else {
	fmt.Println(ret.Metadata)
	fmt.Println(ret.Rows)
}
Output:

Erroneous data:
[2 3 Vasya]
map[bucket_id:5 id:3]
Example (OperationDataCustomType)

ExampleResult_operationDataCustomType demonstrates the ability to cast `OperationData` field, extracted from a CRUD error during decoding using crud.Result, to a custom type. The type of `OperationData` is determined as the crud.Result row type.

conn := exampleConnect()
req := crud.MakeInsertObjectManyRequest(exampleSpace).Objects([]crud.Object{
	crud.MapObject{
		"id":        1,
		"bucket_id": 3,
		"name":      "Makar",
	},
	crud.MapObject{
		"id":        1,
		"bucket_id": 3,
		"name":      "Vasya",
	},
	crud.MapObject{
		"id":        3,
		"bucket_id": 5,
	},
})

type Tuple struct {
	Id       uint64 `msgpack:"id,omitempty"`
	BucketId uint64 `msgpack:"bucket_id,omitempty"`
	Name     string `msgpack:"name,omitempty"`
}

ret := crud.MakeResult(reflect.TypeOf(Tuple{}))
if err := conn.Do(req).GetTyped(&ret); err != nil {
	crudErrs := err.(crud.ErrorMany)
	fmt.Println("Erroneous data:")
	for _, crudErr := range crudErrs.Errors {
		operationData := crudErr.OperationData.(Tuple)
		fmt.Println(operationData)
	}
} else {
	fmt.Println(ret.Metadata)
	fmt.Println(ret.Rows)
}
Output:

Erroneous data:
{1 3 Vasya}
{3 5 }
Example (RowsCustomType)

ExampleResult_rowsCustomType demonstrates how to use a helper type Result to decode a crud response. In this example, rows are decoded as a custom type.

conn := exampleConnect()
req := crud.MakeReplaceRequest(exampleSpace).
	Tuple([]interface{}{uint(2010), nil, "bla"})

type Tuple struct {
	_msgpack struct{} `msgpack:",asArray"` //nolint: structcheck,unused
	Id       uint64
	BucketId uint64
	Name     string
}
ret := crud.MakeResult(reflect.TypeOf(Tuple{}))

if err := conn.Do(req).GetTyped(&ret); err != nil {
	fmt.Printf("Failed to execute request: %s", err)
	return
}

fmt.Println(ret.Metadata)
rows := ret.Rows.([]Tuple)
fmt.Println(rows)
Output:

[{id unsigned false} {bucket_id unsigned true} {name string false}]
[{{} 2010 45 bla}]
Example (RowsInterface)

ExampleResult_rowsInterface demonstrates how to use a helper type Result to decode a crud response. In this example, rows are decoded as an interface{} type.

conn := exampleConnect()
req := crud.MakeReplaceRequest(exampleSpace).
	Tuple([]interface{}{uint(2010), nil, "bla"})

ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
	fmt.Printf("Failed to execute request: %s", err)
	return
}

fmt.Println(ret.Metadata)
fmt.Println(ret.Rows)
Output:

[{id unsigned false} {bucket_id unsigned true} {name string false}]
[[2010 45 bla]]

func MakeResult

func MakeResult(rowType reflect.Type) Result

MakeResult create a Result object with a custom row type for decoding.

func (*Result) DecodeMsgpack

func (r *Result) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

type Schema

type Schema map[string]SpaceSchema

Schema contains CRUD cluster schema definition.

Example
conn := exampleConnect()

req := crud.MakeSchemaRequest()
var result crud.SchemaResult

if err := conn.Do(req).GetTyped(&result); err != nil {
	fmt.Printf("Failed to execute request: %s", err)
	return
}

// Schema may differ between different Tarantool versions.
// https://github.com/tarantool/tarantool/issues/4091
// https://github.com/tarantool/tarantool/commit/17c9c034933d726925910ce5bf8b20e8e388f6e3
for spaceName, spaceSchema := range result.Value {
	fmt.Printf("Space format for '%s' is as follows:\n", spaceName)

	for _, field := range spaceSchema.Format {
		fmt.Printf("    - field '%s' with type '%s'\n", field.Name, field.Type)
	}
}
Output:

Space format for 'test' is as follows:
    - field 'id' with type 'unsigned'
    - field 'bucket_id' with type 'unsigned'
    - field 'name' with type 'string'

func (*Schema) DecodeMsgpack

func (schema *Schema) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

type SchemaOpts

type SchemaOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
	// Cached defines whether router should reload storage schema on call.
	Cached OptBool
}

SchemaOpts describes options for `crud.schema` method.

func (SchemaOpts) EncodeMsgpack

func (opts SchemaOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type SchemaRequest

type SchemaRequest struct {
	// contains filtered or unexported fields
}

SchemaRequest helps you to create request object to call `crud.schema` for execution by a Connection.

func MakeSchemaRequest

func MakeSchemaRequest() SchemaRequest

MakeSchemaRequest returns a new empty SchemaRequest.

func (SchemaRequest) Async

func (req SchemaRequest) Async() bool

Async returns is CRUD request expects a response.

func (SchemaRequest) Body

func (req SchemaRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (SchemaRequest) Context

func (req SchemaRequest) Context(ctx context.Context) SchemaRequest

Context sets a passed context to CRUD request.

func (SchemaRequest) Ctx

func (req SchemaRequest) Ctx() context.Context

Ctx returns a context of CRUD request.

func (SchemaRequest) Opts

func (req SchemaRequest) Opts(opts SchemaOpts) SchemaRequest

Opts sets the options for the SchemaRequest request. Note: default value is nil.

func (SchemaRequest) Response

func (req SchemaRequest) Response(header tarantool.Header,
	body io.Reader) (tarantool.Response, error)

Response creates a response for the baseRequest.

func (SchemaRequest) Space

func (req SchemaRequest) Space(space string) SchemaRequest

Space sets the space name for the SchemaRequest request. Note: default value is nil.

func (SchemaRequest) Type

func (req SchemaRequest) Type() iproto.Type

Type returns IPROTO type for CRUD request.

type SchemaResult

type SchemaResult struct {
	Value Schema
}

SchemaResult contains a schema request result for all spaces.

func (*SchemaResult) DecodeMsgpack

func (result *SchemaResult) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

type SelectOpts

type SelectOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
	// Fields is field names for getting only a subset of fields.
	Fields OptTuple
	// BucketId is a bucket ID.
	BucketId OptUint
	// Mode is a parameter with `write`/`read` possible values,
	// if `write` is specified then operation is performed on master.
	Mode OptString
	// PreferReplica is a parameter to specify preferred target
	// as one of the replicas.
	PreferReplica OptBool
	// Balance is a parameter to use replica according to vshard
	// load balancing policy.
	Balance OptBool
	// First describes the maximum count of the objects to return.
	First OptInt
	// After is a tuple after which objects should be selected.
	After OptTuple
	// BatchSize is a number of tuples to process per one request to storage.
	BatchSize OptUint
	// ForceMapCall describes the map call is performed without any
	// optimizations even if full primary key equal condition is specified.
	ForceMapCall OptBool
	// Fullscan describes if a critical log entry will be skipped on
	// potentially long select.
	Fullscan OptBool
	// FetchLatestMetadata guarantees the up-to-date metadata (space format)
	// in first return value, otherwise it may not take into account
	// the latest migration of the data format. Performance overhead is up to 15%.
	// Disabled by default.
	FetchLatestMetadata OptBool
	// YieldEvery describes number of tuples processed to yield after.
	// Should be positive.
	YieldEvery OptUint
}

SelectOpts describes options for `crud.select` method.

func (SelectOpts) EncodeMsgpack

func (opts SelectOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type SelectRequest

type SelectRequest struct {
	// contains filtered or unexported fields
}

SelectRequest helps you to create request object to call `crud.select` for execution by a Connection.

Example (Pagination)
conn := exampleConnect()

const (
	fromTuple = 5
	allTuples = 10
)
var tuple interface{}
for i := 0; i < allTuples; i++ {
	req := crud.MakeReplaceRequest(exampleSpace).
		Tuple([]interface{}{uint(3000 + i), nil, "bla"})
	ret := crud.Result{}
	if err := conn.Do(req).GetTyped(&ret); err != nil {
		fmt.Printf("Failed to initialize the example: %s\n", err)
		return
	}
	if i == fromTuple {
		tuple = ret.Rows.([]interface{})[0]
	}
}

req := crud.MakeSelectRequest(exampleSpace).
	Opts(crud.SelectOpts{
		First: crud.MakeOptInt(2),
		After: crud.MakeOptTuple(tuple),
	})
ret := crud.Result{}
if err := conn.Do(req).GetTyped(&ret); err != nil {
	fmt.Printf("Failed to execute request: %s", err)
	return
}
fmt.Println(ret.Metadata)
fmt.Println(ret.Rows)
Output:

[{id unsigned false} {bucket_id unsigned true} {name string false}]
[[3006 32 bla] [3007 33 bla]]

func MakeSelectRequest

func MakeSelectRequest(space string) SelectRequest

MakeSelectRequest returns a new empty SelectRequest.

func (SelectRequest) Body

func (req SelectRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (SelectRequest) Conditions

func (req SelectRequest) Conditions(conditions []Condition) SelectRequest

Conditions sets the conditions for the SelectRequest request. Note: default value is nil.

func (SelectRequest) Context

func (req SelectRequest) Context(ctx context.Context) SelectRequest

Context sets a passed context to CRUD request.

func (SelectRequest) Opts

func (req SelectRequest) Opts(opts SelectOpts) SelectRequest

Opts sets the options for the SelectRequest request. Note: default value is nil.

type SimpleOperationObjectOpts

type SimpleOperationObjectOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
	// Fields is field names for getting only a subset of fields.
	Fields OptTuple
	// BucketId is a bucket ID.
	BucketId OptUint
	// SkipNullabilityCheckOnFlatten is a parameter to allow
	// setting null values to non-nullable fields.
	SkipNullabilityCheckOnFlatten OptBool
	// FetchLatestMetadata guarantees the up-to-date metadata (space format)
	// in first return value, otherwise it may not take into account
	// the latest migration of the data format. Performance overhead is up to 15%.
	// Disabled by default.
	FetchLatestMetadata OptBool
	// Noreturn suppresses successfully processed data (first return value is `nil`).
	// Disabled by default.
	Noreturn OptBool
}

SimpleOperationObjectOpts describes options for simple CRUD operations with objects. It doesn't cover `upsert_object` options.

func (SimpleOperationObjectOpts) EncodeMsgpack

func (opts SimpleOperationObjectOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type SimpleOperationOpts

type SimpleOperationOpts struct {
	// Timeout is a `vshard.call` timeout and vshard
	// master discovery timeout (in seconds).
	Timeout OptFloat64
	// VshardRouter is cartridge vshard group name or
	// vshard router instance.
	VshardRouter OptString
	// Fields is field names for getting only a subset of fields.
	Fields OptTuple
	// BucketId is a bucket ID.
	BucketId OptUint
	// FetchLatestMetadata guarantees the up-to-date metadata (space format)
	// in first return value, otherwise it may not take into account
	// the latest migration of the data format. Performance overhead is up to 15%.
	// Disabled by default.
	FetchLatestMetadata OptBool
	// Noreturn suppresses successfully processed data (first return value is `nil`).
	// Disabled by default.
	Noreturn OptBool
}

SimpleOperationOpts describes options for simple CRUD operations. It also covers `upsert_object` options.

func (SimpleOperationOpts) EncodeMsgpack

func (opts SimpleOperationOpts) EncodeMsgpack(enc *msgpack.Encoder) error

EncodeMsgpack provides custom msgpack encoder.

type SpaceSchema

type SpaceSchema struct {
	Format  []FieldFormat    `msgpack:"format"`
	Indexes map[uint32]Index `msgpack:"indexes"`
}

SpaceSchema contains a single CRUD space schema definition.

type SpaceSchemaResult

type SpaceSchemaResult struct {
	Value SpaceSchema
}

SchemaResult contains a schema request result for a single space.

func (*SpaceSchemaResult) DecodeMsgpack

func (result *SpaceSchemaResult) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

type StatsRequest

type StatsRequest struct {
	// contains filtered or unexported fields
}

StatsRequest helps you to create request object to call `crud.stats` for execution by a Connection.

func MakeStatsRequest

func MakeStatsRequest() StatsRequest

MakeStatsRequest returns a new empty StatsRequest.

func (StatsRequest) Async

func (req StatsRequest) Async() bool

Async returns is CRUD request expects a response.

func (StatsRequest) Body

func (req StatsRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (StatsRequest) Context

func (req StatsRequest) Context(ctx context.Context) StatsRequest

Context sets a passed context to CRUD request.

func (StatsRequest) Ctx

func (req StatsRequest) Ctx() context.Context

Ctx returns a context of CRUD request.

func (StatsRequest) Response

func (req StatsRequest) Response(header tarantool.Header,
	body io.Reader) (tarantool.Response, error)

Response creates a response for the baseRequest.

func (StatsRequest) Space

func (req StatsRequest) Space(space string) StatsRequest

Space sets the space name for the StatsRequest request. Note: default value is nil.

func (StatsRequest) Type

func (req StatsRequest) Type() iproto.Type

Type returns IPROTO type for CRUD request.

type StatusTable

type StatusTable struct {
	Status   string
	IsMaster bool
	Message  string
}

StatusTable describes information for instance.

func (*StatusTable) DecodeMsgpack

func (statusTable *StatusTable) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

type StorageInfoOpts

type StorageInfoOpts = BaseOpts

StorageInfoOpts describes options for `crud.storage_info` method.

type StorageInfoRequest

type StorageInfoRequest struct {
	// contains filtered or unexported fields
}

StorageInfoRequest helps you to create request object to call `crud.storage_info` for execution by a Connection.

func MakeStorageInfoRequest

func MakeStorageInfoRequest() StorageInfoRequest

MakeStorageInfoRequest returns a new empty StorageInfoRequest.

func (StorageInfoRequest) Async

func (req StorageInfoRequest) Async() bool

Async returns is CRUD request expects a response.

func (StorageInfoRequest) Body

func (req StorageInfoRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (StorageInfoRequest) Context

Context sets a passed context to CRUD request.

func (StorageInfoRequest) Ctx

func (req StorageInfoRequest) Ctx() context.Context

Ctx returns a context of CRUD request.

func (StorageInfoRequest) Opts

Opts sets the options for the torageInfoRequest request. Note: default value is nil.

func (StorageInfoRequest) Response

func (req StorageInfoRequest) Response(header tarantool.Header,
	body io.Reader) (tarantool.Response, error)

Response creates a response for the baseRequest.

func (StorageInfoRequest) Type

func (req StorageInfoRequest) Type() iproto.Type

Type returns IPROTO type for CRUD request.

type StorageInfoResult

type StorageInfoResult struct {
	Info map[string]StatusTable
}

StorageInfoResult describes result for `crud.storage_info` method.

func (*StorageInfoResult) DecodeMsgpack

func (r *StorageInfoResult) DecodeMsgpack(d *msgpack.Decoder) error

DecodeMsgpack provides custom msgpack decoder.

type TruncateOpts

type TruncateOpts = BaseOpts

TruncateOpts describes options for `crud.truncate` method.

type TruncateRequest

type TruncateRequest struct {
	// contains filtered or unexported fields
}

TruncateRequest helps you to create request object to call `crud.truncate` for execution by a Connection.

func MakeTruncateRequest

func MakeTruncateRequest(space string) TruncateRequest

MakeTruncateRequest returns a new empty TruncateRequest.

func (TruncateRequest) Body

func (req TruncateRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (TruncateRequest) Context

Context sets a passed context to CRUD request.

func (TruncateRequest) Opts

Opts sets the options for the TruncateRequest request. Note: default value is nil.

type TruncateResult

type TruncateResult = BoolResult

TruncateResult describes result for `crud.truncate` method.

type Tuple

type Tuple = interface{}

Tuple is a type to describe tuple for CRUD methods. It can be any type that msgpask can encode as an array.

type TupleOperationsData

type TupleOperationsData struct {
	Tuple      Tuple
	Operations []Operation
	// contains filtered or unexported fields
}

TupleOperationsData contains tuple with operations to be applied to tuple.

type Tuples

type Tuples = interface{}

Tuples is a type to describe an array of tuples for CRUD methods. It can be any type that msgpack can encode, but encoded data must be an array of tuples.

See the reason why not just []Tuple: https://github.com/tarantool/go-tarantool/issues/365

Example (CustomType)

ExampleTuples_customType demonstrates how to use a slice of objects of a custom type as Tuples to make a ReplaceManyRequest.

conn := exampleConnect()

// The type will be encoded/decoded as an array.
type Tuple struct {
	_msgpack struct{} `msgpack:",asArray"` //nolint: structcheck,unused
	Id       uint64
	BucketId *uint64
	Name     string
}
req := crud.MakeReplaceManyRequest(exampleSpace).Tuples([]Tuple{
	Tuple{
		Id:       2010,
		BucketId: nil,
		Name:     "bla",
	},
})

ret := crud.MakeResult(reflect.TypeOf(Tuple{}))
if err := conn.Do(req).GetTyped(&ret); err != nil {
	fmt.Printf("Failed to execute request: %s", err)
	return
}

fmt.Println(ret.Metadata)
rows := ret.Rows.([]Tuple)
if len(rows) == 1 {
	fmt.Println(rows[0].Id)
	fmt.Println(*rows[0].BucketId)
	fmt.Println(rows[0].Name)
} else {
	fmt.Printf("Unexpected result tuples count: %d", len(rows))
}
Output:

[{id unsigned false} {bucket_id unsigned true} {name string false}]
2010
45
bla

type UpdateOpts

type UpdateOpts = SimpleOperationOpts

UpdateOpts describes options for `crud.update` method.

type UpdateRequest

type UpdateRequest struct {
	// contains filtered or unexported fields
}

UpdateRequest helps you to create request object to call `crud.update` for execution by a Connection.

func MakeUpdateRequest

func MakeUpdateRequest(space string) UpdateRequest

MakeUpdateRequest returns a new empty UpdateRequest.

func (UpdateRequest) Body

func (req UpdateRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (UpdateRequest) Context

func (req UpdateRequest) Context(ctx context.Context) UpdateRequest

Context sets a passed context to CRUD request.

func (UpdateRequest) Key

func (req UpdateRequest) Key(key Tuple) UpdateRequest

Key sets the key for the UpdateRequest request. Note: default value is nil.

func (UpdateRequest) Operations

func (req UpdateRequest) Operations(operations []Operation) UpdateRequest

Operations sets the operations for UpdateRequest request. Note: default value is nil.

func (UpdateRequest) Opts

func (req UpdateRequest) Opts(opts UpdateOpts) UpdateRequest

Opts sets the options for the UpdateRequest request. Note: default value is nil.

type UpsertManyOpts

type UpsertManyOpts = OperationManyOpts

UpsertManyOpts describes options for `crud.upsert_many` method.

type UpsertManyRequest

type UpsertManyRequest struct {
	// contains filtered or unexported fields
}

UpsertManyRequest helps you to create request object to call `crud.upsert_many` for execution by a Connection.

func MakeUpsertManyRequest

func MakeUpsertManyRequest(space string) UpsertManyRequest

MakeUpsertManyRequest returns a new empty UpsertManyRequest.

func (UpsertManyRequest) Body

func (req UpsertManyRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (UpsertManyRequest) Context

Context sets a passed context to CRUD request.

func (UpsertManyRequest) Opts

Opts sets the options for the UpsertManyRequest request. Note: default value is nil.

func (UpsertManyRequest) TuplesOperationsData

func (req UpsertManyRequest) TuplesOperationsData(
	tuplesOperationData []TupleOperationsData) UpsertManyRequest

TuplesOperationsData sets tuples and operations for the UpsertManyRequest request. Note: default value is nil.

type UpsertObjectManyOpts

type UpsertObjectManyOpts = OperationManyOpts

UpsertObjectManyOpts describes options for `crud.upsert_object_many` method.

type UpsertObjectManyRequest

type UpsertObjectManyRequest struct {
	// contains filtered or unexported fields
}

UpsertObjectManyRequest helps you to create request object to call `crud.upsert_object_many` for execution by a Connection.

func MakeUpsertObjectManyRequest

func MakeUpsertObjectManyRequest(space string) UpsertObjectManyRequest

MakeUpsertObjectManyRequest returns a new empty UpsertObjectManyRequest.

func (UpsertObjectManyRequest) Body

func (req UpsertObjectManyRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (UpsertObjectManyRequest) Context

Context sets a passed context to CRUD request.

func (UpsertObjectManyRequest) ObjectsOperationsData

func (req UpsertObjectManyRequest) ObjectsOperationsData(
	objectsOperationData []ObjectOperationsData) UpsertObjectManyRequest

ObjectOperationsData sets objects and operations for the UpsertObjectManyRequest request. Note: default value is nil.

func (UpsertObjectManyRequest) Opts

Opts sets the options for the UpsertObjectManyRequest request. Note: default value is nil.

type UpsertObjectOpts

type UpsertObjectOpts = SimpleOperationOpts

UpsertObjectOpts describes options for `crud.upsert_object` method.

type UpsertObjectRequest

type UpsertObjectRequest struct {
	// contains filtered or unexported fields
}

UpsertObjectRequest helps you to create request object to call `crud.upsert_object` for execution by a Connection.

func MakeUpsertObjectRequest

func MakeUpsertObjectRequest(space string) UpsertObjectRequest

MakeUpsertObjectRequest returns a new empty UpsertObjectRequest.

func (UpsertObjectRequest) Body

func (req UpsertObjectRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (UpsertObjectRequest) Context

Context sets a passed context to CRUD request.

func (UpsertObjectRequest) Object

func (req UpsertObjectRequest) Object(object Object) UpsertObjectRequest

Object sets the tuple for the UpsertObjectRequest request. Note: default value is nil.

func (UpsertObjectRequest) Operations

func (req UpsertObjectRequest) Operations(operations []Operation) UpsertObjectRequest

Operations sets the operations for the UpsertObjectRequest request. Note: default value is nil.

func (UpsertObjectRequest) Opts

Opts sets the options for the UpsertObjectRequest request. Note: default value is nil.

type UpsertOpts

type UpsertOpts = SimpleOperationOpts

UpsertOpts describes options for `crud.upsert` method.

type UpsertRequest

type UpsertRequest struct {
	// contains filtered or unexported fields
}

UpsertRequest helps you to create request object to call `crud.upsert` for execution by a Connection.

func MakeUpsertRequest

func MakeUpsertRequest(space string) UpsertRequest

MakeUpsertRequest returns a new empty UpsertRequest.

func (UpsertRequest) Body

func (req UpsertRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error

Body fills an encoder with the call request body.

func (UpsertRequest) Context

func (req UpsertRequest) Context(ctx context.Context) UpsertRequest

Context sets a passed context to CRUD request.

func (UpsertRequest) Operations

func (req UpsertRequest) Operations(operations []Operation) UpsertRequest

Operations sets the operations for the UpsertRequest request. Note: default value is nil.

func (UpsertRequest) Opts

func (req UpsertRequest) Opts(opts UpsertOpts) UpsertRequest

Opts sets the options for the UpsertRequest request. Note: default value is nil.

func (UpsertRequest) Tuple

func (req UpsertRequest) Tuple(tuple Tuple) UpsertRequest

Tuple sets the tuple for the UpsertRequest request. Note: default value is nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL