qb: batch add ability to add raw statements

This commit is contained in:
Michał Matczuk
2017-11-16 13:04:55 +01:00
parent cbe2659e0d
commit cdb91625bf

View File

@@ -59,20 +59,28 @@ func (b *BatchBuilder) ToCql() (stmt string, names []string) {
return return
} }
// Add adds another statement to the batch. // Add builds the builder and adds the statement to the batch.
func (b *BatchBuilder) Add(builder Builder) *BatchBuilder { func (b *BatchBuilder) Add(builder Builder) *BatchBuilder {
stmt, names := builder.ToCql() return b.AddStmt(builder.ToCql())
}
// AddStmt adds statement to the batch.
func (b *BatchBuilder) AddStmt(stmt string, names []string) *BatchBuilder {
b.stmts = append(b.stmts, stmt) b.stmts = append(b.stmts, stmt)
b.names = append(b.names, names...) b.names = append(b.names, names...)
return b return b
} }
// AddWithPrefix adds another statement to the batch. Names returned by the // AddWithPrefix builds the builder and adds the statement to the batch. Names
// builder are prefixed with the prefix + ".". // are prefixed with the prefix + ".".
func (b *BatchBuilder) AddWithPrefix(prefix string, builder Builder) *BatchBuilder { func (b *BatchBuilder) AddWithPrefix(prefix string, builder Builder) *BatchBuilder {
stmt, names := builder.ToCql() stmt, names := builder.ToCql()
return b.AddStmtWithPrefix(prefix, stmt, names)
}
// AddStmtWithPrefix adds statement to the batch. Names are prefixed with
// the prefix + ".".
func (b *BatchBuilder) AddStmtWithPrefix(prefix string, stmt string, names []string) *BatchBuilder {
b.stmts = append(b.stmts, stmt) b.stmts = append(b.stmts, stmt)
for _, name := range names { for _, name := range names {
if prefix != "" { if prefix != "" {