batch: extracted AddWithPrefix
This commit is contained in:
35
qb/batch.go
35
qb/batch.go
@@ -55,6 +55,30 @@ func (b *BatchBuilder) ToCql() (stmt string, names []string) {
|
||||
return
|
||||
}
|
||||
|
||||
// Add adds another statement to the batch.
|
||||
func (b *BatchBuilder) Add(builder Builder) *BatchBuilder {
|
||||
stmt, names := builder.ToCql()
|
||||
|
||||
b.stmts = append(b.stmts, stmt)
|
||||
b.names = append(b.names, names...)
|
||||
return b
|
||||
}
|
||||
|
||||
// AddWithPrefix adds another statement to the batch. Names returned by the
|
||||
// builder are prefixed with the prefix + ".".
|
||||
func (b *BatchBuilder) AddWithPrefix(prefix string, builder Builder) *BatchBuilder {
|
||||
stmt, names := builder.ToCql()
|
||||
|
||||
b.stmts = append(b.stmts, stmt)
|
||||
for _, name := range names {
|
||||
if prefix != "" {
|
||||
name = fmt.Sprint(prefix, ".", name)
|
||||
}
|
||||
b.names = append(b.names, name)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// UnLogged sets a UNLOGGED BATCH clause on the query.
|
||||
func (b *BatchBuilder) UnLogged() *BatchBuilder {
|
||||
b.unlogged = true
|
||||
@@ -78,14 +102,3 @@ func (b *BatchBuilder) TTL() *BatchBuilder {
|
||||
b.using.ttl = true
|
||||
return b
|
||||
}
|
||||
|
||||
// Add adds another batch statement from a builder.
|
||||
func (b *BatchBuilder) Add(prefix string, builder Builder) *BatchBuilder {
|
||||
stmt, names := builder.ToCql()
|
||||
|
||||
b.stmts = append(b.stmts, stmt)
|
||||
for _, name := range names {
|
||||
b.names = append(b.names, fmt.Sprint(prefix, name))
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user