-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcql12.go
More file actions
45 lines (36 loc) · 863 Bytes
/
cql12.go
File metadata and controls
45 lines (36 loc) · 863 Bytes
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
43
44
45
package batchbuilder
import (
"fmt"
"github.com/gocql/gocql"
)
type CqlBatch interface {
Batch
Apply(session *gocql.Session) (err error)
}
type Cql12Batch struct {
BasicBatch
timestamp *int64 // pointer so it can be nil since 0 is a valid ts
}
func NewCql12Batch() CqlBatch {
return &Cql12Batch{}
}
func (self *Cql12Batch) UsingTimestamp(ts int64) *Cql12Batch {
self.timestamp = &ts
return self
}
func (self *Cql12Batch) Apply(session *gocql.Session) (err error) {
var (
batchQuery string
batchArgs []interface{}
)
beginStatement := "BEGIN BATCH"
if self.timestamp != nil {
beginStatement = fmt.Sprintf("%s USING TIMESTAMP %d", beginStatement, *self.timestamp)
}
batchQuery, batchArgs, err = self.Join("\n", beginStatement, "APPLY BATCH")
if err != nil {
return
}
err = session.Query(batchQuery, batchArgs...).Exec()
return
}