Add additional methods to Batch similar to what exists on Queryx
This commit is contained in:
committed by
Sylwia Szunejko
parent
207ba8723e
commit
2eee0b00f1
34
batchx.go
34
batchx.go
@@ -1,6 +1,8 @@
|
||||
package gocqlx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
)
|
||||
|
||||
@@ -27,6 +29,38 @@ func (b *Batch) BindStruct(qry *Queryx, arg interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Bind binds query parameters to values from args.
|
||||
// If value cannot be found an error is reported.
|
||||
func (b *Batch) Bind(qry *Queryx, args ...interface{}) error {
|
||||
if len(qry.Names) != len(args) {
|
||||
return fmt.Errorf("query requires %d arguments, but %d provided", len(qry.Names), len(args))
|
||||
}
|
||||
b.Query(qry.Statement(), args...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// BindMap binds query named parameters to values from arg using a mapper.
|
||||
// If value cannot be found an error is reported.
|
||||
func (b *Batch) BindMap(qry *Queryx, arg map[string]interface{}) error {
|
||||
args, err := qry.bindMapArgs(arg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.Query(qry.Statement(), args...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// BindStructMap binds query named parameters to values from arg0 and arg1 using a mapper.
|
||||
// If value cannot be found an error is reported.
|
||||
func (b *Batch) BindStructMap(qry *Queryx, arg0 interface{}, arg1 map[string]interface{}) error {
|
||||
args, err := qry.bindStructArgs(arg0, arg1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.Query(qry.Statement(), args...)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExecuteBatch executes a batch operation and returns nil if successful
|
||||
// otherwise an error describing the failure.
|
||||
func (s *Session) ExecuteBatch(batch *Batch) error {
|
||||
|
||||
Reference in New Issue
Block a user