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

@@ -10,6 +10,8 @@ package qb
import (
"bytes"
"time"
"github.com/scylladb/gocqlx/v2"
)
// initializer specifies an value for a column in an insert operation.
@@ -78,6 +80,11 @@ func (b *InsertBuilder) ToCql() (stmt string, names []string) {
return
}
// Query returns query built on top of current InsertBuilder state.
func (b *InsertBuilder) Query(session gocqlx.Session) *gocqlx.Queryx {
return session.Query(b.ToCql())
}
// Into sets the INTO clause of the query.
func (b *InsertBuilder) Into(table string) *InsertBuilder {
b.table = table