Added Context variants of Query functions

This commit is contained in:
Maciej Zimnoch
2020-06-18 10:42:02 +02:00
committed by Michal Jan Matczuk
parent 8af6506cde
commit 4ea6f42a51
6 changed files with 57 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ package qb
import (
"bytes"
"context"
"fmt"
"time"
@@ -71,6 +72,11 @@ func (b *BatchBuilder) Query(session gocqlx.Session) *gocqlx.Queryx {
return session.Query(b.ToCql())
}
// QueryContext returns query wrapped with context built on top of current BatchBuilder state.
func (b *BatchBuilder) QueryContext(ctx context.Context, session gocqlx.Session) *gocqlx.Queryx {
return b.Query(session).WithContext(ctx)
}
// Add builds the builder and adds the statement to the batch.
func (b *BatchBuilder) Add(builder Builder) *BatchBuilder {
return b.AddStmt(builder.ToCql())

View File

@@ -9,6 +9,7 @@ package qb
import (
"bytes"
"context"
"time"
"github.com/scylladb/gocqlx/v2"
@@ -61,6 +62,11 @@ func (b *DeleteBuilder) Query(session gocqlx.Session) *gocqlx.Queryx {
return session.Query(b.ToCql())
}
// QueryContext returns query wrapped with context built on top of current DeleteBuilder state.
func (b *DeleteBuilder) QueryContext(ctx context.Context, session gocqlx.Session) *gocqlx.Queryx {
return b.Query(session).WithContext(ctx)
}
// From sets the table to be deleted from.
func (b *DeleteBuilder) From(table string) *DeleteBuilder {
b.table = table

View File

@@ -9,6 +9,7 @@ package qb
import (
"bytes"
"context"
"time"
"github.com/scylladb/gocqlx/v2"
@@ -85,6 +86,11 @@ func (b *InsertBuilder) Query(session gocqlx.Session) *gocqlx.Queryx {
return session.Query(b.ToCql())
}
// QueryContext returns query wrapped with context built on top of current InsertBuilder state.
func (b *InsertBuilder) QueryContext(ctx context.Context, session gocqlx.Session) *gocqlx.Queryx {
return b.Query(session).WithContext(ctx)
}
// Into sets the INTO clause of the query.
func (b *InsertBuilder) Into(table string) *InsertBuilder {
b.table = table

View File

@@ -9,6 +9,7 @@ package qb
import (
"bytes"
"context"
"fmt"
"github.com/scylladb/gocqlx/v2"
@@ -125,6 +126,11 @@ func (b *SelectBuilder) Query(session gocqlx.Session) *gocqlx.Queryx {
return session.Query(b.ToCql())
}
// QueryContext returns query wrapped with context built on top of current SelectBuilder state.
func (b *SelectBuilder) QueryContext(ctx context.Context, session gocqlx.Session) *gocqlx.Queryx {
return b.Query(session).WithContext(ctx)
}
// From sets the table to be selected from.
func (b *SelectBuilder) From(table string) *SelectBuilder {
b.table = table

View File

@@ -9,6 +9,7 @@ package qb
import (
"bytes"
"context"
"time"
"github.com/scylladb/gocqlx/v2"
@@ -80,6 +81,11 @@ func (b *UpdateBuilder) Query(session gocqlx.Session) *gocqlx.Queryx {
return session.Query(b.ToCql())
}
// QueryContext returns query wrapped with context built on top of current UpdateBuilder state.
func (b *UpdateBuilder) QueryContext(ctx context.Context, session gocqlx.Session) *gocqlx.Queryx {
return b.Query(session).WithContext(ctx)
}
// Table sets the table to be updated.
func (b *UpdateBuilder) Table(table string) *UpdateBuilder {
b.table = table