From cdb91625bf409ec44230031071349a3564421bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Thu, 16 Nov 2017 13:04:55 +0100 Subject: [PATCH] qb: batch add ability to add raw statements --- qb/batch.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/qb/batch.go b/qb/batch.go index 9defdbc..3091bfe 100644 --- a/qb/batch.go +++ b/qb/batch.go @@ -59,20 +59,28 @@ func (b *BatchBuilder) ToCql() (stmt string, names []string) { 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 { - 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.names = append(b.names, names...) return b } -// AddWithPrefix adds another statement to the batch. Names returned by the -// builder are prefixed with the prefix + ".". +// AddWithPrefix builds the builder and adds the statement to the batch. Names +// are prefixed with the prefix + ".". func (b *BatchBuilder) AddWithPrefix(prefix string, builder Builder) *BatchBuilder { 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) for _, name := range names { if prefix != "" {