All Projects → tarantool → go-tarantool

tarantool / go-tarantool

Licence: BSD-2-Clause license
Tarantool 1.10+ client for Go language

Projects that are alternatives of or similar to go-tarantool

tarantool-operator
Tarantool Operator manages Tarantool Cartridge clusters atop Kubernetes
Stars: ✭ 48 (-67.57%)
Mutual labels:  tarantool
tarantool-php
PECL PHP driver for Tarantool
Stars: ✭ 82 (-44.59%)
Mutual labels:  tarantool
Tarantool
Get your data in RAM. Get compute close to data. Enjoy the performance.
Stars: ✭ 2,787 (+1783.11%)
Mutual labels:  tarantool
tarantool rs
Sync/Async tarantool database connector. WORK IN PROGRESS. DON'T SHARE THIS REPO
Stars: ✭ 14 (-90.54%)
Mutual labels:  tarantool
tarantool-module
Tarantool Rust SDK
Stars: ✭ 24 (-83.78%)
Mutual labels:  tarantool
tarantool-admin
No description or website provided.
Stars: ✭ 90 (-39.19%)
Mutual labels:  tarantool
ansible-cartridge
Ansible role for deploying tarantool cartridge-based applications
Stars: ✭ 14 (-90.54%)
Mutual labels:  tarantool
go-tarantool
Tarantool 1.6+ connector for Go language
Stars: ✭ 45 (-69.59%)
Mutual labels:  tarantool
mysql-tarantool-replication
A standalone MySQL -> Tarantool replication daemon
Stars: ✭ 47 (-68.24%)
Mutual labels:  tarantool
tarantool-autovshard
Vshard wrapper with automatic master election, failover and centralized configuration storage in Consul.
Stars: ✭ 20 (-86.49%)
Mutual labels:  tarantool
tarantool.ex
Tarantool client library for Elixir projects
Stars: ✭ 26 (-82.43%)
Mutual labels:  tarantool
mapper
Map tarantool tuples to php objects.
Stars: ✭ 68 (-54.05%)
Mutual labels:  tarantool
docker
Docker images for tarantool database
Stars: ✭ 44 (-70.27%)
Mutual labels:  tarantool

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].