decimal

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: BSD-2-Clause Imports: 6 Imported by: 1

Documentation

Overview

Package decimal with support of Tarantool's decimal data type.

Decimal data type supported in Tarantool since 2.2.

Since: 1.7.0

See also:

* Tarantool MessagePack extensions https://www.tarantool.io/en/doc/latest/dev_guide/internals/msgpack_extensions/#the-decimal-type

* Tarantool data model https://www.tarantool.io/en/doc/latest/book/box/data_model/

* Tarantool issue for support decimal type https://github.com/tarantool/tarantool/issues/692

* Tarantool module decimal https://www.tarantool.io/en/doc/latest/reference/reference_lua/decimal/

Example

To enable support of decimal in msgpack with https://github.com/shopspring/decimal, import tarantool/decimal submodule.

server := "127.0.0.1:3013"
opts := tarantool.Opts{
	Timeout:       5 * time.Second,
	Reconnect:     1 * time.Second,
	MaxReconnects: 3,
	User:          "test",
	Pass:          "test",
}
client, err := tarantool.Connect(server, opts)
if err != nil {
	log.Fatalf("Failed to connect: %s", err.Error())
}

spaceNo := uint32(524)

number, err := NewDecimalFromString("-22.804")
if err != nil {
	log.Fatalf("Failed to prepare test decimal: %s", err)
}

resp, err := client.Replace(spaceNo, []interface{}{number})
if err != nil {
	log.Fatalf("Decimal replace failed: %s", err)
}
if resp == nil {
	log.Fatalf("Response is nil after Replace")
}

log.Println("Decimal tuple replace")
log.Println("Error", err)
log.Println("Code", resp.Code)
log.Println("Data", resp.Data)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decimal

type Decimal struct {
	decimal.Decimal
}

func NewDecimal

func NewDecimal(decimal decimal.Decimal) *Decimal

NewDecimal creates a new Decimal from a decimal.Decimal.

func NewDecimalFromString

func NewDecimalFromString(src string) (result *Decimal, err error)

NewDecimalFromString creates a new Decimal from a string.

func (*Decimal) MarshalMsgpack

func (decNum *Decimal) MarshalMsgpack() ([]byte, error)

MarshalMsgpack serializes the Decimal into a MessagePack representation.

func (*Decimal) UnmarshalMsgpack

func (decNum *Decimal) UnmarshalMsgpack(b []byte) error

UnmarshalMsgpack deserializes a Decimal value from a MessagePack representation.

Jump to

Keyboard shortcuts

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