-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbatch.go
42 lines (35 loc) · 793 Bytes
/
batch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ecql
import "github.com/gocql/gocql"
type Batch interface {
Add(s ...Statement) Batch
Apply() error
ApplyCAS() (bool, error)
}
type BatchImpl struct {
session *SessionImpl
batch *gocql.Batch
}
func NewBatch(sess *SessionImpl, typ gocql.BatchType) Batch {
return &BatchImpl{
session: sess,
batch: sess.NewBatch(typ),
}
}
func (b *BatchImpl) Add(s ...Statement) Batch {
for i := range s {
stmt, args := s[i].BuildQuery()
b.batch.Query(stmt, args...)
}
return b
}
func (b *BatchImpl) Apply() error {
return b.session.ExecuteBatch(b.batch)
}
func (b *BatchImpl) ApplyCAS() (bool, error) {
mapping := make(map[string]interface{})
applied, iter, err := b.session.MapExecuteBatchCAS(b.batch, mapping)
if iter != nil {
iter.Close()
}
return applied, err
}