@@ -2,6 +2,7 @@ package tarantool
2
2
3
3
import (
4
4
"errors"
5
+ "reflect"
5
6
"time"
6
7
7
8
"gopkg.in/vmihailenco/msgpack.v2"
@@ -120,6 +121,13 @@ func (conn *Connection) Eval(expr string, args interface{}) (resp *Response, err
120
121
return conn .EvalAsync (expr , args ).Get ()
121
122
}
122
123
124
+ // Execute passes sql expression for execution.
125
+ //
126
+ // It is equal to conn.ExecuteAsync(space, tuple).Get().
127
+ func (conn * Connection ) Execute (expr string , args interface {}) (resp * Response , err error ) {
128
+ return conn .ExecuteAsync (expr , args ).Get ()
129
+ }
130
+
123
131
// single used for conn.GetTyped for decode one tuple
124
132
type single struct {
125
133
res interface {}
@@ -346,10 +354,39 @@ func (conn *Connection) EvalAsync(expr string, args interface{}) *Future {
346
354
})
347
355
}
348
356
357
+ // ExecuteAsync sends a sql expression for execution and returns Future.
358
+ func (conn * Connection ) ExecuteAsync (expr string , args interface {}) * Future {
359
+ future := conn .newFuture (ExecuteRequest )
360
+ bind := makeSQLBind (args )
361
+ return future .send (conn , func (enc * msgpack.Encoder ) error {
362
+ enc .EncodeMapLen (2 )
363
+ enc .EncodeUint64 (KeySQLText )
364
+ enc .EncodeString (expr )
365
+ enc .EncodeUint64 (KeySQLBind )
366
+ return enc .Encode (bind )
367
+ })
368
+ }
369
+
349
370
//
350
371
// private
351
372
//
352
373
374
+ func makeSQLBind (from interface {}) interface {} {
375
+ val := reflect .ValueOf (from )
376
+ arr := []map [string ]interface {}{}
377
+
378
+ if val .Kind () == reflect .Map {
379
+ for _ , e := range val .MapKeys () {
380
+ mp := map [string ]interface {}{}
381
+ v := val .MapIndex (e )
382
+ t := v .Interface ()
383
+ mp [":" + e .String ()] = t
384
+ arr = append (arr , mp )
385
+ }
386
+ }
387
+ return arr
388
+ }
389
+
353
390
func (fut * Future ) pack (h * smallWBuf , enc * msgpack.Encoder , body func (* msgpack.Encoder ) error ) (err error ) {
354
391
rid := fut .requestId
355
392
hl := h .Len ()
0 commit comments