diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b7366b46..6fcd90d53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,15 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release. - Use msgpack/v5 instead of msgpack.v2 (#236) - Call/NewCallRequest = Call17/NewCall17Request (#235) +### Deprecated + +- All Connection., Connection.Typed and + Connection.Async methods. Instead you should use requests objects + + Connection.Do() (#241) +- All ConnectionPool., ConnectionPool.Typed and + ConnectionPool.Async methods. Instead you should use requests + objects + ConnectionPool.Do() (#241) + ### Removed - multi subpackage (#240) diff --git a/README.md b/README.md index 8d67db1b2..b3bff4d3d 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,9 @@ func main() { if err != nil { fmt.Println("Connection refused:", err) } - resp, err := conn.Insert(999, []interface{}{99999, "BB"}) + resp, err := conn.Do(tarantool.NewInsertRequest(999). + Tuple([]interface{}{99999, "BB"}), + ).Get() if err != nil { fmt.Println("Error", err) fmt.Println("Code", resp.Code) @@ -138,12 +140,9 @@ starting a session. There are two parameters: **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. +**Observation 5:** The `Insert` request, like almost all requests, is preceded +by the method `Do` of object `conn` which is the object that was returned +by `Connect()`. ### Migration to v2 diff --git a/connector.go b/connector.go index 3aa2f9542..016dbbfb3 100644 --- a/connector.go +++ b/connector.go @@ -5,48 +5,114 @@ import "time" type Connector interface { ConnectedNow() bool Close() error - Ping() (resp *Response, err error) ConfiguredTimeout() time.Duration + NewPrepared(expr string) (*Prepared, error) + NewStream() (*Stream, error) + NewWatcher(key string, callback WatchCallback) (Watcher, error) + Do(req Request) (fut *Future) + // Deprecated: the method will be removed in the next major version, + // use a PingRequest object + Do() instead. + Ping() (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use a SelectRequest object + Do() instead. Select(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use an InsertRequest object + Do() instead. Insert(space interface{}, tuple interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use a ReplicaRequest object + Do() instead. Replace(space interface{}, tuple interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use a DeleteRequest object + Do() instead. Delete(space, index interface{}, key interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use a UpdateRequest object + Do() instead. Update(space, index interface{}, key, ops interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use a UpsertRequest object + Do() instead. Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use a CallRequest object + Do() instead. Call(functionName string, args interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use a Call16Request object + Do() instead. Call16(functionName string, args interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use a Call17Request object + Do() instead. Call17(functionName string, args interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use an EvalRequest object + Do() instead. Eval(expr string, args interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use an ExecuteRequest object + Do() instead. Execute(expr string, args interface{}) (resp *Response, err error) + // Deprecated: the method will be removed in the next major version, + // use a SelectRequest object + Do() instead. GetTyped(space, index interface{}, key interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use a SelectRequest object + Do() instead. SelectTyped(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use an InsertRequest object + Do() instead. InsertTyped(space interface{}, tuple interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use a ReplaceRequest object + Do() instead. ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use a DeleteRequest object + Do() instead. DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use a UpdateRequest object + Do() instead. UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use a CallRequest object + Do() instead. CallTyped(functionName string, args interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use a Call16Request object + Do() instead. Call16Typed(functionName string, args interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use a Call17Request object + Do() instead. Call17Typed(functionName string, args interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use an EvalRequest object + Do() instead. EvalTyped(expr string, args interface{}, result interface{}) (err error) + // Deprecated: the method will be removed in the next major version, + // use an ExecuteRequest object + Do() instead. ExecuteTyped(expr string, args interface{}, result interface{}) (SQLInfo, []ColumnMetaData, error) + // Deprecated: the method will be removed in the next major version, + // use a SelectRequest object + Do() instead. SelectAsync(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use an InsertRequest object + Do() instead. InsertAsync(space interface{}, tuple interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use a ReplaceRequest object + Do() instead. ReplaceAsync(space interface{}, tuple interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use a DeleteRequest object + Do() instead. DeleteAsync(space, index interface{}, key interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use a UpdateRequest object + Do() instead. UpdateAsync(space, index interface{}, key, ops interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use a UpsertRequest object + Do() instead. UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use a CallRequest object + Do() instead. CallAsync(functionName string, args interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use a Call16Request object + Do() instead. Call16Async(functionName string, args interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use a Call17Request object + Do() instead. Call17Async(functionName string, args interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use an EvalRequest object + Do() instead. EvalAsync(expr string, args interface{}) *Future + // Deprecated: the method will be removed in the next major version, + // use an ExecuteRequest object + Do() instead. ExecuteAsync(expr string, args interface{}) *Future - - NewPrepared(expr string) (*Prepared, error) - NewStream() (*Stream, error) - NewWatcher(key string, callback WatchCallback) (Watcher, error) - - Do(req Request) (fut *Future) } diff --git a/crud/tarantool_test.go b/crud/tarantool_test.go index 837fa2787..c9870abc6 100644 --- a/crud/tarantool_test.go +++ b/crud/tarantool_test.go @@ -489,7 +489,9 @@ func TestCrudGenerateData(t *testing.T) { for _, testCase := range testGenerateDataCases { t.Run(testCase.name, func(t *testing.T) { for i := 1010; i < 1020; i++ { - conn.Delete(spaceName, nil, []interface{}{uint(i)}) + req := tarantool.NewDeleteRequest(spaceName). + Key([]interface{}{uint(i)}) + conn.Do(req).Get() } resp, err := conn.Do(testCase.req).Get() @@ -499,7 +501,9 @@ func TestCrudGenerateData(t *testing.T) { testSelectGeneratedData(t, conn, testCase.expectedTuplesCount) for i := 1010; i < 1020; i++ { - conn.Delete(spaceName, nil, []interface{}{uint(i)}) + req := tarantool.NewDeleteRequest(spaceName). + Key([]interface{}{uint(i)}) + conn.Do(req).Get() } }) } @@ -516,7 +520,9 @@ func TestCrudProcessData(t *testing.T) { testCrudRequestCheck(t, testCase.req, resp, err, testCase.expectedRespLen) for i := 1010; i < 1020; i++ { - conn.Delete(spaceName, nil, []interface{}{uint(i)}) + req := tarantool.NewDeleteRequest(spaceName). + Key([]interface{}{uint(i)}) + conn.Do(req).Get() } }) } @@ -648,7 +654,9 @@ func TestBoolResult(t *testing.T) { } for i := 1010; i < 1020; i++ { - conn.Delete(spaceName, nil, []interface{}{uint(i)}) + req := tarantool.NewDeleteRequest(spaceName). + Key([]interface{}{uint(i)}) + conn.Do(req).Get() } } @@ -671,7 +679,9 @@ func TestNumberResult(t *testing.T) { } for i := 1010; i < 1020; i++ { - conn.Delete(spaceName, nil, []interface{}{uint(i)}) + req := tarantool.NewDeleteRequest(spaceName). + Key([]interface{}{uint(i)}) + conn.Do(req).Get() } } @@ -714,7 +724,9 @@ func TestBaseResult(t *testing.T) { } for i := 1010; i < 1020; i++ { - conn.Delete(spaceName, nil, []interface{}{uint(i)}) + req := tarantool.NewDeleteRequest(spaceName). + Key([]interface{}{uint(i)}) + conn.Do(req).Get() } } @@ -757,7 +769,9 @@ func TestManyResult(t *testing.T) { } for i := 1010; i < 1020; i++ { - conn.Delete(spaceName, nil, []interface{}{uint(i)}) + req := tarantool.NewDeleteRequest(spaceName). + Key([]interface{}{uint(i)}) + conn.Do(req).Get() } } diff --git a/datetime/datetime_test.go b/datetime/datetime_test.go index a47126049..e2f707f6f 100644 --- a/datetime/datetime_test.go +++ b/datetime/datetime_test.go @@ -406,8 +406,9 @@ func TestDatetimeTarantoolInterval(t *testing.T) { for _, dtj := range datetimes { t.Run(fmt.Sprintf("%s_to_%s", dti.ToTime(), dtj.ToTime()), func(t *testing.T) { - resp, err := conn.Call17("call_datetime_interval", - []interface{}{dti, dtj}) + req := NewCallRequest("call_datetime_interval"). + Args([]interface{}{dti, dtj}) + resp, err := conn.Do(req).Get() if err != nil { t.Fatalf("Unable to call call_datetime_interval: %s", err) } @@ -541,7 +542,8 @@ func TestCustomTimezone(t *testing.T) { t.Fatalf("Unable to create datetime: %s", err.Error()) } - resp, err := conn.Replace(spaceTuple1, []interface{}{dt, "payload"}) + req := NewReplaceRequest(spaceTuple1).Tuple([]interface{}{dt, "payload"}) + resp, err := conn.Do(req).Get() if err != nil { t.Fatalf("Datetime replace failed %s", err.Error()) } @@ -558,7 +560,8 @@ func TestCustomTimezone(t *testing.T) { t.Fatalf("Expected offset %d instead of %d", customOffset, offset) } - _, err = conn.Delete(spaceTuple1, 0, []interface{}{dt}) + req := NewDeleteRequest(spaceTuple1).Key([]interface{}{dt}) + _, err = conn.Do(req).Get() if err != nil { t.Fatalf("Datetime delete failed: %s", err.Error()) } @@ -577,7 +580,8 @@ func tupleInsertSelectDelete(t *testing.T, conn *Connection, tm time.Time) { } // Insert tuple with datetime. - _, err = conn.Insert(spaceTuple1, []interface{}{dt, "payload"}) + ins := NewInsertRequest(spaceTuple1).Tuple([]interface{}{dt, "payload"}) + _, err = conn.Do(ins).Get() if err != nil { t.Fatalf("Datetime insert failed: %s", err.Error()) } @@ -585,7 +589,13 @@ func tupleInsertSelectDelete(t *testing.T, conn *Connection, tm time.Time) { // Select tuple with datetime. var offset uint32 = 0 var limit uint32 = 1 - resp, err := conn.Select(spaceTuple1, index, offset, limit, IterEq, []interface{}{dt}) + sel := NewSelectRequest(spaceTuple1). + Index(index). + Offset(offset). + Limit(limit). + Iterator(IterEq). + Key([]interface{}{dt}) + resp, err := conn.Do(sel).Get() if err != nil { t.Fatalf("Datetime select failed: %s", err.Error()) } @@ -595,7 +605,8 @@ func tupleInsertSelectDelete(t *testing.T, conn *Connection, tm time.Time) { assertDatetimeIsEqual(t, resp.Data, tm) // Delete tuple with datetime. - resp, err = conn.Delete(spaceTuple1, index, []interface{}{dt}) + del := NewDeleteRequest(spaceTuple1).Index(index).Key([]interface{}{dt}) + resp, err = conn.Do(del).Get() if err != nil { t.Fatalf("Datetime delete failed: %s", err.Error()) } @@ -738,7 +749,8 @@ func TestDatetimeReplace(t *testing.T) { if err != nil { t.Fatalf("Unable to create Datetime from %s: %s", tm, err) } - resp, err := conn.Replace(spaceTuple1, []interface{}{dt, "payload"}) + rep := NewReplaceRequest(spaceTuple1).Tuple([]interface{}{dt, "payload"}) + resp, err := conn.Do(rep).Get() if err != nil { t.Fatalf("Datetime replace failed: %s", err) } @@ -747,7 +759,12 @@ func TestDatetimeReplace(t *testing.T) { } assertDatetimeIsEqual(t, resp.Data, tm) - resp, err = conn.Select(spaceTuple1, index, 0, 1, IterEq, []interface{}{dt}) + sel := NewSelectRequest(spaceTuple1). + Index(index). + Limit(1). + Iterator(IterEq). + Key([]interface{}{dt}) + resp, err = conn.Do(sel).Get() if err != nil { t.Fatalf("Datetime select failed: %s", err) } @@ -757,7 +774,8 @@ func TestDatetimeReplace(t *testing.T) { assertDatetimeIsEqual(t, resp.Data, tm) // Delete tuple with datetime. - _, err = conn.Delete(spaceTuple1, index, []interface{}{dt}) + del := NewDeleteRequest(spaceTuple1).Index(index).Key([]interface{}{dt}) + _, err = conn.Do(del).Get() if err != nil { t.Fatalf("Datetime delete failed: %s", err.Error()) } @@ -907,7 +925,8 @@ func TestCustomEncodeDecodeTuple1(t *testing.T) { {*dt2, "Moscow"}, }, } - resp, err := conn.Replace(spaceTuple2, &tuple) + rep := NewReplaceRequest(spaceTuple2).Tuple(&tuple) + resp, err := conn.Do(rep).Get() if err != nil || resp.Code != 0 { t.Fatalf("Failed to replace: %s", err.Error()) } @@ -921,7 +940,8 @@ func TestCustomEncodeDecodeTuple1(t *testing.T) { } // Delete the tuple. - _, err = conn.Delete(spaceTuple2, index, []interface{}{cid}) + del := NewDeleteRequest(spaceTuple2).Index(index).Key([]interface{}{cid}) + _, err = conn.Do(del).Get() if err != nil { t.Fatalf("Datetime delete failed: %s", err.Error()) } @@ -955,21 +975,22 @@ func TestCustomDecodeFunction(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, server, opts) defer conn.Close() - // Call function 'call_datetime_testdata' returning a table of custom tuples. - var tuples []Tuple2 - err := conn.Call16Typed("call_datetime_testdata", []interface{}{1}, &tuples) + // Call function 'call_datetime_testdata' returning a custom tuples. + var tuple [][]Tuple2 + call := NewCallRequest("call_datetime_testdata").Args([]interface{}{1}) + err := conn.Do(call).GetTyped(&tuple) if err != nil { t.Fatalf("Failed to CallTyped: %s", err.Error()) } - if cid := tuples[0].Cid; cid != 5 { + if cid := tuple[0][0].Cid; cid != 5 { t.Fatalf("Wrong Cid (%d), should be 5", cid) } - if orig := tuples[0].Orig; orig != "Go!" { + if orig := tuple[0][0].Orig; orig != "Go!" { t.Fatalf("Wrong Orig (%s), should be 'Hello, there!'", orig) } - events := tuples[0].Events + events := tuple[0][0].Events if len(events) != 3 { t.Fatalf("Wrong a number of Events (%d), should be 3", len(events)) } @@ -1003,12 +1024,19 @@ func TestCustomEncodeDecodeTuple5(t *testing.T) { if err != nil { t.Fatalf("Unable to create Datetime from %s: %s", tm, err) } - _, err = conn.Insert(spaceTuple1, []interface{}{dt}) + + ins := NewInsertRequest(spaceTuple1).Tuple([]interface{}{dt}) + _, err = conn.Do(ins).Get() if err != nil { t.Fatalf("Datetime insert failed: %s", err.Error()) } - resp, errSel := conn.Select(spaceTuple1, index, 0, 1, IterEq, []interface{}{dt}) + sel := NewSelectRequest(spaceTuple1). + Index(index). + Limit(1). + Iterator(IterEq). + Key([]interface{}{dt}) + resp, errSel := conn.Do(sel).Get() if errSel != nil { t.Errorf("Failed to Select: %s", errSel.Error()) } @@ -1021,7 +1049,8 @@ func TestCustomEncodeDecodeTuple5(t *testing.T) { } // Teardown: delete a value. - _, err = conn.Delete(spaceTuple1, index, []interface{}{dt}) + del := NewDeleteRequest(spaceTuple1).Index(index).Key([]interface{}{dt}) + _, err = conn.Do(del).Get() if err != nil { t.Fatalf("Datetime delete failed: %s", err.Error()) } diff --git a/datetime/example_test.go b/datetime/example_test.go index 1faa5b24d..5fb1e9ba8 100644 --- a/datetime/example_test.go +++ b/datetime/example_test.go @@ -45,7 +45,9 @@ func Example() { index := "primary" // Replace a tuple with datetime. - resp, err := conn.Replace(space, []interface{}{dt}) + resp, err := conn.Do(tarantool.NewReplaceRequest(space). + Tuple([]interface{}{dt}), + ).Get() if err != nil { fmt.Printf("Error in replace is %v", err) return @@ -58,7 +60,13 @@ func Example() { // Select a tuple with datetime. var offset uint32 = 0 var limit uint32 = 1 - resp, err = conn.Select(space, index, offset, limit, tarantool.IterEq, []interface{}{dt}) + resp, err = conn.Do(tarantool.NewSelectRequest(space). + Index(index). + Offset(offset). + Limit(limit). + Iterator(tarantool.IterEq). + Key([]interface{}{dt}), + ).Get() if err != nil { fmt.Printf("Error in select is %v", err) return @@ -69,7 +77,10 @@ func Example() { fmt.Printf("Data: %v\n", respDt.ToTime()) // Delete a tuple with datetime. - resp, err = conn.Delete(space, index, []interface{}{dt}) + resp, err = conn.Do(tarantool.NewDeleteRequest(space). + Index(index). + Key([]interface{}{dt}), + ).Get() if err != nil { fmt.Printf("Error in delete is %v", err) return diff --git a/datetime/interval_test.go b/datetime/interval_test.go index aa43f2bab..ae42e92c7 100644 --- a/datetime/interval_test.go +++ b/datetime/interval_test.go @@ -5,6 +5,7 @@ import ( "reflect" "testing" + "github.com/tarantool/go-tarantool/v2" . "github.com/tarantool/go-tarantool/v2/datetime" "github.com/tarantool/go-tarantool/v2/test_helpers" ) @@ -118,7 +119,9 @@ func TestIntervalTarantoolEncoding(t *testing.T) { } for _, tc := range cases { t.Run(fmt.Sprintf("%v", tc), func(t *testing.T) { - resp, err := conn.Call17("call_interval_testdata", []interface{}{tc}) + req := tarantool.NewCallRequest("call_interval_testdata"). + Args([]interface{}{tc}) + resp, err := conn.Do(req).Get() if err != nil { t.Fatalf("Unexpected error: %s", err.Error()) } diff --git a/decimal/decimal_test.go b/decimal/decimal_test.go index 97b929ca2..e3eb867c2 100644 --- a/decimal/decimal_test.go +++ b/decimal/decimal_test.go @@ -502,7 +502,8 @@ func TestSelect(t *testing.T) { t.Fatalf("Failed to prepare test decimal: %s", err) } - resp, err := conn.Insert(space, []interface{}{NewDecimal(number)}) + ins := NewInsertRequest(space).Tuple([]interface{}{NewDecimal(number)}) + resp, err := conn.Do(ins).Get() if err != nil { t.Fatalf("Decimal insert failed: %s", err) } @@ -513,7 +514,13 @@ func TestSelect(t *testing.T) { var offset uint32 = 0 var limit uint32 = 1 - resp, err = conn.Select(space, index, offset, limit, IterEq, []interface{}{NewDecimal(number)}) + sel := NewSelectRequest(space). + Index(index). + Offset(offset). + Limit(limit). + Iterator(IterEq). + Key([]interface{}{NewDecimal(number)}) + resp, err = conn.Do(sel).Get() if err != nil { t.Fatalf("Decimal select failed: %s", err.Error()) } @@ -522,7 +529,8 @@ func TestSelect(t *testing.T) { } tupleValueIsDecimal(t, resp.Data, number) - resp, err = conn.Delete(space, index, []interface{}{NewDecimal(number)}) + del := NewDeleteRequest(space).Index(index).Key([]interface{}{NewDecimal(number)}) + resp, err = conn.Do(del).Get() if err != nil { t.Fatalf("Decimal delete failed: %s", err) } @@ -535,7 +543,8 @@ func assertInsert(t *testing.T, conn *Connection, numString string) { t.Fatalf("Failed to prepare test decimal: %s", err) } - resp, err := conn.Insert(space, []interface{}{NewDecimal(number)}) + ins := NewInsertRequest(space).Tuple([]interface{}{NewDecimal(number)}) + resp, err := conn.Do(ins).Get() if err != nil { t.Fatalf("Decimal insert failed: %s", err) } @@ -544,7 +553,8 @@ func assertInsert(t *testing.T, conn *Connection, numString string) { } tupleValueIsDecimal(t, resp.Data, number) - resp, err = conn.Delete(space, index, []interface{}{NewDecimal(number)}) + del := NewDeleteRequest(space).Index(index).Key([]interface{}{NewDecimal(number)}) + resp, err = conn.Do(del).Get() if err != nil { t.Fatalf("Decimal delete failed: %s", err) } @@ -576,7 +586,8 @@ func TestReplace(t *testing.T) { t.Fatalf("Failed to prepare test decimal: %s", err) } - respRep, errRep := conn.Replace(space, []interface{}{NewDecimal(number)}) + rep := NewReplaceRequest(space).Tuple([]interface{}{NewDecimal(number)}) + respRep, errRep := conn.Do(rep).Get() if errRep != nil { t.Fatalf("Decimal replace failed: %s", errRep) } @@ -585,7 +596,12 @@ func TestReplace(t *testing.T) { } tupleValueIsDecimal(t, respRep.Data, number) - respSel, errSel := conn.Select(space, index, 0, 1, IterEq, []interface{}{NewDecimal(number)}) + sel := NewSelectRequest(space). + Index(index). + Limit(1). + Iterator(IterEq). + Key([]interface{}{NewDecimal(number)}) + respSel, errSel := conn.Do(sel).Get() if errSel != nil { t.Fatalf("Decimal select failed: %s", errSel) } diff --git a/decimal/example_test.go b/decimal/example_test.go index cfa43c166..c57cc0603 100644 --- a/decimal/example_test.go +++ b/decimal/example_test.go @@ -40,7 +40,9 @@ func Example() { log.Fatalf("Failed to prepare test decimal: %s", err) } - resp, err := client.Replace(spaceNo, []interface{}{number}) + resp, err := client.Do(tarantool.NewReplaceRequest(spaceNo). + Tuple([]interface{}{number}), + ).Get() if err != nil { log.Fatalf("Decimal replace failed: %s", err) } diff --git a/example_custom_unpacking_test.go b/example_custom_unpacking_test.go index 5bac7ae62..1189e16a3 100644 --- a/example_custom_unpacking_test.go +++ b/example_custom_unpacking_test.go @@ -93,7 +93,9 @@ func Example_customUnpacking() { indexNo := uint32(0) tuple := Tuple2{Cid: 777, Orig: "orig", Members: []Member{{"lol", "", 1}, {"wut", "", 3}}} - resp, err := conn.Replace(spaceNo, &tuple) // NOTE: insert a structure itself. + // Insert a structure itself. + initReq := tarantool.NewReplaceRequest(spaceNo).Tuple(&tuple) + resp, err := conn.Do(initReq).Get() if err != nil { log.Fatalf("Failed to insert: %s", err.Error()) return @@ -102,7 +104,12 @@ func Example_customUnpacking() { fmt.Println("Code", resp.Code) var tuples1 []Tuple2 - err = conn.SelectTyped(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{777}, &tuples1) + selectReq := tarantool.NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Iterator(tarantool.IterEq). + Key([]interface{}{777}) + err = conn.Do(selectReq).GetTyped(&tuples1) if err != nil { log.Fatalf("Failed to SelectTyped: %s", err.Error()) return @@ -111,7 +118,7 @@ func Example_customUnpacking() { // Same result in a "magic" way. var tuples2 []Tuple3 - err = conn.SelectTyped(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{777}, &tuples2) + err = conn.Do(selectReq).GetTyped(&tuples2) if err != nil { log.Fatalf("Failed to SelectTyped: %s", err.Error()) return @@ -120,7 +127,8 @@ func Example_customUnpacking() { // Call a function "func_name" returning a table of custom tuples. var tuples3 [][]Tuple3 - err = conn.Call17Typed("func_name", []interface{}{}, &tuples3) + callReq := tarantool.NewCallRequest("func_name") + err = conn.Do(callReq).GetTyped(&tuples3) if err != nil { log.Fatalf("Failed to CallTyped: %s", err.Error()) return diff --git a/example_test.go b/example_test.go index 60106001e..70d499820 100644 --- a/example_test.go +++ b/example_test.go @@ -18,7 +18,7 @@ type Tuple struct { Name string } -func example_connect(opts tarantool.Opts) *tarantool.Connection { +func exampleConnect(opts tarantool.Opts) *tarantool.Connection { conn, err := tarantool.Connect(server, opts) if err != nil { panic("Connection is not established: " + err.Error()) @@ -44,215 +44,341 @@ func ExampleSslOpts() { } } -func ExampleConnection_Select() { - conn := example_connect(opts) - defer conn.Close() - - conn.Replace(spaceNo, []interface{}{uint(1111), "hello", "world"}) - conn.Replace(spaceNo, []interface{}{uint(1112), "hallo", "werld"}) - - resp, err := conn.Select(617, 0, 0, 100, tarantool.IterEq, []interface{}{uint(1111)}) - - if err != nil { - fmt.Printf("error in select is %v", err) - return - } - fmt.Printf("response is %#v\n", resp.Data) - resp, err = conn.Select("test", "primary", 0, 100, tarantool.IterEq, tarantool.IntKey{1111}) - if err != nil { - fmt.Printf("error in select is %v", err) - return - } - fmt.Printf("response is %#v\n", resp.Data) - - // Output: - // response is []interface {}{[]interface {}{0x457, "hello", "world"}} - // response is []interface {}{[]interface {}{0x457, "hello", "world"}} -} - -func ExampleConnection_SelectTyped() { - conn := example_connect(opts) - defer conn.Close() - var res []Tuple - - err := conn.SelectTyped(617, 0, 0, 100, tarantool.IterEq, tarantool.IntKey{1111}, &res) - - if err != nil { - fmt.Printf("error in select is %v", err) - return - } - fmt.Printf("response is %v\n", res) - err = conn.SelectTyped("test", "primary", 0, 100, tarantool.IterEq, tarantool.IntKey{1111}, &res) - if err != nil { - fmt.Printf("error in select is %v", err) - return - } - fmt.Printf("response is %v\n", res) - // Output: - // response is [{{} 1111 hello world}] - // response is [{{} 1111 hello world}] -} - -func ExampleConnection_SelectAsync() { - conn := example_connect(opts) - defer conn.Close() - spaceNo := uint32(617) - - conn.Insert(spaceNo, []interface{}{uint(16), "test", "one"}) - conn.Insert(spaceNo, []interface{}{uint(17), "test", "one"}) - conn.Insert(spaceNo, []interface{}{uint(18), "test", "one"}) - - var futs [3]*tarantool.Future - futs[0] = conn.SelectAsync("test", "primary", 0, 2, tarantool.IterLe, tarantool.UintKey{16}) - futs[1] = conn.SelectAsync("test", "primary", 0, 1, tarantool.IterEq, tarantool.UintKey{17}) - futs[2] = conn.SelectAsync("test", "primary", 0, 1, tarantool.IterEq, tarantool.UintKey{18}) - var t []Tuple - err := futs[0].GetTyped(&t) - fmt.Println("Future", 0, "Error", err) - fmt.Println("Future", 0, "Data", t) - - resp, err := futs[1].Get() - fmt.Println("Future", 1, "Error", err) - fmt.Println("Future", 1, "Data", resp.Data) - - resp, err = futs[2].Get() - fmt.Println("Future", 2, "Error", err) - fmt.Println("Future", 2, "Data", resp.Data) - // Output: - // Future 0 Error - // Future 0 Data [{{} 16 val 16 bla} {{} 15 val 15 bla}] - // Future 1 Error - // Future 1 Data [[17 val 17 bla]] - // Future 2 Error - // Future 2 Data [[18 val 18 bla]] -} - -func ExampleConnection_GetTyped() { - conn := example_connect(opts) - defer conn.Close() - - const space = "test" - const index = "primary" - conn.Replace(space, []interface{}{uint(1111), "hello", "world"}) - - var t Tuple - err := conn.GetTyped(space, index, []interface{}{1111}, &t) - fmt.Println("Error", err) - fmt.Println("Data", t) - // Output: - // Error - // Data {{} 1111 hello world} -} - func ExampleIntKey() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() const space = "test" const index = "primary" - conn.Replace(space, []interface{}{int(1111), "hello", "world"}) + tuple := []interface{}{int(1111), "hello", "world"} + conn.Do(tarantool.NewReplaceRequest(space).Tuple(tuple)).Get() - var t Tuple - err := conn.GetTyped(space, index, tarantool.IntKey{1111}, &t) + var t []Tuple + err := conn.Do(tarantool.NewSelectRequest(space). + Index(index). + Iterator(tarantool.IterEq). + Key(tarantool.IntKey{1111}), + ).GetTyped(&t) fmt.Println("Error", err) fmt.Println("Data", t) // Output: // Error - // Data {{} 1111 hello world} + // Data [{{} 1111 hello world}] } func ExampleUintKey() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() const space = "test" const index = "primary" - conn.Replace(space, []interface{}{uint(1111), "hello", "world"}) + tuple := []interface{}{uint(1111), "hello", "world"} + conn.Do(tarantool.NewReplaceRequest(space).Tuple(tuple)).Get() - var t Tuple - err := conn.GetTyped(space, index, tarantool.UintKey{1111}, &t) + var t []Tuple + err := conn.Do(tarantool.NewSelectRequest(space). + Index(index). + Iterator(tarantool.IterEq). + Key(tarantool.UintKey{1111}), + ).GetTyped(&t) fmt.Println("Error", err) fmt.Println("Data", t) // Output: // Error - // Data {{} 1111 hello world} + // Data [{{} 1111 hello world}] } func ExampleStringKey() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() const space = "teststring" const index = "primary" - conn.Replace(space, []interface{}{"any", []byte{0x01, 0x02}}) + tuple := []interface{}{"any", []byte{0x01, 0x02}} + conn.Do(tarantool.NewReplaceRequest(space).Tuple(tuple)).Get() - t := struct { + t := []struct { Key string Value []byte }{} - err := conn.GetTyped(space, index, tarantool.StringKey{"any"}, &t) + err := conn.Do(tarantool.NewSelectRequest(space). + Index(index). + Iterator(tarantool.IterEq). + Key(tarantool.StringKey{"any"}), + ).GetTyped(&t) fmt.Println("Error", err) fmt.Println("Data", t) // Output: // Error - // Data {any [1 2]} + // Data [{any [1 2]}] } func ExampleIntIntKey() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() const space = "testintint" const index = "primary" - conn.Replace(space, []interface{}{1, 2, "foo"}) + tuple := []interface{}{1, 2, "foo"} + conn.Do(tarantool.NewReplaceRequest(space).Tuple(tuple)).Get() - t := struct { + t := []struct { Key1 int Key2 int Value string }{} - err := conn.GetTyped(space, index, tarantool.IntIntKey{1, 2}, &t) + err := conn.Do(tarantool.NewSelectRequest(space). + Index(index). + Iterator(tarantool.IterEq). + Key(tarantool.IntIntKey{1, 2}), + ).GetTyped(&t) fmt.Println("Error", err) fmt.Println("Data", t) // Output: // Error - // Data {1 2 foo} + // Data [{1 2 foo}] +} + +func ExamplePingRequest() { + conn := exampleConnect(opts) + defer conn.Close() + + // Ping a Tarantool instance to check connection. + resp, err := conn.Do(tarantool.NewPingRequest()).Get() + fmt.Println("Ping Code", resp.Code) + fmt.Println("Ping Data", resp.Data) + fmt.Println("Ping Error", err) + // Output: + // Ping Code 0 + // Ping Data [] + // Ping Error +} + +// To pass contexts to request objects, use the Context() method. +// Pay attention that when using context with request objects, +// the timeout option for Connection will not affect the lifetime +// of the request. For those purposes use context.WithTimeout() as +// the root context. +func ExamplePingRequest_Context() { + conn := exampleConnect(opts) + defer conn.Close() + + timeout := time.Nanosecond + + // This way you may set the a common timeout for requests with a context. + rootCtx, cancelRoot := context.WithTimeout(context.Background(), timeout) + defer cancelRoot() + + // This context will be canceled with the root after commonTimeout. + ctx, cancel := context.WithCancel(rootCtx) + defer cancel() + + req := tarantool.NewPingRequest().Context(ctx) + + // Ping a Tarantool instance to check connection. + resp, err := conn.Do(req).Get() + fmt.Println("Ping Resp", resp) + fmt.Println("Ping Error", err) + // Output: + // Ping Resp + // Ping Error context is done } func ExampleSelectRequest() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() - req := tarantool.NewSelectRequest(617). + for i := 1111; i <= 1112; i++ { + conn.Do(tarantool.NewReplaceRequest(spaceNo). + Tuple([]interface{}{uint(i), "hello", "world"}), + ).Get() + } + + key := []interface{}{uint(1111)} + resp, err := conn.Do(tarantool.NewSelectRequest(617). Limit(100). - Key(tarantool.IntKey{1111}) - resp, err := conn.Do(req).Get() + Iterator(tarantool.IterEq). + Key(key), + ).Get() + if err != nil { - fmt.Printf("error in do select request is %v", err) + fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %#v\n", resp.Data) - req = tarantool.NewSelectRequest("test"). + var res []Tuple + err = conn.Do(tarantool.NewSelectRequest("test"). Index("primary"). Limit(100). - Key(tarantool.IntKey{1111}) - fut := conn.Do(req) - resp, err = fut.Get() + Iterator(tarantool.IterEq). + Key(key), + ).GetTyped(&res) if err != nil { - fmt.Printf("error in do async select request is %v", err) + fmt.Printf("error in select is %v", err) return } - fmt.Printf("response is %#v\n", resp.Data) + fmt.Printf("response is %v\n", res) + // Output: // response is []interface {}{[]interface {}{0x457, "hello", "world"}} - // response is []interface {}{[]interface {}{0x457, "hello", "world"}} + // response is [{{} 1111 hello world}] +} + +func ExampleInsertRequest() { + conn := exampleConnect(opts) + defer conn.Close() + + // Insert a new tuple { 31, 1 }. + resp, err := conn.Do(tarantool.NewInsertRequest(spaceNo). + Tuple([]interface{}{uint(31), "test", "one"}), + ).Get() + fmt.Println("Insert 31") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + // Insert a new tuple { 32, 1 }. + resp, err = conn.Do(tarantool.NewInsertRequest("test"). + Tuple(&Tuple{Id: 32, Msg: "test", Name: "one"}), + ).Get() + fmt.Println("Insert 32") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + + // Delete tuple with primary key { 31 }. + conn.Do(tarantool.NewDeleteRequest("test"). + Index("primary"). + Key([]interface{}{uint(31)}), + ).Get() + // Delete tuple with primary key { 32 }. + conn.Do(tarantool.NewDeleteRequest("test"). + Index(indexNo). + Key([]interface{}{uint(31)}), + ).Get() + // Output: + // Insert 31 + // Error + // Code 0 + // Data [[31 test one]] + // Insert 32 + // Error + // Code 0 + // Data [[32 test one]] +} + +func ExampleDeleteRequest() { + conn := exampleConnect(opts) + defer conn.Close() + + // Insert a new tuple { 35, 1 }. + conn.Do(tarantool.NewInsertRequest(spaceNo). + Tuple([]interface{}{uint(35), "test", "one"}), + ).Get() + // Insert a new tuple { 36, 1 }. + conn.Do(tarantool.NewInsertRequest("test"). + Tuple(&Tuple{Id: 36, Msg: "test", Name: "one"}), + ).Get() + + // Delete tuple with primary key { 35 }. + resp, err := conn.Do(tarantool.NewDeleteRequest(spaceNo). + Index(indexNo). + Key([]interface{}{uint(35)}), + ).Get() + fmt.Println("Delete 35") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + + // Delete tuple with primary key { 36 }. + resp, err = conn.Do(tarantool.NewDeleteRequest("test"). + Index("primary"). + Key([]interface{}{uint(36)}), + ).Get() + fmt.Println("Delete 36") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + // Output: + // Delete 35 + // Error + // Code 0 + // Data [[35 test one]] + // Delete 36 + // Error + // Code 0 + // Data [[36 test one]] +} + +func ExampleReplaceRequest() { + conn := exampleConnect(opts) + defer conn.Close() + + // Insert a new tuple { 13, 1 }. + conn.Do(tarantool.NewInsertRequest(spaceNo). + Tuple([]interface{}{uint(13), "test", "one"}), + ).Get() + + // Replace a tuple with primary key 13. + // Note, Tuple is defined within tests, and has EncdodeMsgpack and + // DecodeMsgpack methods. + resp, err := conn.Do(tarantool.NewReplaceRequest(spaceNo). + Tuple([]interface{}{uint(13), 1}), + ).Get() + fmt.Println("Replace 13") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + resp, err = conn.Do(tarantool.NewReplaceRequest("test"). + Tuple([]interface{}{uint(13), 1}), + ).Get() + fmt.Println("Replace 13") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + resp, err = conn.Do(tarantool.NewReplaceRequest("test"). + Tuple(&Tuple{Id: 13, Msg: "test", Name: "eleven"}), + ).Get() + fmt.Println("Replace 13") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + resp, err = conn.Do(tarantool.NewReplaceRequest("test"). + Tuple(&Tuple{Id: 13, Msg: "test", Name: "twelve"}), + ).Get() + fmt.Println("Replace 13") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + // Output: + // Replace 13 + // Error + // Code 0 + // Data [[13 1]] + // Replace 13 + // Error + // Code 0 + // Data [[13 1]] + // Replace 13 + // Error + // Code 0 + // Data [[13 test eleven]] + // Replace 13 + // Error + // Code 0 + // Data [[13 test twelve]] } func ExampleUpdateRequest() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() + for i := 1111; i <= 1112; i++ { + conn.Do(tarantool.NewReplaceRequest(spaceNo). + Tuple([]interface{}{uint(i), "hello", "world"}), + ).Get() + } + req := tarantool.NewUpdateRequest(617). Key(tarantool.IntKey{1111}). Operations(tarantool.NewOperations().Assign(1, "bye")) @@ -280,7 +406,7 @@ func ExampleUpdateRequest() { } func ExampleUpsertRequest() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() var req tarantool.Request @@ -305,23 +431,189 @@ func ExampleUpsertRequest() { } fmt.Printf("response is %#v\n", resp.Data) - req = tarantool.NewSelectRequest(617). - Limit(100). - Key(tarantool.IntKey{1113}) + req = tarantool.NewSelectRequest(617). + Limit(100). + Key(tarantool.IntKey{1113}) + resp, err = conn.Do(req).Get() + if err != nil { + fmt.Printf("error in do select request is %v", err) + return + } + fmt.Printf("response is %#v\n", resp.Data) + // Output: + // response is []interface {}{} + // response is []interface {}{} + // response is []interface {}{[]interface {}{0x459, "first", "updated"}} +} + +func ExampleCallRequest() { + conn := exampleConnect(opts) + defer conn.Close() + + // Call a function 'simple_concat' with arguments. + resp, err := conn.Do(tarantool.NewCallRequest("simple_concat"). + Args([]interface{}{"1"}), + ).Get() + fmt.Println("Call simple_concat()") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + // Output: + // Call simple_concat() + // Error + // Code 0 + // Data [11] +} + +func ExampleEvalRequest() { + conn := exampleConnect(opts) + defer conn.Close() + + // Run raw Lua code. + resp, err := conn.Do(tarantool.NewEvalRequest("return 1 + 2")).Get() + fmt.Println("Eval 'return 1 + 2'") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + // Output: + // Eval 'return 1 + 2' + // Error + // Code 0 + // Data [3] +} + +// To use SQL to query a tarantool instance, use ExecuteRequest. +// +// Pay attention that with different types of queries (DDL, DQL, DML etc.) +// some fields of the response structure (MetaData and InfoAutoincrementIds +// in SQLInfo) may be nil. +func ExampleExecuteRequest() { + // Tarantool supports SQL since version 2.0.0 + isLess, _ := test_helpers.IsTarantoolVersionLess(2, 0, 0) + if isLess { + return + } + + conn := exampleConnect(opts) + defer conn.Close() + + req := tarantool.NewExecuteRequest( + "CREATE TABLE SQL_TEST (id INTEGER PRIMARY KEY, name STRING)") + resp, err := conn.Do(req).Get() + fmt.Println("Execute") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + fmt.Println("MetaData", resp.MetaData) + fmt.Println("SQL Info", resp.SQLInfo) + + // There are 4 options to pass named parameters to an SQL query: + // 1) The simple map; + sqlBind1 := map[string]interface{}{ + "id": 1, + "name": "test", + } + + // 2) Any type of structure; + sqlBind2 := struct { + Id int + Name string + }{1, "test"} + + // 3) It is possible to use []tarantool.KeyValueBind; + sqlBind3 := []interface{}{ + tarantool.KeyValueBind{Key: "id", Value: 1}, + tarantool.KeyValueBind{Key: "name", Value: "test"}, + } + + // 4) []interface{} slice with tarantool.KeyValueBind items inside; + sqlBind4 := []tarantool.KeyValueBind{ + {"id", 1}, + {"name", "test"}, + } + + // 1) + req = tarantool.NewExecuteRequest( + "CREATE TABLE SQL_TEST (id INTEGER PRIMARY KEY, name STRING)") + req = req.Args(sqlBind1) + resp, err = conn.Do(req).Get() + fmt.Println("Execute") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + fmt.Println("MetaData", resp.MetaData) + fmt.Println("SQL Info", resp.SQLInfo) + + // 2) + req = req.Args(sqlBind2) + resp, err = conn.Do(req).Get() + fmt.Println("Execute") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + fmt.Println("MetaData", resp.MetaData) + fmt.Println("SQL Info", resp.SQLInfo) + + // 3) + req = req.Args(sqlBind3) + resp, err = conn.Do(req).Get() + fmt.Println("Execute") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + fmt.Println("MetaData", resp.MetaData) + fmt.Println("SQL Info", resp.SQLInfo) + + // 4) + req = req.Args(sqlBind4) + resp, err = conn.Do(req).Get() + fmt.Println("Execute") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + fmt.Println("MetaData", resp.MetaData) + fmt.Println("SQL Info", resp.SQLInfo) + + // The way to pass positional arguments to an SQL query. + req = tarantool.NewExecuteRequest( + "SELECT id FROM SQL_TEST WHERE id=? AND name=?"). + Args([]interface{}{2, "test"}) + resp, err = conn.Do(req).Get() + fmt.Println("Execute") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + fmt.Println("MetaData", resp.MetaData) + fmt.Println("SQL Info", resp.SQLInfo) + + // The way to pass SQL expression with using custom packing/unpacking for + // a type. + var res []Tuple + req = tarantool.NewExecuteRequest( + "SELECT id, name, name FROM SQL_TEST WHERE id=?"). + Args([]interface{}{2}) + err = conn.Do(req).GetTyped(&res) + fmt.Println("ExecuteTyped") + fmt.Println("Error", err) + fmt.Println("Data", res) + + // For using different types of parameters (positioned/named), collect all + // items in []interface{}. + // All "named" items must be passed with tarantool.KeyValueBind{}. + req = tarantool.NewExecuteRequest( + "SELECT id FROM SQL_TEST WHERE id=? AND name=?"). + Args([]interface{}{tarantool.KeyValueBind{"id", 1}, "test"}) resp, err = conn.Do(req).Get() - if err != nil { - fmt.Printf("error in do select request is %v", err) - return - } - fmt.Printf("response is %#v\n", resp.Data) - // Output: - // response is []interface {}{} - // response is []interface {}{} - // response is []interface {}{[]interface {}{0x459, "first", "updated"}} + fmt.Println("Execute") + fmt.Println("Error", err) + fmt.Println("Code", resp.Code) + fmt.Println("Data", resp.Data) + fmt.Println("MetaData", resp.MetaData) + fmt.Println("SQL Info", resp.SQLInfo) } func ExampleProtocolVersion() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() clientProtocolInfo := conn.ClientProtocolInfo() @@ -359,7 +651,7 @@ func ExampleCommitRequest() { } txnOpts := getTestTxnOpts() - conn := example_connect(txnOpts) + conn := exampleConnect(txnOpts) defer conn.Close() stream, _ := conn.NewStream() @@ -436,7 +728,7 @@ func ExampleRollbackRequest() { } txnOpts := getTestTxnOpts() - conn := example_connect(txnOpts) + conn := exampleConnect(txnOpts) defer conn.Close() stream, _ := conn.NewStream() @@ -485,316 +777,133 @@ func ExampleRollbackRequest() { // Rollback transaction req = tarantool.NewRollbackRequest() - resp, err = stream.Do(req).Get() - if err != nil { - fmt.Printf("Failed to Rollback: %s", err.Error()) - return - } - fmt.Printf("Rollback transaction: response is %#v\n", resp.Code) - - // Select outside of transaction - resp, err = conn.Do(selectReq).Get() - if err != nil { - fmt.Printf("Failed to Select: %s", err.Error()) - return - } - fmt.Printf("Select after Rollback: response is %#v\n", resp.Data) -} - -func ExampleBeginRequest_TxnIsolation() { - var req tarantool.Request - var resp *tarantool.Response - var err error - - // Tarantool supports streams and interactive transactions since version 2.10.0 - isLess, _ := test_helpers.IsTarantoolVersionLess(2, 10, 0) - if err != nil || isLess { - return - } - - txnOpts := getTestTxnOpts() - conn := example_connect(txnOpts) - defer conn.Close() - - stream, _ := conn.NewStream() - - // Begin transaction - req = tarantool.NewBeginRequest(). - TxnIsolation(tarantool.ReadConfirmedLevel). - Timeout(500 * time.Millisecond) - resp, err = stream.Do(req).Get() - if err != nil { - fmt.Printf("Failed to Begin: %s", err.Error()) - return - } - fmt.Printf("Begin transaction: response is %#v\n", resp.Code) - - // Insert in stream - req = tarantool.NewInsertRequest(spaceName). - Tuple([]interface{}{uint(2001), "rollback_hello", "rollback_world"}) - resp, err = stream.Do(req).Get() - if err != nil { - fmt.Printf("Failed to Insert: %s", err.Error()) - return - } - fmt.Printf("Insert in stream: response is %#v\n", resp.Code) - - // Select not related to the transaction - // while transaction is not committed - // result of select is empty - selectReq := tarantool.NewSelectRequest(spaceNo). - Index(indexNo). - Limit(1). - Iterator(tarantool.IterEq). - Key([]interface{}{uint(2001)}) - resp, err = conn.Do(selectReq).Get() - if err != nil { - fmt.Printf("Failed to Select: %s", err.Error()) - return - } - fmt.Printf("Select out of stream: response is %#v\n", resp.Data) - - // Select in stream - resp, err = stream.Do(selectReq).Get() - if err != nil { - fmt.Printf("Failed to Select: %s", err.Error()) - return - } - fmt.Printf("Select in stream: response is %#v\n", resp.Data) - - // Rollback transaction - req = tarantool.NewRollbackRequest() - resp, err = stream.Do(req).Get() - if err != nil { - fmt.Printf("Failed to Rollback: %s", err.Error()) - return - } - fmt.Printf("Rollback transaction: response is %#v\n", resp.Code) - - // Select outside of transaction - resp, err = conn.Do(selectReq).Get() - if err != nil { - fmt.Printf("Failed to Select: %s", err.Error()) - return - } - fmt.Printf("Select after Rollback: response is %#v\n", resp.Data) -} - -func ExampleFuture_GetIterator() { - conn := example_connect(opts) - defer conn.Close() - - const timeout = 3 * time.Second - // Or any other Connection.*Async() call. - fut := conn.Call17Async("push_func", []interface{}{4}) - - var it tarantool.ResponseIterator - for it = fut.GetIterator().WithTimeout(timeout); it.Next(); { - resp := it.Value() - if resp.Code == tarantool.PushCode { - // It is a push message. - fmt.Printf("push message: %v\n", resp.Data[0]) - } else if resp.Code == tarantool.OkCode { - // It is a regular response. - fmt.Printf("response: %v", resp.Data[0]) - } else { - fmt.Printf("an unexpected response code %d", resp.Code) - } - } - if err := it.Err(); err != nil { - fmt.Printf("error in call of push_func is %v", err) - return - } - // Output: - // push message: 1 - // push message: 2 - // push message: 3 - // push message: 4 - // response: 4 -} - -func ExampleConnection_Ping() { - conn := example_connect(opts) - defer conn.Close() - - // Ping a Tarantool instance to check connection. - resp, err := conn.Ping() - fmt.Println("Ping Code", resp.Code) - fmt.Println("Ping Data", resp.Data) - fmt.Println("Ping Error", err) - // Output: - // Ping Code 0 - // Ping Data [] - // Ping Error -} - -func ExampleConnection_Insert() { - conn := example_connect(opts) - defer conn.Close() - - // Insert a new tuple { 31, 1 }. - resp, err := conn.Insert(spaceNo, []interface{}{uint(31), "test", "one"}) - fmt.Println("Insert 31") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - // Insert a new tuple { 32, 1 }. - resp, err = conn.Insert("test", &Tuple{Id: 32, Msg: "test", Name: "one"}) - fmt.Println("Insert 32") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - - // Delete tuple with primary key { 31 }. - conn.Delete("test", "primary", []interface{}{uint(31)}) - // Delete tuple with primary key { 32 }. - conn.Delete(spaceNo, indexNo, []interface{}{uint(32)}) - // Output: - // Insert 31 - // Error - // Code 0 - // Data [[31 test one]] - // Insert 32 - // Error - // Code 0 - // Data [[32 test one]] - -} - -func ExampleConnection_Delete() { - conn := example_connect(opts) - defer conn.Close() - - // Insert a new tuple { 35, 1 }. - conn.Insert(spaceNo, []interface{}{uint(35), "test", "one"}) - // Insert a new tuple { 36, 1 }. - conn.Insert("test", &Tuple{Id: 36, Msg: "test", Name: "one"}) - - // Delete tuple with primary key { 35 }. - resp, err := conn.Delete(spaceNo, indexNo, []interface{}{uint(35)}) - fmt.Println("Delete 35") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - - // Delete tuple with primary key { 36 }. - resp, err = conn.Delete("test", "primary", []interface{}{uint(36)}) - fmt.Println("Delete 36") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - // Output: - // Delete 35 - // Error - // Code 0 - // Data [[35 test one]] - // Delete 36 - // Error - // Code 0 - // Data [[36 test one]] -} - -func ExampleConnection_Replace() { - conn := example_connect(opts) - defer conn.Close() - - // Insert a new tuple { 13, 1 }. - conn.Insert(spaceNo, []interface{}{uint(13), "test", "one"}) - - // Replace a tuple with primary key 13. - // Note, Tuple is defined within tests, and has EncdodeMsgpack and - // DecodeMsgpack methods. - resp, err := conn.Replace(spaceNo, []interface{}{uint(13), 1}) - fmt.Println("Replace 13") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - resp, err = conn.Replace("test", []interface{}{uint(13), 1}) - fmt.Println("Replace 13") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - resp, err = conn.Replace("test", &Tuple{Id: 13, Msg: "test", Name: "eleven"}) - fmt.Println("Replace 13") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - resp, err = conn.Replace("test", &Tuple{Id: 13, Msg: "test", Name: "twelve"}) - fmt.Println("Replace 13") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - // Output: - // Replace 13 - // Error - // Code 0 - // Data [[13 1]] - // Replace 13 - // Error - // Code 0 - // Data [[13 1]] - // Replace 13 - // Error - // Code 0 - // Data [[13 test eleven]] - // Replace 13 - // Error - // Code 0 - // Data [[13 test twelve]] + resp, err = stream.Do(req).Get() + if err != nil { + fmt.Printf("Failed to Rollback: %s", err.Error()) + return + } + fmt.Printf("Rollback transaction: response is %#v\n", resp.Code) + + // Select outside of transaction + resp, err = conn.Do(selectReq).Get() + if err != nil { + fmt.Printf("Failed to Select: %s", err.Error()) + return + } + fmt.Printf("Select after Rollback: response is %#v\n", resp.Data) } -func ExampleConnection_Update() { - conn := example_connect(opts) +func ExampleBeginRequest_TxnIsolation() { + var req tarantool.Request + var resp *tarantool.Response + var err error + + // Tarantool supports streams and interactive transactions since version 2.10.0 + isLess, _ := test_helpers.IsTarantoolVersionLess(2, 10, 0) + if err != nil || isLess { + return + } + + txnOpts := getTestTxnOpts() + conn := exampleConnect(txnOpts) defer conn.Close() - // Insert a new tuple { 14, 1 }. - conn.Insert(spaceNo, []interface{}{uint(14), "test", "one"}) + stream, _ := conn.NewStream() - // Update tuple with primary key { 14 }. - resp, err := conn.Update(spaceName, indexName, []interface{}{uint(14)}, []interface{}{[]interface{}{"=", 1, "bye"}}) - fmt.Println("Update 14") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - // Output: - // Update 14 - // Error - // Code 0 - // Data [[14 bye bla]] -} + // Begin transaction + req = tarantool.NewBeginRequest(). + TxnIsolation(tarantool.ReadConfirmedLevel). + Timeout(500 * time.Millisecond) + resp, err = stream.Do(req).Get() + if err != nil { + fmt.Printf("Failed to Begin: %s", err.Error()) + return + } + fmt.Printf("Begin transaction: response is %#v\n", resp.Code) -func ExampleConnection_Call() { - conn := example_connect(opts) - defer conn.Close() + // Insert in stream + req = tarantool.NewInsertRequest(spaceName). + Tuple([]interface{}{uint(2001), "rollback_hello", "rollback_world"}) + resp, err = stream.Do(req).Get() + if err != nil { + fmt.Printf("Failed to Insert: %s", err.Error()) + return + } + fmt.Printf("Insert in stream: response is %#v\n", resp.Code) - // Call a function 'simple_concat' with arguments. - resp, err := conn.Call17("simple_concat", []interface{}{"1"}) - fmt.Println("Call simple_concat()") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - // Output: - // Call simple_concat() - // Error - // Code 0 - // Data [11] + // Select not related to the transaction + // while transaction is not committed + // result of select is empty + selectReq := tarantool.NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Iterator(tarantool.IterEq). + Key([]interface{}{uint(2001)}) + resp, err = conn.Do(selectReq).Get() + if err != nil { + fmt.Printf("Failed to Select: %s", err.Error()) + return + } + fmt.Printf("Select out of stream: response is %#v\n", resp.Data) + + // Select in stream + resp, err = stream.Do(selectReq).Get() + if err != nil { + fmt.Printf("Failed to Select: %s", err.Error()) + return + } + fmt.Printf("Select in stream: response is %#v\n", resp.Data) + + // Rollback transaction + req = tarantool.NewRollbackRequest() + resp, err = stream.Do(req).Get() + if err != nil { + fmt.Printf("Failed to Rollback: %s", err.Error()) + return + } + fmt.Printf("Rollback transaction: response is %#v\n", resp.Code) + + // Select outside of transaction + resp, err = conn.Do(selectReq).Get() + if err != nil { + fmt.Printf("Failed to Select: %s", err.Error()) + return + } + fmt.Printf("Select after Rollback: response is %#v\n", resp.Data) } -func ExampleConnection_Eval() { - conn := example_connect(opts) +func ExampleFuture_GetIterator() { + conn := exampleConnect(opts) defer conn.Close() - // Run raw Lua code. - resp, err := conn.Eval("return 1 + 2", []interface{}{}) - fmt.Println("Eval 'return 1 + 2'") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) + const timeout = 3 * time.Second + fut := conn.Do(tarantool.NewCallRequest("push_func"). + Args([]interface{}{4}), + ) + + var it tarantool.ResponseIterator + for it = fut.GetIterator().WithTimeout(timeout); it.Next(); { + resp := it.Value() + if resp.Code == tarantool.PushCode { + // It is a push message. + fmt.Printf("push message: %v\n", resp.Data[0]) + } else if resp.Code == tarantool.OkCode { + // It is a regular response. + fmt.Printf("response: %v", resp.Data[0]) + } else { + fmt.Printf("an unexpected response code %d", resp.Code) + } + } + if err := it.Err(); err != nil { + fmt.Printf("error in call of push_func is %v", err) + return + } // Output: - // Eval 'return 1 + 2' - // Error - // Code 0 - // Data [3] + // push message: 1 + // push message: 2 + // push message: 3 + // push message: 4 + // response: 4 } func ExampleConnect() { @@ -818,7 +927,7 @@ func ExampleConnect() { // Example demonstrates how to retrieve information with space schema. func ExampleSchema() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() schema := conn.Schema @@ -840,7 +949,7 @@ func ExampleSchema() { // Example demonstrates how to retrieve information with space schema. func ExampleSpace() { - conn := example_connect(opts) + conn := exampleConnect(opts) defer conn.Close() // Save Schema to a local variable to avoid races @@ -883,126 +992,6 @@ func ExampleSpace() { // SpaceField 2 name3 unsigned } -// To use SQL to query a tarantool instance, call Execute. -// -// Pay attention that with different types of queries (DDL, DQL, DML etc.) -// some fields of the response structure (MetaData and InfoAutoincrementIds in SQLInfo) may be nil. -func ExampleConnection_Execute() { - // Tarantool supports SQL since version 2.0.0 - isLess, _ := test_helpers.IsTarantoolVersionLess(2, 0, 0) - if isLess { - return - } - server := "127.0.0.1:3013" - opts := tarantool.Opts{ - Timeout: 5 * time.Second, - User: "test", - Pass: "test", - } - client, err := tarantool.Connect(server, opts) - if err != nil { - fmt.Printf("Failed to connect: %s", err.Error()) - } - - resp, err := client.Execute("CREATE TABLE SQL_TEST (id INTEGER PRIMARY KEY, name STRING)", []interface{}{}) - fmt.Println("Execute") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - fmt.Println("MetaData", resp.MetaData) - fmt.Println("SQL Info", resp.SQLInfo) - - // there are 4 options to pass named parameters to an SQL query - // the simple map: - sqlBind1 := map[string]interface{}{ - "id": 1, - "name": "test", - } - - // any type of structure - sqlBind2 := struct { - Id int - Name string - }{1, "test"} - - // it is possible to use []tarantool.KeyValueBind - sqlBind3 := []interface{}{ - tarantool.KeyValueBind{Key: "id", Value: 1}, - tarantool.KeyValueBind{Key: "name", Value: "test"}, - } - - // or []interface{} slice with tarantool.KeyValueBind items inside - sqlBind4 := []tarantool.KeyValueBind{ - {"id", 1}, - {"name", "test"}, - } - - // the next usage - resp, err = client.Execute("SELECT id FROM SQL_TEST WHERE id=:id AND name=:name", sqlBind1) - fmt.Println("Execute") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - fmt.Println("MetaData", resp.MetaData) - fmt.Println("SQL Info", resp.SQLInfo) - - // the same as - resp, err = client.Execute("SELECT id FROM SQL_TEST WHERE id=:id AND name=:name", sqlBind2) - fmt.Println("Execute") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - fmt.Println("MetaData", resp.MetaData) - fmt.Println("SQL Info", resp.SQLInfo) - - // the same as - resp, err = client.Execute("SELECT id FROM SQL_TEST WHERE id=:id AND name=:name", sqlBind3) - fmt.Println("Execute") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - fmt.Println("MetaData", resp.MetaData) - fmt.Println("SQL Info", resp.SQLInfo) - - // the same as - resp, err = client.Execute("SELECT id FROM SQL_TEST WHERE id=:id AND name=:name", sqlBind4) - fmt.Println("Execute") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - fmt.Println("MetaData", resp.MetaData) - fmt.Println("SQL Info", resp.SQLInfo) - - // the way to pass positional arguments to an SQL query - resp, err = client.Execute("SELECT id FROM SQL_TEST WHERE id=? AND name=?", []interface{}{2, "test"}) - fmt.Println("Execute") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - fmt.Println("MetaData", resp.MetaData) - fmt.Println("SQL Info", resp.SQLInfo) - - // the way to pass SQL expression with using custom packing/unpacking for a type - var res []Tuple - sqlInfo, metaData, err := client.ExecuteTyped("SELECT id, name, name FROM SQL_TEST WHERE id=?", []interface{}{2}, &res) - fmt.Println("ExecuteTyped") - fmt.Println("Error", err) - fmt.Println("Data", res) - fmt.Println("MetaData", metaData) - fmt.Println("SQL Info", sqlInfo) - - // for using different types of parameters (positioned/named), collect all items in []interface{} - // all "named" items must be passed with tarantool.KeyValueBind{} - resp, err = client.Execute("SELECT id FROM SQL_TEST WHERE id=:id AND name=?", - []interface{}{tarantool.KeyValueBind{"id", 1}, "test"}) - fmt.Println("Execute") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - fmt.Println("MetaData", resp.MetaData) - fmt.Println("SQL Info", resp.SQLInfo) -} - // To use prepared statements to query a tarantool instance, call NewPrepared. func ExampleConnection_NewPrepared() { // Tarantool supports SQL since version 2.0.0 @@ -1086,40 +1075,10 @@ func ExampleConnection_NewWatcher() { time.Sleep(time.Second) } -// To pass contexts to request objects, use the Context() method. -// Pay attention that when using context with request objects, -// the timeout option for Connection will not affect the lifetime -// of the request. For those purposes use context.WithTimeout() as -// the root context. -func ExamplePingRequest_Context() { - conn := example_connect(opts) - defer conn.Close() - - timeout := time.Nanosecond - - // this way you may set the common timeout for requests with context - rootCtx, cancelRoot := context.WithTimeout(context.Background(), timeout) - defer cancelRoot() - - // this context will be canceled with the root after commonTimeout - ctx, cancel := context.WithCancel(rootCtx) - defer cancel() - - req := tarantool.NewPingRequest().Context(ctx) - - // Ping a Tarantool instance to check connection. - resp, err := conn.Do(req).Get() - fmt.Println("Ping Resp", resp) - fmt.Println("Ping Error", err) - // Output: - // Ping Resp - // Ping Error context is done -} - // ExampleConnection_CloseGraceful_force demonstrates how to force close // a connection with graceful close in progress after a while. func ExampleConnection_CloseGraceful_force() { - conn := example_connect(opts) + conn := exampleConnect(opts) eval := `local fiber = require('fiber') local time = ... diff --git a/pool/connection_pool.go b/pool/connection_pool.go index f2d85f445..581b226fd 100644 --- a/pool/connection_pool.go +++ b/pool/connection_pool.go @@ -363,6 +363,9 @@ func (pool *ConnectionPool) GetPoolInfo() map[string]*ConnectionInfo { } // Ping sends empty request to Tarantool to check connection. +// +// Deprecated: the method will be removed in the next major version, +// use a PingRequest object + Do() instead. func (connPool *ConnectionPool) Ping(userMode Mode) (*tarantool.Response, error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -373,6 +376,9 @@ func (connPool *ConnectionPool) Ping(userMode Mode) (*tarantool.Response, error) } // Select performs select to box space. +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (connPool *ConnectionPool) Select(space, index interface{}, offset, limit uint32, iterator tarantool.Iter, key interface{}, userMode ...Mode) (resp *tarantool.Response, err error) { @@ -386,6 +392,9 @@ func (connPool *ConnectionPool) Select(space, index interface{}, // Insert performs insertion to box space. // Tarantool will reject Insert when tuple with same primary key exists. +// +// Deprecated: the method will be removed in the next major version, +// use an InsertRequest object + Do() instead. func (connPool *ConnectionPool) Insert(space interface{}, tuple interface{}, userMode ...Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -397,6 +406,9 @@ func (connPool *ConnectionPool) Insert(space interface{}, tuple interface{}, use // Replace performs "insert or replace" action to box space. // If tuple with same primary key exists, it will be replaced. +// +// Deprecated: the method will be removed in the next major version, +// use a ReplaceRequest object + Do() instead. func (connPool *ConnectionPool) Replace(space interface{}, tuple interface{}, userMode ...Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -408,6 +420,9 @@ func (connPool *ConnectionPool) Replace(space interface{}, tuple interface{}, us // Delete performs deletion of a tuple by key. // Result will contain array with deleted tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a DeleteRequest object + Do() instead. func (connPool *ConnectionPool) Delete(space, index interface{}, key interface{}, userMode ...Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -419,6 +434,9 @@ func (connPool *ConnectionPool) Delete(space, index interface{}, key interface{} // Update performs update of a tuple by key. // Result will contain array with updated tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a UpdateRequest object + Do() instead. func (connPool *ConnectionPool) Update(space, index interface{}, key, ops interface{}, userMode ...Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -430,6 +448,9 @@ func (connPool *ConnectionPool) Update(space, index interface{}, key, ops interf // Upsert performs "update or insert" action of a tuple by key. // Result will not contain any tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a UpsertRequest object + Do() instead. func (connPool *ConnectionPool) Upsert(space interface{}, tuple, ops interface{}, userMode ...Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -441,6 +462,9 @@ func (connPool *ConnectionPool) Upsert(space interface{}, tuple, ops interface{} // Call calls registered Tarantool function. // It uses request code for Tarantool >= 1.7, result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a CallRequest object + Do() instead. func (connPool *ConnectionPool) Call(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -453,6 +477,9 @@ func (connPool *ConnectionPool) Call(functionName string, args interface{}, user // Call16 calls registered Tarantool function. // It uses request code for Tarantool 1.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. +// +// Deprecated: the method will be removed in the next major version, +// use a Call16Request object + Do() instead. func (connPool *ConnectionPool) Call16(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -464,6 +491,9 @@ func (connPool *ConnectionPool) Call16(functionName string, args interface{}, us // Call17 calls registered Tarantool function. // It uses request code for Tarantool >= 1.7, result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a Call17Request object + Do() instead. func (connPool *ConnectionPool) Call17(functionName string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -474,6 +504,9 @@ func (connPool *ConnectionPool) Call17(functionName string, args interface{}, us } // Eval passes lua expression for evaluation. +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (connPool *ConnectionPool) Eval(expr string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -484,6 +517,9 @@ func (connPool *ConnectionPool) Eval(expr string, args interface{}, userMode Mod } // Execute passes sql expression to Tarantool for execution. +// +// Deprecated: the method will be removed in the next major version, +// use an ExecuteRequest object + Do() instead. func (connPool *ConnectionPool) Execute(expr string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -495,6 +531,9 @@ func (connPool *ConnectionPool) Execute(expr string, args interface{}, userMode // GetTyped performs select (with limit = 1 and offset = 0) // to box space and fills typed result. +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (connPool *ConnectionPool) GetTyped(space, index interface{}, key interface{}, result interface{}, userMode ...Mode) (err error) { conn, err := connPool.getConnByMode(ANY, userMode) if err != nil { @@ -505,6 +544,9 @@ func (connPool *ConnectionPool) GetTyped(space, index interface{}, key interface } // SelectTyped performs select to box space and fills typed result. +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (connPool *ConnectionPool) SelectTyped(space, index interface{}, offset, limit uint32, iterator tarantool.Iter, key interface{}, result interface{}, userMode ...Mode) (err error) { @@ -518,6 +560,9 @@ func (connPool *ConnectionPool) SelectTyped(space, index interface{}, // InsertTyped performs insertion to box space. // Tarantool will reject Insert when tuple with same primary key exists. +// +// Deprecated: the method will be removed in the next major version, +// use an InsertRequest object + Do() instead. func (connPool *ConnectionPool) InsertTyped(space interface{}, tuple interface{}, result interface{}, userMode ...Mode) (err error) { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -529,6 +574,9 @@ func (connPool *ConnectionPool) InsertTyped(space interface{}, tuple interface{} // ReplaceTyped performs "insert or replace" action to box space. // If tuple with same primary key exists, it will be replaced. +// +// Deprecated: the method will be removed in the next major version, +// use a ReplaceRequest object + Do() instead. func (connPool *ConnectionPool) ReplaceTyped(space interface{}, tuple interface{}, result interface{}, userMode ...Mode) (err error) { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -539,6 +587,9 @@ func (connPool *ConnectionPool) ReplaceTyped(space interface{}, tuple interface{ } // DeleteTyped performs deletion of a tuple by key and fills result with deleted tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a DeleteRequest object + Do() instead. func (connPool *ConnectionPool) DeleteTyped(space, index interface{}, key interface{}, result interface{}, userMode ...Mode) (err error) { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -549,6 +600,9 @@ func (connPool *ConnectionPool) DeleteTyped(space, index interface{}, key interf } // UpdateTyped performs update of a tuple by key and fills result with updated tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a UpdateRequest object + Do() instead. func (connPool *ConnectionPool) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}, userMode ...Mode) (err error) { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -560,6 +614,9 @@ func (connPool *ConnectionPool) UpdateTyped(space, index interface{}, key, ops i // CallTyped calls registered function. // It uses request code for Tarantool >= 1.7, result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a CallRequest object + Do() instead. func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, result interface{}, userMode Mode) (err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -572,6 +629,9 @@ func (connPool *ConnectionPool) CallTyped(functionName string, args interface{}, // Call16Typed calls registered function. // It uses request code for Tarantool 1.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. +// +// Deprecated: the method will be removed in the next major version, +// use a Call16Request object + Do() instead. func (connPool *ConnectionPool) Call16Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -583,6 +643,9 @@ func (connPool *ConnectionPool) Call16Typed(functionName string, args interface{ // Call17Typed calls registered function. // It uses request code for Tarantool >= 1.7, result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a Call17Request object + Do() instead. func (connPool *ConnectionPool) Call17Typed(functionName string, args interface{}, result interface{}, userMode Mode) (err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -593,6 +656,9 @@ func (connPool *ConnectionPool) Call17Typed(functionName string, args interface{ } // EvalTyped passes lua expression for evaluation. +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (connPool *ConnectionPool) EvalTyped(expr string, args interface{}, result interface{}, userMode Mode) (err error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -603,6 +669,9 @@ func (connPool *ConnectionPool) EvalTyped(expr string, args interface{}, result } // ExecuteTyped passes sql expression to Tarantool for execution. +// +// Deprecated: the method will be removed in the next major version, +// use an ExecuteRequest object + Do() instead. func (connPool *ConnectionPool) ExecuteTyped(expr string, args interface{}, result interface{}, userMode Mode) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error) { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -613,6 +682,9 @@ func (connPool *ConnectionPool) ExecuteTyped(expr string, args interface{}, resu } // SelectAsync sends select request to Tarantool and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (connPool *ConnectionPool) SelectAsync(space, index interface{}, offset, limit uint32, iterator tarantool.Iter, key interface{}, userMode ...Mode) *tarantool.Future { @@ -626,6 +698,9 @@ func (connPool *ConnectionPool) SelectAsync(space, index interface{}, // InsertAsync sends insert action to Tarantool and returns Future. // Tarantool will reject Insert when tuple with same primary key exists. +// +// Deprecated: the method will be removed in the next major version, +// use an InsertRequest object + Do() instead. func (connPool *ConnectionPool) InsertAsync(space interface{}, tuple interface{}, userMode ...Mode) *tarantool.Future { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -637,6 +712,9 @@ func (connPool *ConnectionPool) InsertAsync(space interface{}, tuple interface{} // ReplaceAsync sends "insert or replace" action to Tarantool and returns Future. // If tuple with same primary key exists, it will be replaced. +// +// Deprecated: the method will be removed in the next major version, +// use a ReplaceRequest object + Do() instead. func (connPool *ConnectionPool) ReplaceAsync(space interface{}, tuple interface{}, userMode ...Mode) *tarantool.Future { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -648,6 +726,9 @@ func (connPool *ConnectionPool) ReplaceAsync(space interface{}, tuple interface{ // DeleteAsync sends deletion action to Tarantool and returns Future. // Future's result will contain array with deleted tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a DeleteRequest object + Do() instead. func (connPool *ConnectionPool) DeleteAsync(space, index interface{}, key interface{}, userMode ...Mode) *tarantool.Future { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -659,6 +740,9 @@ func (connPool *ConnectionPool) DeleteAsync(space, index interface{}, key interf // UpdateAsync sends deletion of a tuple by key and returns Future. // Future's result will contain array with updated tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a UpdateRequest object + Do() instead. func (connPool *ConnectionPool) UpdateAsync(space, index interface{}, key, ops interface{}, userMode ...Mode) *tarantool.Future { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -670,6 +754,9 @@ func (connPool *ConnectionPool) UpdateAsync(space, index interface{}, key, ops i // UpsertAsync sends "update or insert" action to Tarantool and returns Future. // Future's sesult will not contain any tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a UpsertRequest object + Do() instead. func (connPool *ConnectionPool) UpsertAsync(space interface{}, tuple interface{}, ops interface{}, userMode ...Mode) *tarantool.Future { conn, err := connPool.getConnByMode(RW, userMode) if err != nil { @@ -681,6 +768,9 @@ func (connPool *ConnectionPool) UpsertAsync(space interface{}, tuple interface{} // CallAsync sends a call to registered Tarantool function and returns Future. // It uses request code for Tarantool >= 1.7, future's result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a CallRequest object + Do() instead. func (connPool *ConnectionPool) CallAsync(functionName string, args interface{}, userMode Mode) *tarantool.Future { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -693,6 +783,9 @@ func (connPool *ConnectionPool) CallAsync(functionName string, args interface{}, // Call16Async sends a call to registered Tarantool function and returns Future. // It uses request code for Tarantool 1.6, so future's result is an array of arrays. // Deprecated since Tarantool 1.7.2. +// +// Deprecated: the method will be removed in the next major version, +// use a Call16Request object + Do() instead. func (connPool *ConnectionPool) Call16Async(functionName string, args interface{}, userMode Mode) *tarantool.Future { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -704,6 +797,9 @@ func (connPool *ConnectionPool) Call16Async(functionName string, args interface{ // Call17Async sends a call to registered Tarantool function and returns Future. // It uses request code for Tarantool >= 1.7, future's result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a Call17Request object + Do() instead. func (connPool *ConnectionPool) Call17Async(functionName string, args interface{}, userMode Mode) *tarantool.Future { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -714,6 +810,9 @@ func (connPool *ConnectionPool) Call17Async(functionName string, args interface{ } // EvalAsync sends a lua expression for evaluation and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (connPool *ConnectionPool) EvalAsync(expr string, args interface{}, userMode Mode) *tarantool.Future { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -725,6 +824,9 @@ func (connPool *ConnectionPool) EvalAsync(expr string, args interface{}, userMod // ExecuteAsync sends sql expression to Tarantool for execution and returns // Future. +// +// Deprecated: the method will be removed in the next major version, +// use an ExecuteRequest object + Do() instead. func (connPool *ConnectionPool) ExecuteAsync(expr string, args interface{}, userMode Mode) *tarantool.Future { conn, err := connPool.getNextConnection(userMode) if err != nil { @@ -842,7 +944,7 @@ func (connPool *ConnectionPool) Do(req tarantool.Request, userMode Mode) *tarant // func (connPool *ConnectionPool) getConnectionRole(conn *tarantool.Connection) (Role, error) { - resp, err := conn.Call17("box.info", []interface{}{}) + resp, err := conn.Do(tarantool.NewCallRequest("box.info")).Get() if err != nil { return UnknownRole, err } diff --git a/pool/connection_pool_test.go b/pool/connection_pool_test.go index eda8560e8..912721cd4 100644 --- a/pool/connection_pool_test.go +++ b/pool/connection_pool_test.go @@ -23,7 +23,6 @@ import ( var spaceNo = uint32(520) var spaceName = "testPool" var indexNo = uint32(0) -var indexName = "pk" var ports = []string{"3013", "3014", "3015", "3016", "3017"} var host = "127.0.0.1" @@ -1647,7 +1646,12 @@ func TestInsert(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, servers[2], connOpts) defer conn.Close() - resp, err = conn.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{"rw_insert_key"}) + sel := tarantool.NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Iterator(tarantool.IterEq). + Key([]interface{}{"rw_insert_key"}) + resp, err = conn.Do(sel).Get() require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1682,7 +1686,12 @@ func TestInsert(t *testing.T) { require.Truef(t, ok, "unexpected body of Insert (1)") require.Equalf(t, "preferRW_insert_value", value, "unexpected body of Insert (1)") - resp, err = conn.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{"preferRW_insert_key"}) + sel = tarantool.NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Iterator(tarantool.IterEq). + Key([]interface{}{"preferRW_insert_key"}) + resp, err = conn.Do(sel).Get() require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1717,7 +1726,8 @@ func TestDelete(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, servers[2], connOpts) defer conn.Close() - resp, err := conn.Insert(spaceNo, []interface{}{"delete_key", "delete_value"}) + ins := tarantool.NewInsertRequest(spaceNo).Tuple([]interface{}{"delete_key", "delete_value"}) + resp, err := conn.Do(ins).Get() require.Nilf(t, err, "failed to Insert") require.NotNilf(t, resp, "response is nil after Insert") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Insert") @@ -1752,7 +1762,12 @@ func TestDelete(t *testing.T) { require.Truef(t, ok, "unexpected body of Delete (1)") require.Equalf(t, "delete_value", value, "unexpected body of Delete (1)") - resp, err = conn.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{"delete_key"}) + sel := tarantool.NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Iterator(tarantool.IterEq). + Key([]interface{}{"delete_key"}) + resp, err = conn.Do(sel).Get() require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, 0, len(resp.Data), "response Body len != 0 after Select") @@ -1780,7 +1795,12 @@ func TestUpsert(t *testing.T) { require.Nilf(t, err, "failed to Upsert") require.NotNilf(t, resp, "response is nil after Upsert") - resp, err = conn.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{"upsert_key"}) + sel := tarantool.NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Iterator(tarantool.IterEq). + Key([]interface{}{"upsert_key"}) + resp, err = conn.Do(sel).Get() require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1805,7 +1825,7 @@ func TestUpsert(t *testing.T) { require.Nilf(t, err, "failed to Upsert") require.NotNilf(t, resp, "response is nil after Upsert") - resp, err = conn.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{"upsert_key"}) + resp, err = conn.Do(sel).Get() require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1840,7 +1860,9 @@ func TestUpdate(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, servers[2], connOpts) defer conn.Close() - resp, err := conn.Insert(spaceNo, []interface{}{"update_key", "update_value"}) + ins := tarantool.NewInsertRequest(spaceNo). + Tuple([]interface{}{"update_key", "update_value"}) + resp, err := conn.Do(ins).Get() require.Nilf(t, err, "failed to Insert") require.NotNilf(t, resp, "response is nil after Insert") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Insert") @@ -1862,7 +1884,12 @@ func TestUpdate(t *testing.T) { require.Nilf(t, err, "failed to Update") require.NotNilf(t, resp, "response is nil after Update") - resp, err = conn.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{"update_key"}) + sel := tarantool.NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Iterator(tarantool.IterEq). + Key([]interface{}{"update_key"}) + resp, err = conn.Do(sel).Get() require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1887,7 +1914,7 @@ func TestUpdate(t *testing.T) { require.Nilf(t, err, "failed to Update") require.NotNilf(t, resp, "response is nil after Update") - resp, err = conn.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{"update_key"}) + resp, err = conn.Do(sel).Get() require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1922,7 +1949,9 @@ func TestReplace(t *testing.T) { conn := test_helpers.ConnectWithValidation(t, servers[2], connOpts) defer conn.Close() - resp, err := conn.Insert(spaceNo, []interface{}{"replace_key", "replace_value"}) + ins := tarantool.NewInsertRequest(spaceNo). + Tuple([]interface{}{"replace_key", "replace_value"}) + resp, err := conn.Do(ins).Get() require.Nilf(t, err, "failed to Insert") require.NotNilf(t, resp, "response is nil after Insert") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Insert") @@ -1944,7 +1973,12 @@ func TestReplace(t *testing.T) { require.Nilf(t, err, "failed to Replace") require.NotNilf(t, resp, "response is nil after Replace") - resp, err = conn.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{"new_key"}) + sel := tarantool.NewSelectRequest(spaceNo). + Index(indexNo). + Limit(1). + Iterator(tarantool.IterEq). + Key([]interface{}{"new_key"}) + resp, err = conn.Do(sel).Get() require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") @@ -1966,7 +2000,7 @@ func TestReplace(t *testing.T) { require.Nilf(t, err, "failed to Replace") require.NotNilf(t, resp, "response is nil after Replace") - resp, err = conn.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{"new_key"}) + resp, err = conn.Do(sel).Get() require.Nilf(t, err, "failed to Select") require.NotNilf(t, resp, "response is nil after Select") require.Equalf(t, len(resp.Data), 1, "response Body len != 1 after Select") diff --git a/pool/connector.go b/pool/connector.go index 852f47cee..acb9a9187 100644 --- a/pool/connector.go +++ b/pool/connector.go @@ -47,11 +47,6 @@ func (c *ConnectorAdapter) Close() error { return err } -// Ping sends empty request to Tarantool to check connection. -func (c *ConnectorAdapter) Ping() (*tarantool.Response, error) { - return c.pool.Ping(c.mode) -} - // ConfiguredTimeout returns a timeout from connections config. func (c *ConnectorAdapter) ConfiguredTimeout() time.Duration { ret, err := c.pool.ConfiguredTimeout(c.mode) @@ -61,7 +56,18 @@ func (c *ConnectorAdapter) ConfiguredTimeout() time.Duration { return ret } +// Ping sends empty request to Tarantool to check connection. +// +// Deprecated: the method will be removed in the next major version, +// use a PingRequest object + Do() instead. +func (c *ConnectorAdapter) Ping() (*tarantool.Response, error) { + return c.pool.Ping(c.mode) +} + // Select performs select to box space. +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (c *ConnectorAdapter) Select(space, index interface{}, offset, limit uint32, iterator tarantool.Iter, key interface{}) (*tarantool.Response, error) { @@ -69,30 +75,45 @@ func (c *ConnectorAdapter) Select(space, index interface{}, } // Insert performs insertion to box space. +// +// Deprecated: the method will be removed in the next major version, +// use an InsertRequest object + Do() instead. func (c *ConnectorAdapter) Insert(space interface{}, tuple interface{}) (*tarantool.Response, error) { return c.pool.Insert(space, tuple, c.mode) } // Replace performs "insert or replace" action to box space. +// +// Deprecated: the method will be removed in the next major version, +// use a ReplaceRequest object + Do() instead. func (c *ConnectorAdapter) Replace(space interface{}, tuple interface{}) (*tarantool.Response, error) { return c.pool.Replace(space, tuple, c.mode) } // Delete performs deletion of a tuple by key. +// +// Deprecated: the method will be removed in the next major version, +// use a DeleteRequest object + Do() instead. func (c *ConnectorAdapter) Delete(space, index interface{}, key interface{}) (*tarantool.Response, error) { return c.pool.Delete(space, index, key, c.mode) } // Update performs update of a tuple by key. +// +// Deprecated: the method will be removed in the next major version, +// use a UpdateRequest object + Do() instead. func (c *ConnectorAdapter) Update(space, index interface{}, key, ops interface{}) (*tarantool.Response, error) { return c.pool.Update(space, index, key, ops, c.mode) } // Upsert performs "update or insert" action of a tuple by key. +// +// Deprecated: the method will be removed in the next major version, +// use a UpsertRequest object + Do() instead. func (c *ConnectorAdapter) Upsert(space interface{}, tuple, ops interface{}) (*tarantool.Response, error) { return c.pool.Upsert(space, tuple, ops, c.mode) @@ -100,6 +121,9 @@ func (c *ConnectorAdapter) Upsert(space interface{}, // Call calls registered Tarantool function. // It uses request code for Tarantool >= 1.7, result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a CallRequest object + Do() instead. func (c *ConnectorAdapter) Call(functionName string, args interface{}) (*tarantool.Response, error) { return c.pool.Call(functionName, args, c.mode) @@ -108,6 +132,9 @@ func (c *ConnectorAdapter) Call(functionName string, // Call16 calls registered Tarantool function. // It uses request code for Tarantool 1.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. +// +// Deprecated: the method will be removed in the next major version, +// use a Call16Request object + Do() instead. func (c *ConnectorAdapter) Call16(functionName string, args interface{}) (*tarantool.Response, error) { return c.pool.Call16(functionName, args, c.mode) @@ -115,18 +142,27 @@ func (c *ConnectorAdapter) Call16(functionName string, // Call17 calls registered Tarantool function. // It uses request code for Tarantool >= 1.7, result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a Call17Request object + Do() instead. func (c *ConnectorAdapter) Call17(functionName string, args interface{}) (*tarantool.Response, error) { return c.pool.Call17(functionName, args, c.mode) } // Eval passes Lua expression for evaluation. +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (c *ConnectorAdapter) Eval(expr string, args interface{}) (*tarantool.Response, error) { return c.pool.Eval(expr, args, c.mode) } // Execute passes sql expression to Tarantool for execution. +// +// Deprecated: the method will be removed in the next major version, +// use an ExecuteRequest object + Do() instead. func (c *ConnectorAdapter) Execute(expr string, args interface{}) (*tarantool.Response, error) { return c.pool.Execute(expr, args, c.mode) @@ -134,12 +170,18 @@ func (c *ConnectorAdapter) Execute(expr string, // GetTyped performs select (with limit = 1 and offset = 0) // to box space and fills typed result. +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (c *ConnectorAdapter) GetTyped(space, index interface{}, key interface{}, result interface{}) error { return c.pool.GetTyped(space, index, key, result, c.mode) } // SelectTyped performs select to box space and fills typed result. +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (c *ConnectorAdapter) SelectTyped(space, index interface{}, offset, limit uint32, iterator tarantool.Iter, key interface{}, result interface{}) error { @@ -147,24 +189,36 @@ func (c *ConnectorAdapter) SelectTyped(space, index interface{}, } // InsertTyped performs insertion to box space. +// +// Deprecated: the method will be removed in the next major version, +// use an InsertRequest object + Do() instead. func (c *ConnectorAdapter) InsertTyped(space interface{}, tuple interface{}, result interface{}) error { return c.pool.InsertTyped(space, tuple, result, c.mode) } // ReplaceTyped performs "insert or replace" action to box space. +// +// Deprecated: the method will be removed in the next major version, +// use a ReplaceRequest object + Do() instead. func (c *ConnectorAdapter) ReplaceTyped(space interface{}, tuple interface{}, result interface{}) error { return c.pool.ReplaceTyped(space, tuple, result, c.mode) } // DeleteTyped performs deletion of a tuple by key and fills result with deleted tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a DeleteRequest object + Do() instead. func (c *ConnectorAdapter) DeleteTyped(space, index interface{}, key interface{}, result interface{}) error { return c.pool.DeleteTyped(space, index, key, result, c.mode) } // UpdateTyped performs update of a tuple by key and fills result with updated tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a UpdateRequest object + Do() instead. func (c *ConnectorAdapter) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) error { return c.pool.UpdateTyped(space, index, key, ops, result, c.mode) @@ -172,6 +226,9 @@ func (c *ConnectorAdapter) UpdateTyped(space, index interface{}, // CallTyped calls registered function. // It uses request code for Tarantool >= 1.7, result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a CallRequest object + Do() instead. func (c *ConnectorAdapter) CallTyped(functionName string, args interface{}, result interface{}) error { return c.pool.CallTyped(functionName, args, result, c.mode) @@ -180,6 +237,9 @@ func (c *ConnectorAdapter) CallTyped(functionName string, // Call16Typed calls registered function. // It uses request code for Tarantool 1.6, result is an array of arrays. // Deprecated since Tarantool 1.7.2. +// +// Deprecated: the method will be removed in the next major version, +// use a Call16Request object + Do() instead. func (c *ConnectorAdapter) Call16Typed(functionName string, args interface{}, result interface{}) error { return c.pool.Call16Typed(functionName, args, result, c.mode) @@ -187,54 +247,81 @@ func (c *ConnectorAdapter) Call16Typed(functionName string, // Call17Typed calls registered function. // It uses request code for Tarantool >= 1.7, result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a Call17Request object + Do() instead. func (c *ConnectorAdapter) Call17Typed(functionName string, args interface{}, result interface{}) error { return c.pool.Call17Typed(functionName, args, result, c.mode) } // EvalTyped passes Lua expression for evaluation. +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (c *ConnectorAdapter) EvalTyped(expr string, args interface{}, result interface{}) error { return c.pool.EvalTyped(expr, args, result, c.mode) } // ExecuteTyped passes sql expression to Tarantool for execution. +// +// Deprecated: the method will be removed in the next major version, +// use an ExecuteRequest object + Do() instead. func (c *ConnectorAdapter) ExecuteTyped(expr string, args interface{}, result interface{}) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error) { return c.pool.ExecuteTyped(expr, args, result, c.mode) } // SelectAsync sends select request to Tarantool and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (c *ConnectorAdapter) SelectAsync(space, index interface{}, offset, limit uint32, iterator tarantool.Iter, key interface{}) *tarantool.Future { return c.pool.SelectAsync(space, index, offset, limit, iterator, key, c.mode) } // InsertAsync sends insert action to Tarantool and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use an InsertRequest object + Do() instead. func (c *ConnectorAdapter) InsertAsync(space interface{}, tuple interface{}) *tarantool.Future { return c.pool.InsertAsync(space, tuple, c.mode) } // ReplaceAsync sends "insert or replace" action to Tarantool and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use a ReplaceRequest object + Do() instead. func (c *ConnectorAdapter) ReplaceAsync(space interface{}, tuple interface{}) *tarantool.Future { return c.pool.ReplaceAsync(space, tuple, c.mode) } // DeleteAsync sends deletion action to Tarantool and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use a DeleteRequest object + Do() instead. func (c *ConnectorAdapter) DeleteAsync(space, index interface{}, key interface{}) *tarantool.Future { return c.pool.DeleteAsync(space, index, key, c.mode) } // Update sends deletion of a tuple by key and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use a UpdateRequest object + Do() instead. func (c *ConnectorAdapter) UpdateAsync(space, index interface{}, key, ops interface{}) *tarantool.Future { return c.pool.UpdateAsync(space, index, key, ops, c.mode) } // UpsertAsync sends "update or insert" action to Tarantool and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use a UpsertRequest object + Do() instead. func (c *ConnectorAdapter) UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *tarantool.Future { return c.pool.UpsertAsync(space, tuple, ops, c.mode) @@ -242,6 +329,9 @@ func (c *ConnectorAdapter) UpsertAsync(space interface{}, tuple interface{}, // CallAsync sends a call to registered Tarantool function and returns Future. // It uses request code for Tarantool >= 1.7, future's result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a CallRequest object + Do() instead. func (c *ConnectorAdapter) CallAsync(functionName string, args interface{}) *tarantool.Future { return c.pool.CallAsync(functionName, args, c.mode) @@ -250,6 +340,9 @@ func (c *ConnectorAdapter) CallAsync(functionName string, // Call16Async sends a call to registered Tarantool function and returns Future. // It uses request code for Tarantool 1.6, so future's result is an array of arrays. // Deprecated since Tarantool 1.7.2. +// +// Deprecated: the method will be removed in the next major version, +// use a Call16Request object + Do() instead. func (c *ConnectorAdapter) Call16Async(functionName string, args interface{}) *tarantool.Future { return c.pool.Call16Async(functionName, args, c.mode) @@ -257,18 +350,27 @@ func (c *ConnectorAdapter) Call16Async(functionName string, // Call17Async sends a call to registered Tarantool function and returns Future. // It uses request code for Tarantool >= 1.7, future's result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a Call17Request object + Do() instead. func (c *ConnectorAdapter) Call17Async(functionName string, args interface{}) *tarantool.Future { return c.pool.Call17Async(functionName, args, c.mode) } // EvalAsync sends a Lua expression for evaluation and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (c *ConnectorAdapter) EvalAsync(expr string, args interface{}) *tarantool.Future { return c.pool.EvalAsync(expr, args, c.mode) } // ExecuteAsync sends a sql expression for execution and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (c *ConnectorAdapter) ExecuteAsync(expr string, args interface{}) *tarantool.Future { return c.pool.ExecuteAsync(expr, args, c.mode) diff --git a/pool/example_test.go b/pool/example_test.go index f917668a6..84a41ff7b 100644 --- a/pool/example_test.go +++ b/pool/example_test.go @@ -32,521 +32,31 @@ func examplePool(roles []bool, connOpts tarantool.Opts) (*pool.ConnectionPool, e return connPool, nil } -func ExampleConnectionPool_Select() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) - } - defer connPool.Close() - - // Connect to servers[2] to check if tuple - // was inserted on RW instance - conn, err := tarantool.Connect(servers[2], connOpts) - if err != nil || conn == nil { - fmt.Printf("failed to connect to %s", servers[2]) - return - } - - // Insert a new tuple {"key1", "value1"}. - _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - // Insert a new tuple {"key2", "value2"}. - _, err = conn.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - - resp, err := connPool.Select( - spaceNo, indexNo, 0, 100, tarantool.IterEq, - []interface{}{"key1"}, pool.PreferRW) - if err != nil { - fmt.Printf("error in select is %v", err) - return - } - fmt.Printf("response is %#v\n", resp.Data) - resp, err = connPool.Select( - spaceNo, indexNo, 0, 100, tarantool.IterEq, - []interface{}{"key2"}, pool.PreferRW) - if err != nil { - fmt.Printf("error in select is %v", err) - return - } - fmt.Printf("response is %#v\n", resp.Data) - - // Delete tuple with primary key "key1". - _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - // Delete tuple with primary key "key2". - _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key2"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - - // Output: - // response is []interface {}{[]interface {}{"key1", "value1"}} - // response is []interface {}{[]interface {}{"key2", "value2"}} -} - -func ExampleConnectionPool_SelectTyped() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) - } - defer connPool.Close() - - // Connect to servers[2] to check if tuple - // was inserted on RW instance - conn, err := tarantool.Connect(servers[2], connOpts) - if err != nil || conn == nil { - fmt.Printf("failed to connect to %s", servers[2]) - return - } - - // Insert a new tuple {"key1", "value1"}. - _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - // Insert a new tuple {"key2", "value2"}. - _, err = conn.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - - var res []Tuple - err = connPool.SelectTyped( - spaceNo, indexNo, 0, 100, tarantool.IterEq, - []interface{}{"key1"}, &res, pool.PreferRW) - if err != nil { - fmt.Printf("error in select is %v", err) - return - } - fmt.Printf("response is %v\n", res) - err = connPool.SelectTyped( - spaceName, indexName, 0, 100, tarantool.IterEq, - []interface{}{"key2"}, &res, pool.PreferRW) - if err != nil { - fmt.Printf("error in select is %v", err) - return - } - fmt.Printf("response is %v\n", res) - - // Delete tuple with primary key "key1". - _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - // Delete tuple with primary key "key2". - _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key2"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - - // Output: - // response is [{{} key1 value1}] - // response is [{{} key2 value2}] -} - -func ExampleConnectionPool_SelectAsync() { +func ExampleConnectionPool_Do() { connPool, err := examplePool(testRoles, connOpts) if err != nil { fmt.Println(err) } defer connPool.Close() - // Connect to servers[2] to check if tuple - // was inserted on RW instance - conn, err := tarantool.Connect(servers[2], connOpts) - if err != nil || conn == nil { - fmt.Printf("failed to connect to %s", servers[2]) - return - } - - // Insert a new tuple {"key1", "value1"}. - _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - // Insert a new tuple {"key2", "value2"}. - _, err = conn.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - // Insert a new tuple {"key3", "value3"}. - _, err = conn.Insert(spaceNo, []interface{}{"key3", "value3"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - - var futs [3]*tarantool.Future - futs[0] = connPool.SelectAsync( - spaceName, indexName, 0, 2, tarantool.IterEq, - []interface{}{"key1"}, pool.PreferRW) - futs[1] = connPool.SelectAsync( - spaceName, indexName, 0, 1, tarantool.IterEq, - []interface{}{"key2"}, pool.RW) - futs[2] = connPool.SelectAsync( - spaceName, indexName, 0, 1, tarantool.IterEq, - []interface{}{"key3"}, pool.RW) - var t []Tuple - err = futs[0].GetTyped(&t) - fmt.Println("Future", 0, "Error", err) - fmt.Println("Future", 0, "Data", t) - - resp, err := futs[1].Get() - fmt.Println("Future", 1, "Error", err) - fmt.Println("Future", 1, "Data", resp.Data) - - resp, err = futs[2].Get() - fmt.Println("Future", 2, "Error", err) - fmt.Println("Future", 2, "Data", resp.Data) - - // Delete tuple with primary key "key1". - _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - // Delete tuple with primary key "key2". - _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key2"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - // Delete tuple with primary key "key3". - _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key3"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - - // Output: - // Future 0 Error - // Future 0 Data [{{} key1 value1}] - // Future 1 Error - // Future 1 Data [[key2 value2]] - // Future 2 Error - // Future 2 Data [[key3 value3]] -} - -func ExampleConnectionPool_SelectAsync_err() { - roles := []bool{true, true, true, true, true} - connPool, err := examplePool(roles, connOpts) - if err != nil { - fmt.Println(err) + modes := []pool.Mode{ + pool.ANY, + pool.RW, + pool.RO, + pool.PreferRW, + pool.PreferRO, } - defer connPool.Close() - - var futs [3]*tarantool.Future - futs[0] = connPool.SelectAsync( - spaceName, indexName, 0, 2, tarantool.IterEq, - []interface{}{"key1"}, pool.RW) - - err = futs[0].Err() - fmt.Println("Future", 0, "Error", err) - - // Output: - // Future 0 Error can't find rw instance in pool -} - -func ExampleConnectionPool_Ping() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) + for _, m := range modes { + // It could be any request object. + req := tarantool.NewPingRequest() + _, err := connPool.Do(req, m).Get() + fmt.Println("Ping Error", err) } - defer connPool.Close() - - // Ping a Tarantool instance to check connection. - resp, err := connPool.Ping(pool.ANY) - fmt.Println("Ping Code", resp.Code) - fmt.Println("Ping Data", resp.Data) - fmt.Println("Ping Error", err) // Output: - // Ping Code 0 - // Ping Data [] // Ping Error -} - -func ExampleConnectionPool_Insert() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) - } - defer connPool.Close() - - // Insert a new tuple {"key1", "value1"}. - resp, err := connPool.Insert(spaceNo, []interface{}{"key1", "value1"}) - fmt.Println("Insert key1") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - // Insert a new tuple {"key2", "value2"}. - resp, err = connPool.Insert(spaceName, &Tuple{Key: "key2", Value: "value2"}, pool.PreferRW) - fmt.Println("Insert key2") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - - // Connect to servers[2] to check if tuple - // was inserted on RW instance - conn, err := tarantool.Connect(servers[2], connOpts) - if err != nil || conn == nil { - fmt.Printf("failed to connect to %s", servers[2]) - return - } - - // Delete tuple with primary key "key1". - _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - // Delete tuple with primary key "key2". - _, err = conn.Delete(spaceNo, indexNo, []interface{}{"key2"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - // Output: - // Insert key1 - // Error - // Code 0 - // Data [[key1 value1]] - // Insert key2 - // Error - // Code 0 - // Data [[key2 value2]] -} - -func ExampleConnectionPool_Delete() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) - } - defer connPool.Close() - - // Connect to servers[2] to check if tuple - // was inserted on RW instance - conn, err := tarantool.Connect(servers[2], connOpts) - if err != nil || conn == nil { - fmt.Printf("failed to connect to %s", servers[2]) - return - } - - // Insert a new tuple {"key1", "value1"}. - _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - // Insert a new tuple {"key2", "value2"}. - _, err = conn.Insert(spaceNo, []interface{}{"key2", "value2"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - - // Delete tuple with primary key {"key1"}. - resp, err := connPool.Delete(spaceNo, indexNo, []interface{}{"key1"}) - fmt.Println("Delete key1") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - - // Delete tuple with primary key { "key2" }. - resp, err = connPool.Delete(spaceName, indexName, []interface{}{"key2"}, pool.PreferRW) - fmt.Println("Delete key2") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - // Output: - // Delete key1 - // Error - // Code 0 - // Data [[key1 value1]] - // Delete key2 - // Error - // Code 0 - // Data [[key2 value2]] -} - -func ExampleConnectionPool_Replace() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) - } - defer connPool.Close() - - // Connect to servers[2] to check if tuple - // was inserted on RW instance - conn, err := tarantool.Connect(servers[2], connOpts) - if err != nil || conn == nil { - fmt.Printf("failed to connect to %s", servers[2]) - return - } - - // Insert a new tuple {"key1", "value1"}. - _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - - // Replace a tuple with primary key ""key1. - // Note, Tuple is defined within tests, and has EncdodeMsgpack and - // DecodeMsgpack methods. - resp, err := connPool.Replace(spaceNo, []interface{}{"key1", "new_value"}) - fmt.Println("Replace key1") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - resp, err = connPool.Replace(spaceName, []interface{}{"key1", "another_value"}) - fmt.Println("Replace key1") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - resp, err = connPool.Replace(spaceName, &Tuple{Key: "key1", Value: "value2"}) - fmt.Println("Replace key1") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - resp, err = connPool.Replace(spaceName, &Tuple{Key: "key1", Value: "new_value2"}, pool.PreferRW) - fmt.Println("Replace key1") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - - // Delete tuple with primary key "key1". - _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - - // Output: - // Replace key1 - // Error - // Code 0 - // Data [[key1 new_value]] - // Replace key1 - // Error - // Code 0 - // Data [[key1 another_value]] - // Replace key1 - // Error - // Code 0 - // Data [[key1 value2]] - // Replace key1 - // Error - // Code 0 - // Data [[key1 new_value2]] -} - -func ExampleConnectionPool_Update() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) - } - defer connPool.Close() - - // Connect to servers[2] to check if tuple - // was inserted on RW instance - conn, err := tarantool.Connect(servers[2], connOpts) - if err != nil || conn == nil { - fmt.Printf("failed to connect to %s", servers[2]) - return - } - - // Insert a new tuple {"key1", "value1"}. - _, err = conn.Insert(spaceNo, []interface{}{"key1", "value1"}) - if err != nil { - fmt.Printf("Failed to insert: %s", err.Error()) - return - } - - // Update tuple with primary key { "key1" }. - resp, err := connPool.Update( - spaceName, indexName, []interface{}{"key1"}, - []interface{}{[]interface{}{"=", 1, "new_value"}}, pool.PreferRW) - fmt.Println("Update key1") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - - // Delete tuple with primary key "key1". - _, err = conn.Delete(spaceName, indexName, []interface{}{"key1"}) - if err != nil { - fmt.Printf("Failed to delete: %s", err.Error()) - } - - // Output: - // Update key1 - // Error - // Code 0 - // Data [[key1 new_value]] -} - -func ExampleConnectionPool_Call() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) - } - defer connPool.Close() - - // Call a function 'simple_incr' with arguments. - resp, err := connPool.Call17("simple_incr", []interface{}{1}, pool.PreferRW) - fmt.Println("Call simple_incr()") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - // Output: - // Call simple_incr() - // Error - // Code 0 - // Data [2] -} - -func ExampleConnectionPool_Eval() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) - } - defer connPool.Close() - - // Run raw Lua code. - resp, err := connPool.Eval("return 1 + 2", []interface{}{}, pool.PreferRW) - fmt.Println("Eval 'return 1 + 2'") - fmt.Println("Error", err) - fmt.Println("Code", resp.Code) - fmt.Println("Data", resp.Data) - // Output: - // Eval 'return 1 + 2' - // Error - // Code 0 - // Data [3] -} - -func ExampleConnectionPool_Do() { - connPool, err := examplePool(testRoles, connOpts) - if err != nil { - fmt.Println(err) - } - defer connPool.Close() - - // Ping a Tarantool instance to check connection. - req := tarantool.NewPingRequest() - resp, err := connPool.Do(req, pool.ANY).Get() - fmt.Println("Ping Code", resp.Code) - fmt.Println("Ping Data", resp.Data) - fmt.Println("Ping Error", err) - // Output: - // Ping Code 0 - // Ping Data [] + // Ping Error + // Ping Error + // Ping Error // Ping Error } @@ -917,7 +427,7 @@ func ExampleConnectorAdapter() { var connector tarantool.Connector = adapter // Ping an RW instance to check connection. - resp, err := connector.Ping() + resp, err := connector.Do(tarantool.NewPingRequest()).Get() fmt.Println("Ping Code", resp.Code) fmt.Println("Ping Data", resp.Data) fmt.Println("Ping Error", err) diff --git a/pool/pooler.go b/pool/pooler.go index a7cae8f95..a588d67f4 100644 --- a/pool/pooler.go +++ b/pool/pooler.go @@ -10,82 +10,148 @@ import ( type Pooler interface { ConnectedNow(mode Mode) (bool, error) Close() []error - Ping(mode Mode) (*tarantool.Response, error) ConfiguredTimeout(mode Mode) (time.Duration, error) + NewPrepared(expr string, mode Mode) (*tarantool.Prepared, error) + NewStream(mode Mode) (*tarantool.Stream, error) + NewWatcher(key string, callback tarantool.WatchCallback, + mode Mode) (tarantool.Watcher, error) + Do(req tarantool.Request, mode Mode) (fut *tarantool.Future) + // Deprecated: the method will be removed in the next major version, + // use a PingRequest object + Do() instead. + Ping(mode Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use a SelectRequest object + Do() instead. Select(space, index interface{}, offset, limit uint32, iterator tarantool.Iter, key interface{}, mode ...Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use an InsertRequest object + Do() instead. Insert(space interface{}, tuple interface{}, mode ...Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use a ReplaceRequest object + Do() instead. Replace(space interface{}, tuple interface{}, mode ...Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use a DeleteRequest object + Do() instead. Delete(space, index interface{}, key interface{}, mode ...Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use a UpdateRequest object + Do() instead. Update(space, index interface{}, key, ops interface{}, mode ...Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use a UpsertRequest object + Do() instead. Upsert(space interface{}, tuple, ops interface{}, mode ...Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use a CallRequest object + Do() instead. Call(functionName string, args interface{}, mode Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use a Call16Request object + Do() instead. Call16(functionName string, args interface{}, mode Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use a Call17Request object + Do() instead. Call17(functionName string, args interface{}, mode Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use an EvalRequest object + Do() instead. Eval(expr string, args interface{}, mode Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use an ExecuteRequest object + Do() instead. Execute(expr string, args interface{}, mode Mode) (*tarantool.Response, error) + // Deprecated: the method will be removed in the next major version, + // use a SelectRequest object + Do() instead. GetTyped(space, index interface{}, key interface{}, result interface{}, mode ...Mode) error + // Deprecated: the method will be removed in the next major version, + // use a SelectRequest object + Do() instead. SelectTyped(space, index interface{}, offset, limit uint32, iterator tarantool.Iter, key interface{}, result interface{}, mode ...Mode) error + // Deprecated: the method will be removed in the next major version, + // use an InsertRequest object + Do() instead. InsertTyped(space interface{}, tuple interface{}, result interface{}, mode ...Mode) error + // Deprecated: the method will be removed in the next major version, + // use a ReplaceRequest object + Do() instead. ReplaceTyped(space interface{}, tuple interface{}, result interface{}, mode ...Mode) error + // Deprecated: the method will be removed in the next major version, + // use a DeleteRequest object + Do() instead. DeleteTyped(space, index interface{}, key interface{}, result interface{}, mode ...Mode) error + // Deprecated: the method will be removed in the next major version, + // use a UpdateRequest object + Do() instead. UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}, mode ...Mode) error + // Deprecated: the method will be removed in the next major version, + // use a CallRequest object + Do() instead. CallTyped(functionName string, args interface{}, result interface{}, mode Mode) error + // Deprecated: the method will be removed in the next major version, + // use a Call16Request object + Do() instead. Call16Typed(functionName string, args interface{}, result interface{}, mode Mode) error + // Deprecated: the method will be removed in the next major version, + // use a Call17Request object + Do() instead. Call17Typed(functionName string, args interface{}, result interface{}, mode Mode) error + // Deprecated: the method will be removed in the next major version, + // use an EvalRequest object + Do() instead. EvalTyped(expr string, args interface{}, result interface{}, mode Mode) error + // Deprecated: the method will be removed in the next major version, + // use an ExecuteRequest object + Do() instead. ExecuteTyped(expr string, args interface{}, result interface{}, mode Mode) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error) + // Deprecated: the method will be removed in the next major version, + // use a SelectRequest object + Do() instead. SelectAsync(space, index interface{}, offset, limit uint32, iterator tarantool.Iter, key interface{}, mode ...Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use an InsertRequest object + Do() instead. InsertAsync(space interface{}, tuple interface{}, mode ...Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use a ReplaceRequest object + Do() instead. ReplaceAsync(space interface{}, tuple interface{}, mode ...Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use a DeleteRequest object + Do() instead. DeleteAsync(space, index interface{}, key interface{}, mode ...Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use a UpdateRequest object + Do() instead. UpdateAsync(space, index interface{}, key, ops interface{}, mode ...Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use a UpsertRequest object + Do() instead. UpsertAsync(space interface{}, tuple interface{}, ops interface{}, mode ...Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use a CallRequest object + Do() instead. CallAsync(functionName string, args interface{}, mode Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use a Call16Request object + Do() instead. Call16Async(functionName string, args interface{}, mode Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use a Call17Request object + Do() instead. Call17Async(functionName string, args interface{}, mode Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use an EvalRequest object + Do() instead. EvalAsync(expr string, args interface{}, mode Mode) *tarantool.Future + // Deprecated: the method will be removed in the next major version, + // use an ExecuteRequest object + Do() instead. ExecuteAsync(expr string, args interface{}, mode Mode) *tarantool.Future - - NewPrepared(expr string, mode Mode) (*tarantool.Prepared, error) - NewStream(mode Mode) (*tarantool.Stream, error) - NewWatcher(key string, callback tarantool.WatchCallback, - mode Mode) (tarantool.Watcher, error) - - Do(req tarantool.Request, mode Mode) (fut *tarantool.Future) } diff --git a/queue/queue.go b/queue/queue.go index 2407bad03..615e56819 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -197,20 +197,25 @@ func New(conn tarantool.Connector, name string) Queue { // Create creates a new queue with config. func (q *queue) Create(cfg Cfg) error { cmd := "local name, type, cfg = ... ; queue.create_tube(name, type, cfg)" - _, err := q.conn.Eval(cmd, []interface{}{q.name, cfg.getType(), cfg.toMap()}) + _, err := q.conn.Do(tarantool.NewEvalRequest(cmd). + Args([]interface{}{q.name, cfg.getType(), cfg.toMap()}), + ).Get() return err } // Set queue settings. func (q *queue) Cfg(opts CfgOpts) error { - _, err := q.conn.Call17(q.cmds.cfg, []interface{}{opts.toMap()}) + req := tarantool.NewCallRequest(q.cmds.cfg).Args([]interface{}{opts.toMap()}) + _, err := q.conn.Do(req).Get() return err } // Exists checks existence of a tube. func (q *queue) Exists() (bool, error) { cmd := "local name = ... ; return queue.tube[name] ~= nil" - resp, err := q.conn.Eval(cmd, []string{q.name}) + resp, err := q.conn.Do(tarantool.NewEvalRequest(cmd). + Args([]string{q.name}), + ).Get() if err != nil { return false, err } @@ -238,7 +243,8 @@ func (q *queue) Identify(u *uuid.UUID) (uuid.UUID, error) { } } - if resp, err := q.conn.Call17(q.cmds.identify, args); err == nil { + req := tarantool.NewCallRequest(q.cmds.identify).Args(args) + if resp, err := q.conn.Do(req).Get(); err == nil { if us, ok := resp.Data[0].(string); ok { return uuid.FromBytes([]byte(us)) } else { @@ -264,7 +270,8 @@ func (q *queue) put(params ...interface{}) (*Task, error) { result: params[0], q: q, } - if err := q.conn.Call17Typed(q.cmds.put, params, &qd); err != nil { + req := tarantool.NewCallRequest(q.cmds.put).Args(params) + if err := q.conn.Do(req).GetTyped(&qd); err != nil { return nil, err } return qd.task, nil @@ -315,7 +322,8 @@ func (q *queue) take(params interface{}, result ...interface{}) (*Task, error) { if len(result) > 0 { qd.result = result[0] } - if err := q.conn.Call17Typed(q.cmds.take, []interface{}{params}, &qd); err != nil { + req := tarantool.NewCallRequest(q.cmds.take).Args([]interface{}{params}) + if err := q.conn.Do(req).GetTyped(&qd); err != nil { return nil, err } return qd.task, nil @@ -323,20 +331,21 @@ func (q *queue) take(params interface{}, result ...interface{}) (*Task, error) { // Drop queue. func (q *queue) Drop() error { - _, err := q.conn.Call17(q.cmds.drop, []interface{}{}) + _, err := q.conn.Do(tarantool.NewCallRequest(q.cmds.drop)).Get() return err } // ReleaseAll forcibly returns all taken tasks to a ready state. func (q *queue) ReleaseAll() error { - _, err := q.conn.Call17(q.cmds.releaseAll, []interface{}{}) + _, err := q.conn.Do(tarantool.NewCallRequest(q.cmds.releaseAll)).Get() return err } // Look at a task without changing its state. func (q *queue) Peek(taskId uint64) (*Task, error) { qd := queueData{q: q} - if err := q.conn.Call17Typed(q.cmds.peek, []interface{}{taskId}, &qd); err != nil { + req := tarantool.NewCallRequest(q.cmds.peek).Args([]interface{}{taskId}) + if err := q.conn.Do(req).GetTyped(&qd); err != nil { return nil, err } return qd.task, nil @@ -363,7 +372,8 @@ func (q *queue) _release(taskId uint64, cfg Opts) (string, error) { } func (q *queue) produce(cmd string, params ...interface{}) (string, error) { qd := queueData{q: q} - if err := q.conn.Call17Typed(cmd, params, &qd); err != nil || qd.task == nil { + req := tarantool.NewCallRequest(cmd).Args(params) + if err := q.conn.Do(req).GetTyped(&qd); err != nil || qd.task == nil { return "", err } return qd.task.status, nil @@ -388,7 +398,8 @@ func (r *kickResult) DecodeMsgpack(d *msgpack.Decoder) (err error) { // Reverse the effect of a bury request on one or more tasks. func (q *queue) Kick(count uint64) (uint64, error) { var r kickResult - err := q.conn.Call17Typed(q.cmds.kick, []interface{}{count}, &r) + req := tarantool.NewCallRequest(q.cmds.kick).Args([]interface{}{count}) + err := q.conn.Do(req).GetTyped(&r) return r.id, err } @@ -400,7 +411,7 @@ func (q *queue) Delete(taskId uint64) error { // State returns a current queue state. func (q *queue) State() (State, error) { - resp, err := q.conn.Call17(q.cmds.state, []interface{}{}) + resp, err := q.conn.Do(tarantool.NewCallRequest(q.cmds.state)).Get() if err != nil { return UnknownState, err } @@ -417,7 +428,8 @@ func (q *queue) State() (State, error) { // Return the number of tasks in a queue broken down by task_state, and the // number of requests broken down by the type of request. func (q *queue) Statistic() (interface{}, error) { - resp, err := q.conn.Call17(q.cmds.statistics, []interface{}{q.name}) + req := tarantool.NewCallRequest(q.cmds.statistics).Args([]interface{}{q.name}) + resp, err := q.conn.Do(req).Get() if err != nil { return nil, err } diff --git a/request.go b/request.go index adb4a7b31..48c13e869 100644 --- a/request.go +++ b/request.go @@ -167,6 +167,9 @@ func fillPing(enc *msgpack.Encoder) error { } // Ping sends empty request to Tarantool to check connection. +// +// Deprecated: the method will be removed in the next major version, +// use a PingRequest object + Do() instead. func (conn *Connection) Ping() (resp *Response, err error) { return conn.Do(NewPingRequest()).Get() } @@ -174,6 +177,9 @@ func (conn *Connection) Ping() (resp *Response, err error) { // Select performs select to box space. // // It is equal to conn.SelectAsync(...).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (conn *Connection) Select(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) (resp *Response, err error) { return conn.SelectAsync(space, index, offset, limit, iterator, key).Get() } @@ -182,6 +188,9 @@ func (conn *Connection) Select(space, index interface{}, offset, limit uint32, i // Tarantool will reject Insert when tuple with same primary key exists. // // It is equal to conn.InsertAsync(space, tuple).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use an InsertRequest object + Do() instead. func (conn *Connection) Insert(space interface{}, tuple interface{}) (resp *Response, err error) { return conn.InsertAsync(space, tuple).Get() } @@ -190,6 +199,9 @@ func (conn *Connection) Insert(space interface{}, tuple interface{}) (resp *Resp // If tuple with same primary key exists, it will be replaced. // // It is equal to conn.ReplaceAsync(space, tuple).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use a ReplaceRequest object + Do() instead. func (conn *Connection) Replace(space interface{}, tuple interface{}) (resp *Response, err error) { return conn.ReplaceAsync(space, tuple).Get() } @@ -198,6 +210,9 @@ func (conn *Connection) Replace(space interface{}, tuple interface{}) (resp *Res // Result will contain array with deleted tuple. // // It is equal to conn.DeleteAsync(space, tuple).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use a DeleteRequest object + Do() instead. func (conn *Connection) Delete(space, index interface{}, key interface{}) (resp *Response, err error) { return conn.DeleteAsync(space, index, key).Get() } @@ -206,6 +221,9 @@ func (conn *Connection) Delete(space, index interface{}, key interface{}) (resp // Result will contain array with updated tuple. // // It is equal to conn.UpdateAsync(space, tuple).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use a UpdateRequest object + Do() instead. func (conn *Connection) Update(space, index interface{}, key, ops interface{}) (resp *Response, err error) { return conn.UpdateAsync(space, index, key, ops).Get() } @@ -214,6 +232,9 @@ func (conn *Connection) Update(space, index interface{}, key, ops interface{}) ( // Result will not contain any tuple. // // It is equal to conn.UpsertAsync(space, tuple, ops).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use a UpsertRequest object + Do() instead. func (conn *Connection) Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error) { return conn.UpsertAsync(space, tuple, ops).Get() } @@ -222,6 +243,9 @@ func (conn *Connection) Upsert(space interface{}, tuple, ops interface{}) (resp // It uses request code for Tarantool >= 1.7, result is an array. // // It is equal to conn.CallAsync(functionName, args).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use a CallRequest object + Do() instead. func (conn *Connection) Call(functionName string, args interface{}) (resp *Response, err error) { return conn.CallAsync(functionName, args).Get() } @@ -231,6 +255,9 @@ func (conn *Connection) Call(functionName string, args interface{}) (resp *Respo // Deprecated since Tarantool 1.7.2. // // It is equal to conn.Call16Async(functionName, args).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use a Call16Request object + Do() instead. func (conn *Connection) Call16(functionName string, args interface{}) (resp *Response, err error) { return conn.Call16Async(functionName, args).Get() } @@ -239,6 +266,9 @@ func (conn *Connection) Call16(functionName string, args interface{}) (resp *Res // It uses request code for Tarantool >= 1.7, result is an array. // // It is equal to conn.Call17Async(functionName, args).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use a Call17Request object + Do() instead. func (conn *Connection) Call17(functionName string, args interface{}) (resp *Response, err error) { return conn.Call17Async(functionName, args).Get() } @@ -246,6 +276,9 @@ func (conn *Connection) Call17(functionName string, args interface{}) (resp *Res // Eval passes Lua expression for evaluation. // // It is equal to conn.EvalAsync(space, tuple).Get(). +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (conn *Connection) Eval(expr string, args interface{}) (resp *Response, err error) { return conn.EvalAsync(expr, args).Get() } @@ -254,6 +287,9 @@ func (conn *Connection) Eval(expr string, args interface{}) (resp *Response, err // // It is equal to conn.ExecuteAsync(expr, args).Get(). // Since 1.6.0 +// +// Deprecated: the method will be removed in the next major version, +// use an ExecuteRequest object + Do() instead. func (conn *Connection) Execute(expr string, args interface{}) (resp *Response, err error) { return conn.ExecuteAsync(expr, args).Get() } @@ -283,6 +319,9 @@ func (s *single) DecodeMsgpack(d *msgpack.Decoder) error { // to box space and fills typed result. // // It is equal to conn.SelectAsync(space, index, 0, 1, IterEq, key).GetTyped(&result) +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (conn *Connection) GetTyped(space, index interface{}, key interface{}, result interface{}) (err error) { s := single{res: result} err = conn.SelectAsync(space, index, 0, 1, IterEq, key).GetTyped(&s) @@ -292,6 +331,9 @@ func (conn *Connection) GetTyped(space, index interface{}, key interface{}, resu // SelectTyped performs select to box space and fills typed result. // // It is equal to conn.SelectAsync(space, index, offset, limit, iterator, key).GetTyped(&result) +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (conn *Connection) SelectTyped(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}, result interface{}) (err error) { return conn.SelectAsync(space, index, offset, limit, iterator, key).GetTyped(result) } @@ -300,6 +342,9 @@ func (conn *Connection) SelectTyped(space, index interface{}, offset, limit uint // Tarantool will reject Insert when tuple with same primary key exists. // // It is equal to conn.InsertAsync(space, tuple).GetTyped(&result). +// +// Deprecated: the method will be removed in the next major version, +// use an InsertRequest object + Do() instead. func (conn *Connection) InsertTyped(space interface{}, tuple interface{}, result interface{}) (err error) { return conn.InsertAsync(space, tuple).GetTyped(result) } @@ -308,6 +353,9 @@ func (conn *Connection) InsertTyped(space interface{}, tuple interface{}, result // If tuple with same primary key exists, it will be replaced. // // It is equal to conn.ReplaceAsync(space, tuple).GetTyped(&result). +// +// Deprecated: the method will be removed in the next major version, +// use a ReplaceRequest object + Do() instead. func (conn *Connection) ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error) { return conn.ReplaceAsync(space, tuple).GetTyped(result) } @@ -315,6 +363,9 @@ func (conn *Connection) ReplaceTyped(space interface{}, tuple interface{}, resul // DeleteTyped performs deletion of a tuple by key and fills result with deleted tuple. // // It is equal to conn.DeleteAsync(space, tuple).GetTyped(&result). +// +// Deprecated: the method will be removed in the next major version, +// use a DeleteRequest object + Do() instead. func (conn *Connection) DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error) { return conn.DeleteAsync(space, index, key).GetTyped(result) } @@ -322,6 +373,9 @@ func (conn *Connection) DeleteTyped(space, index interface{}, key interface{}, r // UpdateTyped performs update of a tuple by key and fills result with updated tuple. // // It is equal to conn.UpdateAsync(space, tuple, ops).GetTyped(&result). +// +// Deprecated: the method will be removed in the next major version, +// use a UpdateRequest object + Do() instead. func (conn *Connection) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error) { return conn.UpdateAsync(space, index, key, ops).GetTyped(result) } @@ -330,6 +384,9 @@ func (conn *Connection) UpdateTyped(space, index interface{}, key, ops interface // It uses request code for Tarantool >= 1.7, result is an array. // // It is equal to conn.Call16Async(functionName, args).GetTyped(&result). +// +// Deprecated: the method will be removed in the next major version, +// use a CallRequest object + Do() instead. func (conn *Connection) CallTyped(functionName string, args interface{}, result interface{}) (err error) { return conn.CallAsync(functionName, args).GetTyped(result) } @@ -339,6 +396,9 @@ func (conn *Connection) CallTyped(functionName string, args interface{}, result // Deprecated since Tarantool 1.7.2. // // It is equal to conn.Call16Async(functionName, args).GetTyped(&result). +// +// Deprecated: the method will be removed in the next major version, +// use a Call16Request object + Do() instead. func (conn *Connection) Call16Typed(functionName string, args interface{}, result interface{}) (err error) { return conn.Call16Async(functionName, args).GetTyped(result) } @@ -347,6 +407,9 @@ func (conn *Connection) Call16Typed(functionName string, args interface{}, resul // It uses request code for Tarantool >= 1.7, result is an array. // // It is equal to conn.Call17Async(functionName, args).GetTyped(&result). +// +// Deprecated: the method will be removed in the next major version, +// use a Call17Request object + Do() instead. func (conn *Connection) Call17Typed(functionName string, args interface{}, result interface{}) (err error) { return conn.Call17Async(functionName, args).GetTyped(result) } @@ -354,6 +417,9 @@ func (conn *Connection) Call17Typed(functionName string, args interface{}, resul // EvalTyped passes Lua expression for evaluation. // // It is equal to conn.EvalAsync(space, tuple).GetTyped(&result). +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (conn *Connection) EvalTyped(expr string, args interface{}, result interface{}) (err error) { return conn.EvalAsync(expr, args).GetTyped(result) } @@ -362,6 +428,9 @@ func (conn *Connection) EvalTyped(expr string, args interface{}, result interfac // // In addition to error returns sql info and columns meta data // Since 1.6.0 +// +// Deprecated: the method will be removed in the next major version, +// use an ExecuteRequest object + Do() instead. func (conn *Connection) ExecuteTyped(expr string, args interface{}, result interface{}) (SQLInfo, []ColumnMetaData, error) { fut := conn.ExecuteAsync(expr, args) err := fut.GetTyped(&result) @@ -369,6 +438,9 @@ func (conn *Connection) ExecuteTyped(expr string, args interface{}, result inter } // SelectAsync sends select request to Tarantool and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use a SelectRequest object + Do() instead. func (conn *Connection) SelectAsync(space, index interface{}, offset, limit uint32, iterator Iter, key interface{}) *Future { req := NewSelectRequest(space). Index(index). @@ -381,6 +453,9 @@ func (conn *Connection) SelectAsync(space, index interface{}, offset, limit uint // InsertAsync sends insert action to Tarantool and returns Future. // Tarantool will reject Insert when tuple with same primary key exists. +// +// Deprecated: the method will be removed in the next major version, +// use an InsertRequest object + Do() instead. func (conn *Connection) InsertAsync(space interface{}, tuple interface{}) *Future { req := NewInsertRequest(space).Tuple(tuple) return conn.Do(req) @@ -388,6 +463,9 @@ func (conn *Connection) InsertAsync(space interface{}, tuple interface{}) *Futur // ReplaceAsync sends "insert or replace" action to Tarantool and returns Future. // If tuple with same primary key exists, it will be replaced. +// +// Deprecated: the method will be removed in the next major version, +// use a ReplaceRequest object + Do() instead. func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Future { req := NewReplaceRequest(space).Tuple(tuple) return conn.Do(req) @@ -395,6 +473,9 @@ func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Futu // DeleteAsync sends deletion action to Tarantool and returns Future. // Future's result will contain array with deleted tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a DeleteRequest object + Do() instead. func (conn *Connection) DeleteAsync(space, index interface{}, key interface{}) *Future { req := NewDeleteRequest(space).Index(index).Key(key) return conn.Do(req) @@ -402,6 +483,9 @@ func (conn *Connection) DeleteAsync(space, index interface{}, key interface{}) * // Update sends deletion of a tuple by key and returns Future. // Future's result will contain array with updated tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a UpdateRequest object + Do() instead. func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface{}) *Future { req := NewUpdateRequest(space).Index(index).Key(key) req.ops = ops @@ -410,6 +494,9 @@ func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface // UpsertAsync sends "update or insert" action to Tarantool and returns Future. // Future's sesult will not contain any tuple. +// +// Deprecated: the method will be removed in the next major version, +// use a UpsertRequest object + Do() instead. func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future { req := NewUpsertRequest(space).Tuple(tuple) req.ops = ops @@ -418,6 +505,9 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in // CallAsync sends a call to registered Tarantool function and returns Future. // It uses request code for Tarantool >= 1.7, so future's result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a CallRequest object + Do() instead. func (conn *Connection) CallAsync(functionName string, args interface{}) *Future { req := NewCallRequest(functionName).Args(args) return conn.Do(req) @@ -426,6 +516,9 @@ func (conn *Connection) CallAsync(functionName string, args interface{}) *Future // Call16Async sends a call to registered Tarantool function and returns Future. // It uses request code for Tarantool 1.6, so future's result is an array of arrays. // Deprecated since Tarantool 1.7.2. +// +// Deprecated: the method will be removed in the next major version, +// use a Call16Request object + Do() instead. func (conn *Connection) Call16Async(functionName string, args interface{}) *Future { req := NewCall16Request(functionName).Args(args) return conn.Do(req) @@ -433,12 +526,18 @@ func (conn *Connection) Call16Async(functionName string, args interface{}) *Futu // Call17Async sends a call to registered Tarantool function and returns Future. // It uses request code for Tarantool >= 1.7, so future's result is an array. +// +// Deprecated: the method will be removed in the next major version, +// use a Call17Request object + Do() instead. func (conn *Connection) Call17Async(functionName string, args interface{}) *Future { req := NewCall17Request(functionName).Args(args) return conn.Do(req) } // EvalAsync sends a Lua expression for evaluation and returns Future. +// +// Deprecated: the method will be removed in the next major version, +// use an EvalRequest object + Do() instead. func (conn *Connection) EvalAsync(expr string, args interface{}) *Future { req := NewEvalRequest(expr).Args(args) return conn.Do(req) @@ -446,6 +545,9 @@ func (conn *Connection) EvalAsync(expr string, args interface{}) *Future { // ExecuteAsync sends a sql expression for execution and returns Future. // Since 1.6.0 +// +// Deprecated: the method will be removed in the next major version, +// use an ExecuteRequest object + Do() instead. func (conn *Connection) ExecuteAsync(expr string, args interface{}) *Future { req := NewExecuteRequest(expr).Args(args) return conn.Do(req) diff --git a/settings/example_test.go b/settings/example_test.go index c9bdc3c49..b1d0e5d4f 100644 --- a/settings/example_test.go +++ b/settings/example_test.go @@ -31,14 +31,16 @@ func Example_sqlFullColumnNames() { } // Create a space. - _, err = conn.Execute("CREATE TABLE example(id INT PRIMARY KEY, x INT);", []interface{}{}) + req := tarantool.NewExecuteRequest("CREATE TABLE example(id INT PRIMARY KEY, x INT);") + _, err = conn.Do(req).Get() if err != nil { fmt.Printf("error in create table: %v\n", err) return } // Insert some tuple into space. - _, err = conn.Execute("INSERT INTO example VALUES (1, 1);", []interface{}{}) + req = tarantool.NewExecuteRequest("INSERT INTO example VALUES (1, 1);") + _, err = conn.Do(req).Get() if err != nil { fmt.Printf("error on insert: %v\n", err) return @@ -52,7 +54,8 @@ func Example_sqlFullColumnNames() { } // Get some data with SQL query. - resp, err = conn.Execute("SELECT x FROM example WHERE id = 1;", []interface{}{}) + req = tarantool.NewExecuteRequest("SELECT x FROM example WHERE id = 1;") + _, err = conn.Do(req).Get() if err != nil { fmt.Printf("error on select: %v\n", err) return @@ -68,7 +71,7 @@ func Example_sqlFullColumnNames() { } // Get some data with SQL query. - resp, err = conn.Execute("SELECT x FROM example WHERE id = 1;", []interface{}{}) + _, err = conn.Do(req).Get() if err != nil { fmt.Printf("error on select: %v\n", err) return diff --git a/settings/tarantool_test.go b/settings/tarantool_test.go index aeec28cc0..128e84328 100644 --- a/settings/tarantool_test.go +++ b/settings/tarantool_test.go @@ -68,7 +68,8 @@ func TestErrorMarshalingEnabledSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"error_marshaling_enabled", false}}, resp.Data) // Get a box.Error value. - resp, err = conn.Eval("return box.error.new(box.error.UNKNOWN)", []interface{}{}) + eval := tarantool.NewEvalRequest("return box.error.new(box.error.UNKNOWN)") + resp, err = conn.Do(eval).Get() require.Nil(t, err) require.NotNil(t, resp) require.IsType(t, "string", resp.Data[0]) @@ -86,7 +87,7 @@ func TestErrorMarshalingEnabledSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"error_marshaling_enabled", true}}, resp.Data) // Get a box.Error value. - resp, err = conn.Eval("return box.error.new(box.error.UNKNOWN)", []interface{}{}) + resp, err = conn.Do(eval).Get() require.Nil(t, err) require.NotNil(t, resp) _, ok := resp.Data[0].(*tarantool.BoxError) @@ -116,13 +117,15 @@ func TestSQLDefaultEngineSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_default_engine", "vinyl"}}, resp.Data) // Create a space with "CREATE TABLE". - resp, err = conn.Execute("CREATE TABLE t1_vinyl(a INT PRIMARY KEY, b INT, c INT);", []interface{}{}) + exec := tarantool.NewExecuteRequest("CREATE TABLE t1_vinyl(a INT PRIMARY KEY, b INT, c INT);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) // Check new space engine. - resp, err = conn.Eval("return box.space['T1_VINYL'].engine", []interface{}{}) + eval := tarantool.NewEvalRequest("return box.space['T1_VINYL'].engine") + resp, err = conn.Do(eval).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, "vinyl", resp.Data[0]) @@ -140,13 +143,15 @@ func TestSQLDefaultEngineSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_default_engine", "memtx"}}, resp.Data) // Create a space with "CREATE TABLE". - resp, err = conn.Execute("CREATE TABLE t2_memtx(a INT PRIMARY KEY, b INT, c INT);", []interface{}{}) + exec = tarantool.NewExecuteRequest("CREATE TABLE t2_memtx(a INT PRIMARY KEY, b INT, c INT);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) // Check new space engine. - resp, err = conn.Eval("return box.space['T2_MEMTX'].engine", []interface{}{}) + eval = tarantool.NewEvalRequest("return box.space['T2_MEMTX'].engine") + resp, err = conn.Do(eval).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, "memtx", resp.Data[0]) @@ -163,13 +168,15 @@ func TestSQLDeferForeignKeysSetting(t *testing.T) { defer conn.Close() // Create a parent space. - resp, err = conn.Execute("CREATE TABLE parent(id INT PRIMARY KEY, y INT UNIQUE);", []interface{}{}) + exec := tarantool.NewExecuteRequest("CREATE TABLE parent(id INT PRIMARY KEY, y INT UNIQUE);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) // Create a space with reference to the parent space. - resp, err = conn.Execute("CREATE TABLE child(id INT PRIMARY KEY, x INT REFERENCES parent(y));", []interface{}{}) + exec = tarantool.NewExecuteRequest("CREATE TABLE child(id INT PRIMARY KEY, x INT REFERENCES parent(y));") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) @@ -200,7 +207,7 @@ func TestSQLDeferForeignKeysSetting(t *testing.T) { // Evaluate a scenario when foreign key not exists // on INSERT, but exists on commit. - _, err = conn.Eval(deferEval, []interface{}{}) + _, err = conn.Do(tarantool.NewEvalRequest(deferEval)).Get() require.NotNil(t, err) require.ErrorContains(t, err, "Failed to execute SQL statement: FOREIGN KEY constraint failed") @@ -217,7 +224,7 @@ func TestSQLDeferForeignKeysSetting(t *testing.T) { // Evaluate a scenario when foreign key not exists // on INSERT, but exists on commit. - resp, err = conn.Eval(deferEval, []interface{}{}) + resp, err = conn.Do(tarantool.NewEvalRequest(deferEval)).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, true, resp.Data[0]) @@ -233,13 +240,15 @@ func TestSQLFullColumnNamesSetting(t *testing.T) { defer conn.Close() // Create a space. - resp, err = conn.Execute("CREATE TABLE fkname(id INT PRIMARY KEY, x INT);", []interface{}{}) + exec := tarantool.NewExecuteRequest("CREATE TABLE fkname(id INT PRIMARY KEY, x INT);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) // Fill it with some data. - resp, err = conn.Execute("INSERT INTO fkname VALUES (1, 1);", []interface{}{}) + exec = tarantool.NewExecuteRequest("INSERT INTO fkname VALUES (1, 1);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) @@ -257,7 +266,8 @@ func TestSQLFullColumnNamesSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_full_column_names", false}}, resp.Data) // Get a data with short column names in metadata. - resp, err = conn.Execute("SELECT x FROM fkname WHERE id = 1;", []interface{}{}) + exec = tarantool.NewExecuteRequest("SELECT x FROM fkname WHERE id = 1;") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, "X", resp.MetaData[0].FieldName) @@ -275,7 +285,8 @@ func TestSQLFullColumnNamesSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_full_column_names", true}}, resp.Data) // Get a data with full column names in metadata. - resp, err = conn.Execute("SELECT x FROM fkname WHERE id = 1;", []interface{}{}) + exec = tarantool.NewExecuteRequest("SELECT x FROM fkname WHERE id = 1;") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, "FKNAME.X", resp.MetaData[0].FieldName) @@ -291,13 +302,15 @@ func TestSQLFullMetadataSetting(t *testing.T) { defer conn.Close() // Create a space. - resp, err = conn.Execute("CREATE TABLE fmt(id INT PRIMARY KEY, x INT);", []interface{}{}) + exec := tarantool.NewExecuteRequest("CREATE TABLE fmt(id INT PRIMARY KEY, x INT);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) // Fill it with some data. - resp, err = conn.Execute("INSERT INTO fmt VALUES (1, 1);", []interface{}{}) + exec = tarantool.NewExecuteRequest("INSERT INTO fmt VALUES (1, 1);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) @@ -314,7 +327,8 @@ func TestSQLFullMetadataSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_full_metadata", false}}, resp.Data) // Get a data without additional fields in metadata. - resp, err = conn.Execute("SELECT x FROM fmt WHERE id = 1;", []interface{}{}) + exec = tarantool.NewExecuteRequest("SELECT x FROM fmt WHERE id = 1;") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, "", resp.MetaData[0].FieldSpan) @@ -332,7 +346,8 @@ func TestSQLFullMetadataSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_full_metadata", true}}, resp.Data) // Get a data with additional fields in metadata. - resp, err = conn.Execute("SELECT x FROM fmt WHERE id = 1;", []interface{}{}) + exec = tarantool.NewExecuteRequest("SELECT x FROM fmt WHERE id = 1;") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, "x", resp.MetaData[0].FieldSpan) @@ -386,22 +401,25 @@ func TestSQLRecursiveTriggersSetting(t *testing.T) { defer conn.Close() // Create a space. - resp, err = conn.Execute("CREATE TABLE rec(id INTEGER PRIMARY KEY, a INT, b INT);", []interface{}{}) + exec := tarantool.NewExecuteRequest("CREATE TABLE rec(id INTEGER PRIMARY KEY, a INT, b INT);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) // Fill it with some data. - resp, err = conn.Execute("INSERT INTO rec VALUES(1, 1, 2);", []interface{}{}) + exec = tarantool.NewExecuteRequest("INSERT INTO rec VALUES(1, 1, 2);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) // Create a recursive trigger (with infinite depth). - resp, err = conn.Execute(` + exec = tarantool.NewExecuteRequest(` CREATE TRIGGER tr12 AFTER UPDATE ON rec FOR EACH ROW BEGIN UPDATE rec SET a=new.a+1, b=new.b+1; - END;`, []interface{}{}) + END;`) + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) @@ -419,7 +437,8 @@ func TestSQLRecursiveTriggersSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_recursive_triggers", true}}, resp.Data) // Trigger the recursion. - _, err = conn.Execute("UPDATE rec SET a=a+1, b=b+1;", []interface{}{}) + exec = tarantool.NewExecuteRequest("UPDATE rec SET a=a+1, b=b+1;") + _, err = conn.Do(exec).Get() require.NotNil(t, err) require.ErrorContains(t, err, "Failed to execute SQL statement: too many levels of trigger recursion") @@ -436,7 +455,8 @@ func TestSQLRecursiveTriggersSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_recursive_triggers", false}}, resp.Data) // Trigger the recursion. - resp, err = conn.Execute("UPDATE rec SET a=a+1, b=b+1;", []interface{}{}) + exec = tarantool.NewExecuteRequest("UPDATE rec SET a=a+1, b=b+1;") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) @@ -452,18 +472,21 @@ func TestSQLReverseUnorderedSelectsSetting(t *testing.T) { defer conn.Close() // Create a space. - resp, err = conn.Execute("CREATE TABLE data(id STRING PRIMARY KEY);", []interface{}{}) + exec := tarantool.NewExecuteRequest("CREATE TABLE data(id STRING PRIMARY KEY);") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) // Fill it with some data. - resp, err = conn.Execute("INSERT INTO data VALUES('1');", []interface{}{}) + exec = tarantool.NewExecuteRequest("INSERT INTO data VALUES('1');") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) - resp, err = conn.Execute("INSERT INTO data VALUES('2');", []interface{}{}) + exec = tarantool.NewExecuteRequest("INSERT INTO data VALUES('2');") + resp, err = conn.Do(exec).Get() require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) @@ -488,7 +511,7 @@ func TestSQLReverseUnorderedSelectsSetting(t *testing.T) { query = "SELECT * FROM data;" } - resp, err = conn.Execute(query, []interface{}{}) + resp, err = conn.Do(tarantool.NewExecuteRequest(query)).Get() require.Nil(t, err) require.NotNil(t, resp) require.EqualValues(t, []interface{}{"1"}, resp.Data[0]) @@ -507,7 +530,7 @@ func TestSQLReverseUnorderedSelectsSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_reverse_unordered_selects", true}}, resp.Data) // Select multiple records. - resp, err = conn.Execute(query, []interface{}{}) + resp, err = conn.Do(tarantool.NewExecuteRequest(query)).Get() require.Nil(t, err) require.NotNil(t, resp) require.EqualValues(t, []interface{}{"2"}, resp.Data[0]) diff --git a/test_helpers/main.go b/test_helpers/main.go index c234d4c02..c777f2f26 100644 --- a/test_helpers/main.go +++ b/test_helpers/main.go @@ -106,7 +106,7 @@ func isReady(server string, opts *tarantool.Opts) error { } defer conn.Close() - resp, err = conn.Ping() + resp, err = conn.Do(tarantool.NewPingRequest()).Get() if err != nil { return err } diff --git a/test_helpers/pool_helper.go b/test_helpers/pool_helper.go index a559ef98d..7dcd70cbc 100644 --- a/test_helpers/pool_helper.go +++ b/test_helpers/pool_helper.go @@ -82,7 +82,8 @@ func ProcessListenOnInstance(args interface{}) error { } for i := 0; i < listenArgs.ServersNumber; i++ { - resp, err := listenArgs.ConnPool.Eval("return box.cfg.listen", []interface{}{}, listenArgs.Mode) + req := tarantool.NewEvalRequest("return box.cfg.listen") + resp, err := listenArgs.ConnPool.Do(req, listenArgs.Mode).Get() if err != nil { return fmt.Errorf("fail to Eval: %s", err.Error()) } @@ -138,7 +139,7 @@ func InsertOnInstance(server string, connOpts tarantool.Opts, space interface{}, } defer conn.Close() - resp, err := conn.Insert(space, tuple) + resp, err := conn.Do(tarantool.NewInsertRequest(space).Tuple(tuple)).Get() if err != nil { return fmt.Errorf("Failed to Insert: %s", err.Error()) } @@ -195,8 +196,9 @@ func SetInstanceRO(server string, connOpts tarantool.Opts, isReplica bool) error defer conn.Close() - _, err = conn.Call17("box.cfg", []interface{}{map[string]bool{"read_only": isReplica}}) - if err != nil { + req := tarantool.NewCallRequest("box.cfg"). + Args([]interface{}{map[string]bool{"read_only": isReplica}}) + if _, err := conn.Do(req).Get(); err != nil { return err } diff --git a/uuid/example_test.go b/uuid/example_test.go index 6ad8ebad9..632f620be 100644 --- a/uuid/example_test.go +++ b/uuid/example_test.go @@ -37,7 +37,9 @@ func Example() { log.Fatalf("Failed to prepare uuid: %s", uuidErr) } - resp, err := client.Replace(spaceNo, []interface{}{id}) + resp, err := client.Do(tarantool.NewReplaceRequest(spaceNo). + Tuple([]interface{}{id}), + ).Get() fmt.Println("UUID tuple replace") fmt.Println("Error", err) diff --git a/uuid/uuid_test.go b/uuid/uuid_test.go index f09caf03d..84abd42d2 100644 --- a/uuid/uuid_test.go +++ b/uuid/uuid_test.go @@ -81,7 +81,12 @@ func TestSelect(t *testing.T) { t.Fatalf("Failed to prepare test uuid: %s", uuidErr) } - resp, errSel := conn.Select(space, index, 0, 1, IterEq, []interface{}{id}) + sel := NewSelectRequest(space). + Index(index). + Limit(1). + Iterator(IterEq). + Key([]interface{}{id}) + resp, errSel := conn.Do(sel).Get() if errSel != nil { t.Fatalf("UUID select failed: %s", errSel.Error()) } @@ -91,7 +96,7 @@ func TestSelect(t *testing.T) { tupleValueIsId(t, resp.Data, id) var tuples []TupleUUID - errTyp := conn.SelectTyped(space, index, 0, 1, IterEq, []interface{}{id}, &tuples) + errTyp := conn.Do(sel).GetTyped(&tuples) if errTyp != nil { t.Fatalf("Failed to SelectTyped: %s", errTyp.Error()) } @@ -116,7 +121,8 @@ func TestReplace(t *testing.T) { t.Errorf("Failed to prepare test uuid: %s", uuidErr) } - respRep, errRep := conn.Replace(space, []interface{}{id}) + rep := NewReplaceRequest(space).Tuple([]interface{}{id}) + respRep, errRep := conn.Do(rep).Get() if errRep != nil { t.Errorf("UUID replace failed: %s", errRep) } @@ -125,7 +131,12 @@ func TestReplace(t *testing.T) { } tupleValueIsId(t, respRep.Data, id) - respSel, errSel := conn.Select(space, index, 0, 1, IterEq, []interface{}{id}) + sel := NewSelectRequest(space). + Index(index). + Limit(1). + Iterator(IterEq). + Key([]interface{}{id}) + respSel, errSel := conn.Do(sel).Get() if errSel != nil { t.Errorf("UUID select failed: %s", errSel) }