Categorygithub.com/tarantool/go-tarantool
modulepackage
1.12.2
Repository: https://github.com/tarantool/go-tarantool.git
Documentation: pkg.go.dev

# README

Go Reference Actions Status Code Coverage Telegram GitHub Discussions Stack Overflow

Client in Go for Tarantool

The package go-tarantool contains everything you need to connect to Tarantool 1.10+.

The advantage of integrating Go with Tarantool, which is an application server plus a DBMS, is that Go programmers can handle databases and perform on-the-fly recompilations of embedded Lua routines, just as in C, with responses that are faster than other packages according to public benchmarks.

Table of contents

Installation

We assume that you have Tarantool version 1.10+ and a modern Linux or BSD operating system.

You need a current version of go, version 1.13 or later (use go version to check the version number). Do not use gccgo-go.

Note: If your go version is older than 1.13 or if go is not installed, download and run the latest tarball from golang.org.

The package go-tarantool is located in tarantool/go-tarantool repository. To download and install, say:

$ go get github.com/tarantool/go-tarantool

This should put the source and binary files in subdirectories of /usr/local/go, so that you can access them by adding github.com/tarantool/go-tarantool to the import {...} section at the start of any Go program.

Build tags

We define multiple build tags.

This allows us to introduce new features without losing backward compatibility.

  1. To disable SSL support and linking with OpenSSL, you can use the tag:
    go_tarantool_ssl_disable
    
  2. To change the default Call behavior from Call16 to Call17, you can use the build tag:
    go_tarantool_call_17
    
    Note: In future releases, Call17 may be used as default Call behavior.
  3. To replace usage of msgpack.v2 with msgpack.v5, you can use the build tag:
    go_tarantool_msgpack_v5
    
    Note: In future releases, msgpack.v5 may be used by default. We recommend to read msgpack.v5 migration notes and try to use msgpack.v5 before the changes.
  4. To run fuzz tests with decimals, you can use the build tag:
    go_tarantool_decimal_fuzzing
    
    Note: It crashes old Tarantool versions and requires Go 1.18+.

Documentation

Read the Tarantool documentation to find descriptions of terms such as "connect", "space", "index", and the requests to create and manipulate database objects or Lua functions.

In general, connector methods can be divided into two main parts:

  • Connect() function and functions related to connecting, and
  • Data manipulation functions and Lua invocations such as Insert() or Call().

The supported requests have parameters and results equivalent to requests in the Tarantool CRUD operations. There are also Typed and Async versions of each data-manipulation function.

API Reference

Learn API documentation and examples at pkg.go.dev.

Walking-through example

We can now have a closer look at the example and make some observations about what it does.

package tarantool

import (
	"fmt"
	"github.com/tarantool/go-tarantool"
)

func main() {
	opts := tarantool.Opts{User: "guest"}
	conn, err := tarantool.Connect("127.0.0.1:3301", opts)
	if err != nil {
		fmt.Println("Connection refused:", err)
	}
	resp, err := conn.Insert(999, []interface{}{99999, "BB"})
	if err != nil {
		fmt.Println("Error", err)
		fmt.Println("Code", resp.Code)
	}
}

Observation 1: The line "github.com/tarantool/go-tarantool" in the import(...) section brings in all Tarantool-related functions and structures.

Observation 2: The line starting with "Opts :=" sets up the options for Connect(). In this example, the structure contains only a single value, the username. The structure may also contain other settings, see more in documentation for the "Opts" structure.

Observation 3: The line containing "tarantool.Connect" is essential for starting a session. There are two parameters:

  • a string with host:port format, and
  • the option structure that was set up earlier.

Observation 4: The err structure will be nil if there is no error, otherwise it will have a description which can be retrieved with err.Error().

Observation 5: The Insert request, like almost all requests, is preceded by "conn." which is the name of the object that was returned by Connect(). There are two parameters:

  • a space number (it could just as easily have been a space name), and
  • a tuple.

msgpack.v5 migration

Most function names and argument types in msgpack.v5 and msgpack.v2 have not changed (in our code, we noticed changes in EncodeInt, EncodeUint and RegisterExt). But there are a lot of changes in a logic of encoding and decoding. On the plus side the migration seems easy, but on the minus side you need to be very careful.

First of all, EncodeInt8, EncodeInt16, EncodeInt32, EncodeInt64 and EncodeUint* analogues at msgpack.v5 encode numbers as is without loss of type. In msgpack.v2 the type of a number is reduced to a value.

Secondly, a base decoding function does not convert numbers to int64 or uint64. It converts numbers to an exact type defined by MessagePack. The change makes manual type conversions much more difficult and can lead to runtime errors with an old code. We do not recommend to use type conversions and give preference to *Typed functions (besides, it's faster).

There are also changes in the logic that can lead to errors in the old code, as example. Although in msgpack.v5 some functions for the logic tuning were added (see UseLooseInterfaceDecoding, UseCompactInts etc), it is still impossible to achieve full compliance of behavior between msgpack.v5 and msgpack.v2. So we don't go this way. We use standard settings if it possible.

Contributing

See the contributing guide for detailed instructions on how to get started with our project.

Alternative connectors

There are two other connectors available from the open source community:

See feature comparison in the documentation.

# Packages

Package with methods to work with a Tarantool cluster considering master discovery.
Package crud with support of API of Tarantool's CRUD module.
Package with support of Tarantool's datetime data type.
Package decimal with support of Tarantool's decimal data type.
Package with methods to work with a Tarantool cluster.
Package with implementation of methods for work with a Tarantool's queue implementations.
Package settings is a collection of requests to set a connection session setting or get current session configuration.
Helpers for managing Tarantool process for testing purposes.
Package with support of Tarantool's UUID data type.

# Functions

Connect creates and configures a new Connection.
NewBeginRequest returns a new BeginRequest.
NewBroadcastRequest returns a new broadcast request for a specified key.
NewCall16Request returns a new empty Call16Request.
NewCall17Request returns a new empty CallRequest.
NewCallRequest return a new empty CallRequest.
NewCommitRequest returns a new CommitRequest.
NewDeleteRequest returns a new empty DeleteRequest.
NewEvalRequest returns a new empty EvalRequest.
NewExecutePreparedRequest returns a new empty preparedExecuteRequest.
NewExecuteRequest returns a new empty ExecuteRequest.
NewFuture creates a new empty Future.
NewIdRequest returns a new IdRequest.
NewInsertRequest returns a new empty InsertRequest.
NewOperations returns a new empty collection of update operations.
NewPingRequest returns a new PingRequest.
NewPreparedFromResponse constructs a Prepared object.
NewPrepareRequest returns a new empty PrepareRequest.
NewReplaceRequest returns a new empty ReplaceRequest.
NewRollbackRequest returns a new RollbackRequest.
NewSelectRequest returns a new empty SelectRequest.
NewUnprepareRequest returns a new empty UnprepareRequest.
NewUpdateRequest returns a new empty UpdateRequest.
NewUpsertRequest returns a new empty UpsertRequest.

# Constants

No description provided by the author
AutoAuth does not force any authentication method.
No description provided by the author
If the BestEffortLevel (serializable) isolation level becomes unreachable, the transaction is marked as «conflicted» and can no longer be committed.
call in 1.6 format */.
call in >= 1.7 format */.
No description provided by the author
ChapSha1Auth forces chap-sha1 authentication method.
Either reconnect attempts exhausted, or explicit Close is called.
No description provided by the author
Connected signals that connection is established or reestablished.
By default, the isolation level of Tarantool is serializable.
No description provided by the author
Disconnected signals that connection is broken.
%s access denied for user '%s'.
Operation is not permitted when there is an active transaction.
Can't modify space '%s': %s.
Argument type in operation '%c' on field %u does not match field type: expected a %s.
Attempt to modify a tuple field which is part of index '%s' in space '%s'.
Incorrect value for option '%s': %s.
Can't reset cluster id: it is already assigned.
Cluster id of the replica %s doesn't match cluster id of the master %s.
Tarantool client error codes.
Tarantool client error codes.
Tarantool client error codes.
Failed to create function '%s': %s.
Failed to create role '%s': %s.
Failed to create space '%s': %s.
Failed to create user '%s': %s.
A multi-statement transaction can not use multiple storage engines.
Can't drop function %u: %s.
Can't drop primary key in space '%s' while secondary keys exist.
Can't drop space '%s': %s.
Failed to drop user '%s': %s.
Invalid key part count in an exact match (expected %u, got %u).
Can not create a new fiber: recursion limit reached.
Tuple field %u type does not match one required by operation: expected %s.
Ambiguous field type in index '%s', key part %u.
%s access denied for user '%s' to function '%s'.
Function '%s' already exists.
Unsupported language '%s' specified for function '%s'.
A limit on the total number of functions has been reached: %u.
Incorrect grant arguments: %s.
Setting password for guest user has no effect.
Invalid identifier '%s' (expected letters, digits or an underscore).
Illegal parameters, %s.
Index '%s' already exists.
Tuple field count %u is less than required by a defined index (expected %u).
Unsupported index type supplied for index '%s' in space '%s'.
Error injection '%s'.
Invalid MsgPack - %s.
Invalid LSN order for server %u: previous LSN = %llu, new lsn = %llu.
Invalid UUID: %s.
Failed to read xlog: %lld.
Invalid xlog name: expected %lld got %lld.
Invalid xlog order: %lld and %lld.
Unknown iterator type '%s'.
Invalid key part count (expected [0..%u], got %u).
Supplied key type of part %u does not match index part type: expected %s.
Can't drop the primary key in a system space, space '%s'.
Failed to dynamically load function '%s': %s.
Local server is not active.
Failed to allocate %u bytes in %s for %s.
Missing mandatory field '%s' in request.
Can't find snapshot.
Can't create or modify index '%s' in space '%s': %s.
More than one tuple found by get().
Operation is not permitted when there is no active transaction.
Connection is not established.
Can't modify data on a replication slave.
Space engine '%s' does not exist.
Field %d was not found in the tuple.
Function '%s' does not exist.
No index #%u is defined in space '%s'.
Procedure '%.*s' is not defined.
Role '%s' is not found.
Space '%s' does not exist.
Trigger is not found.
User '%s' is not found.
No description provided by the author
ErrorExtensionFeature represents support of MP_ERROR objects over MessagePack (supported by connector).
Incorrect password supplied for user '%s'.
User '%s' already has %s access on %s '%s'.
User '%s' does not have %s access on %s '%s'.
???.
%s.
msgpack.encode: can not encode Lua type '%s'.
%s.
Tarantool client error codes.
Tarantool client error codes.
Can't modify data because this server is in read-only mode.
Can't set option '%s' dynamically.
Replica count limit reached: %u.
Reserved66.
Role '%s' already exists.
User '%s' already has role '%s'.
Granting role '%s' to role '%s' would create a loop.
User '%s' does not have role '%s'.
RTree: %s must be an array with %u (point) or %u (rectangle/box) numeric coordinates.
Can't initialize server id with a reserved value %u.
Failed to allocate %u bytes for tuple in the slab allocator: tuple is too large.
%s.
%s access denied for user '%s' to space '%s'.
Space '%s' already exists.
Tuple field count %u does not match space '%s' field count %u.
SPLICE error on field %u: %s.
Timeout exceeded.
Tarantool client error codes.
Transaction has been aborted by conflict.
Tuple format limit reached: %u.
Duplicate key exists in unique index '%s' in space '%s'.
Tuple is too long %u.
Tuple/Key must be MsgPack array.
Tuple doesn't exist in index '%s' in space '%s'.
Tuple reference counter overflow.
Unknown error.
Unknown request type %u.
Unknown RTREE index distance type %s.
Unknown object type '%s'.
Server %s is not registered with the cluster.
Unknown UPDATE operation.
%s does not support %s.
Unsupported role privilege '%s'.
Field %u UPDATE error: %s.
Integer overflow when performing '%c' operation on field %u.
Space %s has a unique secondary index and does not support UPSERT.
User '%s' already exists.
A limit on the total number of users has been reached: %u.
Failed to write to disk.
Wrong index options (field %u): %s.
Wrong index parts (field %u): %s; expected field1 id (number), field1 type (string), ...
Wrong record in _index space: got {%s}, expected {%s}.
Wrong schema version, current: %d, in request: %u.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
all tuples.
No description provided by the author
all bits are not set.
all bits from x are set in key.
at least one x's bit is set.
key == x ASC order.
key >= x.
key > x.
key <= x.
key < x.
tuples in distance ascending order from specified point.
key overlaps x.
key == x DESC order.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Extended error in >= 2.4 format.
Error in pre-2.4 format.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LogLastReconnectFailed is logged when last reconnect attempt failed, connection will be closed after that.
LogReconnectFailed is logged when reconnect attempt failed.
LogUnexpectedResultId is logged when response with unknown id was received.
LogWatchEventReadFailed is logged when failed to read a watch event.
No description provided by the author
No description provided by the author
PaginationFeature represents support of pagination (supported by connector).
PapSha256Auth forces pap-sha256 authentication method.
No description provided by the author
No description provided by the author
No description provided by the author
The ReadCommittedLevel isolation level makes visible all transactions that started commit (stream.Do(NewCommitRequest()) was called).
The ReadConfirmedLevel isolation level makes visible all transactions that finished the commit (stream.Do(NewCommitRequest()) was returned).
ReconnectFailed signals that attempt to reconnect has failed.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Shutdown signals that shutdown callback is processing.
StreamsFeature represents streams support (supported by connector).
No description provided by the author
TransactionsFeature represents interactive transactions support.
No description provided by the author
No description provided by the author
No description provided by the author
WatchersFeature represents support of watchers (supported by connector).
No description provided by the author

# Structs

BeginRequest helps you to create a begin request object for execution by a Stream.
BoxError is a type representing Tarantool `box.error` object: a single MP_ERROR_STACK object with a link to the previous stack error.
BroadcastRequest helps to send broadcast messages.
CallRequest helps you to create a call request object for execution by a Connection.
ClientError is connection error produced by this client, i.e.
No description provided by the author
CommitRequest helps you to create a commit request object for execution by a Stream.
Connection is a handle with a single connection to a Tarantool instance.
ConnEvent is sent throw Notify channel specified in Opts.
No description provided by the author
DeleteRequest helps you to create a delete request object for execution by a Connection.
DialOpts is a way to configure a Dial method to create a new Conn.
Error is wrapper around error returned by Tarantool.
EvalRequest helps you to create an eval request object for execution by a Connection.
ExecutePreparedRequest helps you to create an execute prepared request object for execution by a Connection.
ExecuteRequest helps you to create an execute request object for execution by a Connection.
No description provided by the author
Future is a handle for asynchronous request.
Greeting is a message sent by Tarantool on connect.
IdRequest informs the server about supported protocol version and protocol features.
Index contains information about index.
No description provided by the author
InsertRequest helps you to create an insert request object for execution by a Connection.
IntIntKey is utility type for passing two integer keys to Select*, Update*, Delete* and GetTyped.
IntKey is utility type for passing integer key to Select*, Update*, Delete* and GetTyped.
KeyValueBind is a type for encoding named SQL parameters.
Op - is update operation.
Operations is a collection of update operations.
No description provided by the author
Opts is a way to configure Connection.
PingRequest helps you to create an execute request object for execution by a Connection.
Prepared is a type for handling prepared statements Since 1.7.0.
PrepareRequest helps you to create a prepare request object for execution by a Connection.
ProtocolInfo type aggregates Tarantool protocol version and features info.
ReplaceRequest helps you to create a replace request object for execution by a Connection.
No description provided by the author
RollbackRequest helps you to create a rollback request object for execution by a Stream.
Schema contains information about spaces and indexes.
SelectRequest allows you to create a select request object for execution by a Connection.
Space contains information about Tarantool's space.
No description provided by the author
SslOpts is a way to configure ssl transport.
No description provided by the author
StringKey is utility type for passing string key to Select*, Update*, Delete* and GetTyped.
TtDialer is a default implementation of the Dialer interface which is used by the connector.
UintKey is utility type for passing unsigned integer key to Select*, Update*, Delete* and GetTyped.
UnprepareRequest helps you to create an unprepare request object for execution by a Connection.
UpdateRequest helps you to create an update request object for execution by a Connection.
UpsertRequest helps you to create an upsert request object for execution by a Connection.
WatchEvent is a watch notification event received from a server.

# Interfaces

Conn is a generic stream-oriented network connection to a Tarantool instance.
ConnectedRequest is an interface that provides the info about a Connection the request belongs to.
No description provided by the author
Dialer is the interface that wraps a method to connect to a Tarantool instance.
Logger is logger type expected to be passed in options.
Request is an interface that provides the necessary data to create a request that will be sent to a tarantool instance.
ResponseIterator is an interface for iteration over a set of responses.
SchemaResolver is an interface for resolving schema details.
TimeoutResponseIterator is an interface that extends ResponseIterator and adds the ability to change a timeout for the Next() call.
Watcher is a subscription to broadcast events.

# Type aliases

Auth is used as a parameter to set up an authentication method.
No description provided by the author
No description provided by the author
PreparedID is a type for Prepared Statement ID.
ProtocolVersion type stores a Tarantool protocol feature.
ProtocolVersion type stores Tarantool protocol version.
No description provided by the author
WatchCallback is a callback to invoke when the key value is updated.