qb: Added shortcuts to Queryx

It allows to write shorter and more straightforward code.
Instead writing:

```
session.Query(qb.Select("cluster").Columns("id").ToCql())
```

you can write:

```
qb.Select("cluster").Columns("id").Query(session)
```
This commit is contained in:
Maciej Zimnoch
2020-06-17 16:36:24 +02:00
committed by Michal Jan Matczuk
parent 564db08698
commit 4f4f94e2e6
5 changed files with 35 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ import (
"bytes"
"fmt"
"time"
"github.com/scylladb/gocqlx/v2"
)
// BATCH reference:
@@ -64,6 +66,11 @@ func (b *BatchBuilder) ToCql() (stmt string, names []string) {
return
}
// Query returns query built on top of current BatchBuilder state.
func (b *BatchBuilder) Query(session gocqlx.Session) *gocqlx.Queryx {
return session.Query(b.ToCql())
}
// Add builds the builder and adds the statement to the batch.
func (b *BatchBuilder) Add(builder Builder) *BatchBuilder {
return b.AddStmt(builder.ToCql())