Skip to content

Commit

Permalink
go-tarantool: update to v2
Browse files Browse the repository at this point in the history
This patch updates go-tarantool version used to v2.

Closes #6
  • Loading branch information
DerekBum committed Oct 8, 2024
1 parent 3e6fbfc commit 707d064
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 96 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed
- bump `go-tarantool` dependency to `v2`.

## [0.1.0] - 2023-09-08

### Changed
Expand Down
18 changes: 9 additions & 9 deletions converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"time"

"github.com/google/uuid"
"github.com/tarantool/go-tarantool/datetime"
"github.com/tarantool/go-tarantool/decimal"
"github.com/tarantool/go-tarantool/v2/datetime"
"github.com/tarantool/go-tarantool/v2/decimal"
)

// Converter is a converter from S to T.
Expand All @@ -33,8 +33,8 @@ var (
_ Converter[string, any] = (*IdentityConverter[string])(nil)
_ Converter[string, any] = (*StringToIntervalConverter)(nil)

_ Converter[*datetime.Datetime, string] = (*DatetimeToStringConverter)(nil)
_ Converter[datetime.Interval, string] = (*IntervalToStringConverter)(nil)
_ Converter[datetime.Datetime, string] = (*DatetimeToStringConverter)(nil)
_ Converter[datetime.Interval, string] = (*IntervalToStringConverter)(nil)
)

// IdentityConverter is a converter from S to any, that doesn't change the input.
Expand Down Expand Up @@ -164,7 +164,7 @@ func MakeStringToDecimalConverter(ignoreChars, decSeparators string) StringToDec
func (conv StringToDecimalConverter) Convert(src string) (any, error) {
src = replaceCharacters(src, conv.ignoreChars, "")
src = replaceCharacters(src, conv.decSeparators, ".")
return decimal.NewDecimalFromString(src)
return decimal.MakeDecimalFromString(src)
}

// StringToUUIDConverter is a converter from string to UUID.
Expand Down Expand Up @@ -206,7 +206,7 @@ func (StringToDatetimeConverter) Convert(src string) (any, error) {
}
_, offset := tm.Zone()
tm = tm.In(time.FixedZone(datetime.NoTimezone, offset))
return datetime.NewDatetime(tm)
return datetime.MakeDatetime(tm)
}
loc, err := time.LoadLocation(tzName)
if err != nil {
Expand All @@ -216,7 +216,7 @@ func (StringToDatetimeConverter) Convert(src string) (any, error) {
if err != nil {
return nil, err
}
return datetime.NewDatetime(tm)
return datetime.MakeDatetime(tm)
}

// StringToMapConverter is a converter from string to map.
Expand Down Expand Up @@ -341,9 +341,9 @@ func MakeDatetimeToStringConverter() DatetimeToStringConverter {
return DatetimeToStringConverter{}
}

// Convert is the implementation of Converter[*datetime.Datetime, string]
// Convert is the implementation of Converter[datetime.Datetime, string]
// for DatetimeToStringConverter.
func (DatetimeToStringConverter) Convert(datetime *datetime.Datetime) (string, error) {
func (DatetimeToStringConverter) Convert(datetime datetime.Datetime) (string, error) {
tm := datetime.ToTime()
zone := tm.Location().String()
if zone != "" {
Expand Down
26 changes: 13 additions & 13 deletions converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
dec "github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tarantool/go-tarantool/datetime"
"github.com/tarantool/go-tarantool/decimal"
"github.com/tarantool/go-tarantool/v2/datetime"
"github.com/tarantool/go-tarantool/v2/decimal"
"github.com/tarantool/go-tupleconv"
)

Expand All @@ -38,8 +38,8 @@ func HelperTestConverter[S any, T any](
}
}

func getDatetimeWithValidate(t *testing.T, tm time.Time) *datetime.Datetime {
dt, err := datetime.NewDatetime(tm)
func getDatetimeWithValidate(t *testing.T, tm time.Time) datetime.Datetime {
dt, err := datetime.MakeDatetime(tm)
require.NoError(t, err)
return dt
}
Expand Down Expand Up @@ -247,35 +247,35 @@ func TestConverters(t *testing.T) {
tupleconv.MakeStringToDecimalConverter(thSeparators, decSeparators): {
{
value: "0",
expected: &decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(0), 0)},
expected: decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(0), 0)},
},
{
value: "1",
expected: &decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(1), 0)},
expected: decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(1), 0)},
},
{
value: "-1",
expected: &decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(-1), 0)},
expected: decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(-1), 0)},
},
{
value: "43904329",
expected: &decimal.Decimal{
expected: decimal.Decimal{
Decimal: dec.NewFromBigInt(big.NewInt(43904329), 0),
},
},
{
value: "-9223372036854775808",
expected: &decimal.Decimal{
expected: decimal.Decimal{
Decimal: dec.NewFromBigInt(big.NewInt(int64(-9223372036854775808)), 0),
},
},
{
value: "1.447e+44",
expected: &decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(1447), 41)},
expected: decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(1447), 41)},
},
{
value: "1*5",
expected: &decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(15), -1)},
expected: decimal.Decimal{Decimal: dec.NewFromBigInt(big.NewInt(15), -1)},
},

// Error.
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestMakeDatetimeToStringConverter(t *testing.T) {
parisLoc)
time3 := time.Date(2020, 9, 14, 12, 12, 12, 0, time.UTC)

cases := []convCase[*datetime.Datetime, string]{
cases := []convCase[datetime.Datetime, string]{
{
value: getDatetimeWithValidate(t, time1),
expected: "2023-08-30T12:06:05.123456789+0400",
Expand All @@ -335,7 +335,7 @@ func TestMakeDatetimeToStringConverter(t *testing.T) {
},
}
converter := tupleconv.MakeDatetimeToStringConverter()
HelperTestConverter[*datetime.Datetime, string](t, converter, cases)
HelperTestConverter[datetime.Datetime, string](t, converter, cases)
}

func TestMakeIntervalToStringConverter(t *testing.T) {
Expand Down
57 changes: 37 additions & 20 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package tupleconv_test

import (
"context"
"errors"
"fmt"
"github.com/tarantool/go-tarantool"
"github.com/tarantool/go-tarantool/datetime"
"github.com/tarantool/go-tarantool/test_helpers"
"github.com/tarantool/go-tupleconv"
"strconv"
"strings"
"time"

_ "github.com/tarantool/go-tarantool/uuid"
"github.com/tarantool/go-tarantool/v2"
"github.com/tarantool/go-tarantool/v2/datetime"
"github.com/tarantool/go-tarantool/v2/test_helpers"
"github.com/tarantool/go-tupleconv"

_ "github.com/tarantool/go-tarantool/v2/uuid"
)

type filterIntConverter struct {
Expand Down Expand Up @@ -179,14 +181,21 @@ func ExampleTTConvFactory_custom() {

const workDir = "work_dir"
const server = "127.0.0.1:3014"

Check failure on line 183 in example_test.go

View workflow job for this annotation

GitHub Actions / tests

File is not `gofmt`-ed (gofmt)
var dialer = tarantool.NetDialer{
Address: server,
User: "test",
Password: "password",
}
var opts = tarantool.Opts{
Timeout: 5 * time.Second,
}

func upTarantool() (func(), error) {
inst, err := test_helpers.StartTarantool(test_helpers.StartOpts{
Dialer: dialer,
InitScript: "testdata/config.lua",
Listen: server,
WorkDir: workDir,
User: "test",
Pass: "password",
WaitStart: 100 * time.Millisecond,
ConnectRetry: 3,
RetryTimeout: 500 * time.Millisecond,
Expand All @@ -207,7 +216,7 @@ func makeTtEncoder() func(any) (string, error) {
return func(src any) (string, error) {
switch src := src.(type) {
case datetime.Datetime:
return datetimeConverter.Convert(&src)
return datetimeConverter.Convert(src)
default:
return fmt.Sprint(src), nil
}
Expand All @@ -225,10 +234,9 @@ func ExampleMap_insertMappedTuples() {
}
defer cleanupTarantool()

conn, _ := tarantool.Connect(server, tarantool.Opts{
User: "test",
Pass: "password",
})
conn, _ := tarantool.Connect(context.Background(), dialer, opts)
defer conn.Close()

var spaceFmtResp [][]tupleconv.SpaceField
req := tarantool.NewCallRequest("get_test_space_fmt")
if err := conn.Do(req).GetTyped(&spaceFmtResp); err != nil {
Expand Down Expand Up @@ -264,22 +272,32 @@ func ExampleMap_insertMappedTuples() {
return
}
insertReq := tarantool.NewInsertRequest("test_space").Tuple(mapped)
resp, err := conn.Do(insertReq).Get()
resp, err := conn.Do(insertReq).GetResponse()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("insert response code =", resp.Code)
data, err := resp.Decode()
if err != nil {
fmt.Printf("Error while decoding: %s", err)
return
}
fmt.Println("insert response code =", data)
}

selectReq := tarantool.NewSelectRequest("test_space")
resp, err := conn.Do(selectReq).Get()
resp, err := conn.Do(selectReq).GetResponse()
if err != nil {
fmt.Println(err)
return
}
data, err := resp.Decode()
if err != nil {
fmt.Println(err)
return
}

tuple0, _ := resp.Data[0].([]any)
tuple0, _ := data[0].([]any)
encoder := tupleconv.MakeMapper[any, string]([]tupleconv.Converter[any, string]{}).
WithDefaultConverter(tupleconv.MakeFuncConverter(makeTtEncoder()))

Expand Down Expand Up @@ -308,10 +326,9 @@ func Example_ttEncoder() {
tupleEncoder := tupleconv.MakeMapper([]tupleconv.Converter[any, string]{}).
WithDefaultConverter(converter)

conn, _ := tarantool.Connect(server, tarantool.Opts{
User: "test",
Pass: "password",
})
conn, _ := tarantool.Connect(context.Background(), dialer, opts)
defer conn.Close()

req := tarantool.NewSelectRequest("finances")

var tuples [][]any
Expand Down
11 changes: 2 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@ require (
github.com/google/uuid v1.3.0
github.com/shopspring/decimal v1.3.1
github.com/stretchr/testify v1.7.1
github.com/tarantool/go-tarantool v1.11.0
github.com/tarantool/go-tarantool/v2 v2.1.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/golang/protobuf v1.3.1 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/tarantool/go-openssl v0.0.8-0.20230307065445-720eeb389195 // indirect
github.com/tarantool/go-iproto v1.0.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/vmihailenco/msgpack.v2 v2.9.2 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
42 changes: 5 additions & 37 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,56 +1,24 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-pointer v0.0.1 h1:n+XhsuGeVO6MEAp7xyEukFINEa+Quek5psIR/ylA6o0=
github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnUbNvJZAlc=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU=
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572/go.mod h1:w0SWMsp6j9O/dk4/ZpIhL+3CkG8ofA2vuv7k+ltqUMc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tarantool/go-openssl v0.0.8-0.20230307065445-720eeb389195 h1:/AN3eUPsTlvF6W+Ng/8ZjnSU6o7L0H4Wb9GMks6RkzU=
github.com/tarantool/go-openssl v0.0.8-0.20230307065445-720eeb389195/go.mod h1:M7H4xYSbzqpW/ZRBMyH0eyqQBsnhAMfsYk5mv0yid7A=
github.com/tarantool/go-tarantool v1.11.0 h1:iLw8kYDQNFA3c3VHhBJJajXKUJPaz0StY/CdrutDn6s=
github.com/tarantool/go-tarantool v1.11.0/go.mod h1:QRiXv0jnxwgxHtr9ZmifSr/eRba76gTUBgp69pDMX1U=
github.com/tarantool/go-iproto v1.0.0 h1:quC4hdFhCuFYaCqOFgUxH2foRkhAy+TlEy7gQLhdVjw=
github.com/tarantool/go-iproto v1.0.0/go.mod h1:LNCtdyZxojUed8SbOiYHoc3v9NvaZTB7p96hUySMlIo=
github.com/tarantool/go-tarantool/v2 v2.1.0 h1:IY33WoS8Kqb+TxNnKbzu/7yVkiCNZGhbG5Gw0/tMfSk=
github.com/tarantool/go-tarantool/v2 v2.1.0/go.mod h1:cpjGW5FHAXIMf0PKZte70pMOeadw1MA/hrDv1LblWk4=
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/vmihailenco/msgpack.v2 v2.9.2 h1:gjPqo9orRVlSAH/065qw3MsFCDpH7fa1KpiizXyllY4=
gopkg.in/vmihailenco/msgpack.v2 v2.9.2/go.mod h1:/3Dn1Npt9+MYyLpYYXjInO/5jvMLamn+AEGwNEOatn8=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 707d064

Please sign in to comment.