Skip to content

Commit b73b8b7

Browse files
committed
sql: add execute methods to multi-connection handlers
This patch adds methods Execute, ExecuteAsync and ExecuteTyped to multi and connection_pool handlers. Follows up #62
1 parent 87df0a1 commit b73b8b7

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

connection_pool/connection_pool.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ func (connPool *ConnectionPool) Eval(expr string, args interface{}, userMode Mod
302302
return conn.Eval(expr, args)
303303
}
304304

305+
// Execute passes a sql expression to Tarantool for execution.
306+
//
307+
// Since 1.7.0
308+
func (connPool *ConnectionPool) Execute(expr string, args interface{}, userMode Mode) (resp *tarantool.Response, err error) {
309+
conn, err := connPool.getNextConnection(userMode)
310+
if err != nil {
311+
return nil, err
312+
}
313+
314+
return conn.Execute(expr, args)
315+
}
316+
305317
// GetTyped performs select (with limit = 1 and offset = 0)
306318
// to box space and fills typed result.
307319
func (connPool *ConnectionPool) GetTyped(space, index interface{}, key interface{}, result interface{}, userMode ...Mode) (err error) {
@@ -412,6 +424,18 @@ func (connPool *ConnectionPool) EvalTyped(expr string, args interface{}, result
412424
return conn.EvalTyped(expr, args, result)
413425
}
414426

427+
// ExecuteTyped passes a sql expression for execution.
428+
//
429+
// Since 1.7.0
430+
func (connPool *ConnectionPool) ExecuteTyped(expr string, args interface{}, result interface{}, userMode Mode) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error) {
431+
conn, err := connPool.getNextConnection(userMode)
432+
if err != nil {
433+
return tarantool.SQLInfo{}, nil, err
434+
}
435+
436+
return conn.ExecuteTyped(expr, args, result)
437+
}
438+
415439
// SelectAsync sends select request to Tarantool and returns Future.
416440
func (connPool *ConnectionPool) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}, userMode ...Mode) *tarantool.Future {
417441
conn, err := connPool.getConnByMode(ANY, userMode)
@@ -524,6 +548,18 @@ func (connPool *ConnectionPool) EvalAsync(expr string, args interface{}, userMod
524548
return conn.EvalAsync(expr, args)
525549
}
526550

551+
// ExecuteAsync passes an sql expression for execution.
552+
//
553+
// Since 1.7.0
554+
func (connPool *ConnectionPool) ExecuteAsync(expr string, args interface{}, userMode Mode) *tarantool.Future {
555+
conn, err := connPool.getNextConnection(userMode)
556+
if err != nil {
557+
return tarantool.NewErrorFuture(err)
558+
}
559+
560+
return conn.ExecuteAsync(expr, args)
561+
}
562+
527563
// Do sends the request and returns a response.
528564
func (connPool *ConnectionPool) Do(req tarantool.Request, userMode Mode) (*tarantool.Response, error) {
529565
conn, err := connPool.getNextConnection(userMode)

multi/multi.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func (connMulti *ConnectionMulti) Eval(expr string, args interface{}) (resp *tar
349349
return connMulti.getCurrentConnection().Eval(expr, args)
350350
}
351351

352-
// Execute passes sql expression to Tarantool for execution.
352+
// Execute passes a sql expression to Tarantool for execution.
353353
//
354354
// Since 1.6.0
355355
func (connMulti *ConnectionMulti) Execute(expr string, args interface{}) (resp *tarantool.Response, err error) {
@@ -419,6 +419,11 @@ func (connMulti *ConnectionMulti) EvalTyped(expr string, args interface{}, resul
419419
return connMulti.getCurrentConnection().EvalTyped(expr, args, result)
420420
}
421421

422+
// ExecuteTyped passes a sql expression for execution.
423+
func (connMulti *ConnectionMulti) ExecuteTyped(expr string, args interface{}, result interface{}) (tarantool.SQLInfo, []tarantool.ColumnMetaData, error) {
424+
return connMulti.getCurrentConnection().ExecuteTyped(expr, args, result)
425+
}
426+
422427
// SelectAsync sends select request to Tarantool and returns Future.
423428
func (connMulti *ConnectionMulti) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *tarantool.Future {
424429
return connMulti.getCurrentConnection().SelectAsync(space, index, offset, limit, iterator, key)
@@ -482,6 +487,13 @@ func (connMulti *ConnectionMulti) EvalAsync(expr string, args interface{}) *tara
482487
return connMulti.getCurrentConnection().EvalAsync(expr, args)
483488
}
484489

490+
// ExecuteAsync passes an sql expression for execution.
491+
//
492+
// Since 1.7.0
493+
func (connMulti *ConnectionMulti) ExecuteAsync(expr string, args interface{}) *tarantool.Future {
494+
return connMulti.getCurrentConnection().ExecuteAsync(expr, args)
495+
}
496+
485497
// Do sends the request and returns a response.
486498
func (connMulti *ConnectionMulti) Do(req tarantool.Request) (*tarantool.Response, error) {
487499
return connMulti.getCurrentConnection().Do(req)

0 commit comments

Comments
 (0)