Documentation ¶
Overview ¶
Package qb provides CQL query builders. The builders create CQL statement and a list of named parameters that can later be bound using github.com/scylladb/gocqlx.
Index ¶
- func TTL(d time.Duration) int64
- func Timestamp(t time.Time) int64
- type BatchBuilder
- func (b *BatchBuilder) Add(builder Builder) *BatchBuilder
- func (b *BatchBuilder) AddStmt(stmt string, names []string) *BatchBuilder
- func (b *BatchBuilder) AddStmtWithPrefix(prefix string, stmt string, names []string) *BatchBuilder
- func (b *BatchBuilder) AddWithPrefix(prefix string, builder Builder) *BatchBuilder
- func (b *BatchBuilder) Counter() *BatchBuilder
- func (b *BatchBuilder) TTL() *BatchBuilder
- func (b *BatchBuilder) Timestamp() *BatchBuilder
- func (b *BatchBuilder) ToCql() (stmt string, names []string)
- func (b *BatchBuilder) UnLogged() *BatchBuilder
- type Builder
- type Cmp
- func Contains(column string) Cmp
- func ContainsNamed(column, name string) Cmp
- func Eq(column string) Cmp
- func EqFunc(column string, fn *Func) Cmp
- func EqNamed(column, name string) Cmp
- func Gt(column string) Cmp
- func GtFunc(column string, fn *Func) Cmp
- func GtNamed(column, name string) Cmp
- func GtOrEq(column string) Cmp
- func GtOrEqFunc(column string, fn *Func) Cmp
- func GtOrEqNamed(column, name string) Cmp
- func In(column string) Cmp
- func InNamed(column, name string) Cmp
- func Lt(column string) Cmp
- func LtFunc(column string, fn *Func) Cmp
- func LtNamed(column, name string) Cmp
- func LtOrEq(column string) Cmp
- func LtOrEqFunc(column string, fn *Func) Cmp
- func LtOrEqNamed(column, name string) Cmp
- type CmpOp
- type DeleteBuilder
- func (b *DeleteBuilder) Columns(columns ...string) *DeleteBuilder
- func (b *DeleteBuilder) Existing() *DeleteBuilder
- func (b *DeleteBuilder) From(table string) *DeleteBuilder
- func (b *DeleteBuilder) If(w ...Cmp) *DeleteBuilder
- func (b *DeleteBuilder) Timestamp() *DeleteBuilder
- func (b *DeleteBuilder) ToCql() (stmt string, names []string)
- func (b *DeleteBuilder) Where(w ...Cmp) *DeleteBuilder
- type Func
- type InsertBuilder
- func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder
- func (b *InsertBuilder) Into(table string) *InsertBuilder
- func (b *InsertBuilder) TTL() *InsertBuilder
- func (b *InsertBuilder) Timestamp() *InsertBuilder
- func (b *InsertBuilder) ToCql() (stmt string, names []string)
- func (b *InsertBuilder) Unique() *InsertBuilder
- type M
- type Order
- type SelectBuilder
- func (b *SelectBuilder) AllowFiltering() *SelectBuilder
- func (b *SelectBuilder) Columns(columns ...string) *SelectBuilder
- func (b *SelectBuilder) Distinct(columns ...string) *SelectBuilder
- func (b *SelectBuilder) From(table string) *SelectBuilder
- func (b *SelectBuilder) GetRestrictionsOnColumn(column string) []Cmp
- func (b *SelectBuilder) GroupBy(columns ...string) *SelectBuilder
- func (b *SelectBuilder) Limit(limit uint) *SelectBuilder
- func (b *SelectBuilder) LimitPerPartition(limit uint) *SelectBuilder
- func (b *SelectBuilder) OrderBy(column string, o Order) *SelectBuilder
- func (b *SelectBuilder) ToCql() (stmt string, names []string)
- func (b *SelectBuilder) Where(w ...Cmp) *SelectBuilder
- type TokenBuilder
- func (t TokenBuilder) Eq() Cmp
- func (t TokenBuilder) EqNamed(names ...string) Cmp
- func (t TokenBuilder) Gt() Cmp
- func (t TokenBuilder) GtNamed(names ...string) Cmp
- func (t TokenBuilder) GtOrEq() Cmp
- func (t TokenBuilder) GtOrEqNamed(names ...string) Cmp
- func (t TokenBuilder) Lt() Cmp
- func (t TokenBuilder) LtNamed(names ...string) Cmp
- func (t TokenBuilder) LtOrEq() Cmp
- func (t TokenBuilder) LtOrEqNamed(names ...string) Cmp
- type UpdateBuilder
- func (b *UpdateBuilder) Add(column string) *UpdateBuilder
- func (b *UpdateBuilder) AddNamed(column, name string) *UpdateBuilder
- func (b *UpdateBuilder) Existing() *UpdateBuilder
- func (b *UpdateBuilder) If(w ...Cmp) *UpdateBuilder
- func (b *UpdateBuilder) Remove(column string) *UpdateBuilder
- func (b *UpdateBuilder) RemoveNamed(column, name string) *UpdateBuilder
- func (b *UpdateBuilder) Set(columns ...string) *UpdateBuilder
- func (b *UpdateBuilder) SetFunc(column string, fn *Func) *UpdateBuilder
- func (b *UpdateBuilder) TTL() *UpdateBuilder
- func (b *UpdateBuilder) Table(table string) *UpdateBuilder
- func (b *UpdateBuilder) Timestamp() *UpdateBuilder
- func (b *UpdateBuilder) ToCql() (stmt string, names []string)
- func (b *UpdateBuilder) Where(w ...Cmp) *UpdateBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BatchBuilder ¶
type BatchBuilder struct {
// contains filtered or unexported fields
}
BatchBuilder builds CQL BATCH statements.
func (*BatchBuilder) Add ¶
func (b *BatchBuilder) Add(builder Builder) *BatchBuilder
Add builds the builder and adds the statement to the batch.
func (*BatchBuilder) AddStmt ¶
func (b *BatchBuilder) AddStmt(stmt string, names []string) *BatchBuilder
AddStmt adds statement to the batch.
func (*BatchBuilder) AddStmtWithPrefix ¶
func (b *BatchBuilder) AddStmtWithPrefix(prefix string, stmt string, names []string) *BatchBuilder
AddStmtWithPrefix adds statement to the batch. Names are prefixed with the prefix + ".".
func (*BatchBuilder) AddWithPrefix ¶
func (b *BatchBuilder) AddWithPrefix(prefix string, builder Builder) *BatchBuilder
AddWithPrefix builds the builder and adds the statement to the batch. Names are prefixed with the prefix + ".".
func (*BatchBuilder) Counter ¶
func (b *BatchBuilder) Counter() *BatchBuilder
Counter sets a COUNTER BATCH clause on the query.
func (*BatchBuilder) TTL ¶
func (b *BatchBuilder) TTL() *BatchBuilder
TTL sets a USING TTL clause on the query.
func (*BatchBuilder) Timestamp ¶
func (b *BatchBuilder) Timestamp() *BatchBuilder
Timestamp sets a USING TIMESTAMP clause on the query.
func (*BatchBuilder) ToCql ¶
func (b *BatchBuilder) ToCql() (stmt string, names []string)
ToCql builds the query into a CQL string and named args.
func (*BatchBuilder) UnLogged ¶
func (b *BatchBuilder) UnLogged() *BatchBuilder
UnLogged sets a UNLOGGED BATCH clause on the query.
type Builder ¶
type Builder interface { // ToCql builds the query into a CQL string and named args. ToCql() (stmt string, names []string) }
Builder is interface implemented by all the builders.
type Cmp ¶
type Cmp struct {
// contains filtered or unexported fields
}
Cmp if a filtering comparator that is used in WHERE and IF clauses.
func ContainsNamed ¶
ContainsNamed produces column CONTAINS ? with a custom parameter name.
func GtOrEqFunc ¶
GtOrEqFunc produces column>=someFunc(?...).
func GtOrEqNamed ¶
GtOrEqNamed produces column>=? with a custom parameter name.
func LtOrEqFunc ¶
LtOrEqFunc produces column<=someFunc(?...).
func LtOrEqNamed ¶
LtOrEqNamed produces column<=? with a custom parameter name.
type CmpOp ¶
type CmpOp byte
CmpOp specifies Cmd operation type. It's a copied version of the private op type below.
type DeleteBuilder ¶
type DeleteBuilder struct {
// contains filtered or unexported fields
}
DeleteBuilder builds CQL DELETE statements.
func Delete ¶
func Delete(table string) *DeleteBuilder
Delete returns a new DeleteBuilder with the given table name.
func (*DeleteBuilder) Columns ¶
func (b *DeleteBuilder) Columns(columns ...string) *DeleteBuilder
Columns adds delete columns to the query.
func (*DeleteBuilder) Existing ¶
func (b *DeleteBuilder) Existing() *DeleteBuilder
Existing sets a IF EXISTS clause on the query.
func (*DeleteBuilder) From ¶
func (b *DeleteBuilder) From(table string) *DeleteBuilder
From sets the table to be deleted from.
func (*DeleteBuilder) If ¶
func (b *DeleteBuilder) If(w ...Cmp) *DeleteBuilder
If adds an expression to the IF clause of the query. Expressions are ANDed together in the generated CQL.
func (*DeleteBuilder) Timestamp ¶
func (b *DeleteBuilder) Timestamp() *DeleteBuilder
Timestamp sets a USING TIMESTAMP clause on the query.
func (*DeleteBuilder) ToCql ¶
func (b *DeleteBuilder) ToCql() (stmt string, names []string)
ToCql builds the query into a CQL string and named args.
func (*DeleteBuilder) Where ¶
func (b *DeleteBuilder) Where(w ...Cmp) *DeleteBuilder
Where adds an expression to the WHERE clause of the query. Expressions are ANDed together in the generated CQL.
type Func ¶
type Func struct { // function name Name string Value string // name of the function parameters ParamNames []string }
Func is a custom database function invocation that can be use in a comparator or update statement.
type InsertBuilder ¶
type InsertBuilder struct {
// contains filtered or unexported fields
}
InsertBuilder builds CQL INSERT statements.
func Insert ¶
func Insert(table string) *InsertBuilder
Insert returns a new InsertBuilder with the given table name.
func (*InsertBuilder) Columns ¶
func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder
Columns adds insert columns to the query.
func (*InsertBuilder) Into ¶
func (b *InsertBuilder) Into(table string) *InsertBuilder
Into sets the INTO clause of the query.
func (*InsertBuilder) TTL ¶
func (b *InsertBuilder) TTL() *InsertBuilder
TTL sets a USING TTL clause on the query.
func (*InsertBuilder) Timestamp ¶
func (b *InsertBuilder) Timestamp() *InsertBuilder
Timestamp sets a USING TIMESTAMP clause on the query.
func (*InsertBuilder) ToCql ¶
func (b *InsertBuilder) ToCql() (stmt string, names []string)
ToCql builds the query into a CQL string and named args.
func (*InsertBuilder) Unique ¶
func (b *InsertBuilder) Unique() *InsertBuilder
Unique sets a IF NOT EXISTS clause on the query.
type SelectBuilder ¶
type SelectBuilder struct {
// contains filtered or unexported fields
}
SelectBuilder builds CQL SELECT statements.
func Select ¶
func Select(table string) *SelectBuilder
Select returns a new SelectBuilder with the given table name.
func (*SelectBuilder) AllowFiltering ¶
func (b *SelectBuilder) AllowFiltering() *SelectBuilder
AllowFiltering sets a ALLOW FILTERING clause on the query.
func (*SelectBuilder) Columns ¶
func (b *SelectBuilder) Columns(columns ...string) *SelectBuilder
Columns adds result columns to the query.
func (*SelectBuilder) Distinct ¶
func (b *SelectBuilder) Distinct(columns ...string) *SelectBuilder
Distinct sets DISTINCT clause on the query.
func (*SelectBuilder) From ¶
func (b *SelectBuilder) From(table string) *SelectBuilder
From sets the table to be selected from.
func (*SelectBuilder) GetRestrictionsOnColumn ¶
func (b *SelectBuilder) GetRestrictionsOnColumn(column string) []Cmp
GetRestrictionsOnColumn returns a list of Cmp objects on a specific column.
func (*SelectBuilder) GroupBy ¶
func (b *SelectBuilder) GroupBy(columns ...string) *SelectBuilder
GroupBy sets GROUP BY clause on the query. Columns must be a primary key, this will automatically add the the columns as first selectors.
func (*SelectBuilder) Limit ¶
func (b *SelectBuilder) Limit(limit uint) *SelectBuilder
Limit sets a LIMIT clause on the query.
func (*SelectBuilder) LimitPerPartition ¶
func (b *SelectBuilder) LimitPerPartition(limit uint) *SelectBuilder
LimitPerPartition sets a PER PARTITION LIMIT clause on the query.
func (*SelectBuilder) OrderBy ¶
func (b *SelectBuilder) OrderBy(column string, o Order) *SelectBuilder
OrderBy sets ORDER BY clause on the query.
func (*SelectBuilder) ToCql ¶
func (b *SelectBuilder) ToCql() (stmt string, names []string)
ToCql builds the query into a CQL string and named args.
func (*SelectBuilder) Where ¶
func (b *SelectBuilder) Where(w ...Cmp) *SelectBuilder
Where adds an expression to the WHERE clause of the query. Expressions are ANDed together in the generated CQL.
type TokenBuilder ¶
type TokenBuilder []string
TokenBuilder helps implement pagination using token function.
func (TokenBuilder) EqNamed ¶
func (t TokenBuilder) EqNamed(names ...string) Cmp
EqNamed produces token(column)=token(?) with a custom parameter name.
func (TokenBuilder) GtNamed ¶
func (t TokenBuilder) GtNamed(names ...string) Cmp
GtNamed produces token(column)>token(?) with a custom parameter name.
func (TokenBuilder) GtOrEq ¶
func (t TokenBuilder) GtOrEq() Cmp
GtOrEq produces token(column)>=token(?).
func (TokenBuilder) GtOrEqNamed ¶
func (t TokenBuilder) GtOrEqNamed(names ...string) Cmp
GtOrEqNamed produces token(column)>=token(?) with a custom parameter name.
func (TokenBuilder) LtNamed ¶
func (t TokenBuilder) LtNamed(names ...string) Cmp
LtNamed produces token(column)<token(?) with a custom parameter name.
func (TokenBuilder) LtOrEq ¶
func (t TokenBuilder) LtOrEq() Cmp
LtOrEq produces token(column)<=token(?).
func (TokenBuilder) LtOrEqNamed ¶
func (t TokenBuilder) LtOrEqNamed(names ...string) Cmp
LtOrEqNamed produces token(column)<=token(?) with a custom parameter name.
type UpdateBuilder ¶
type UpdateBuilder struct {
// contains filtered or unexported fields
}
UpdateBuilder builds CQL UPDATE statements.
func Update ¶
func Update(table string) *UpdateBuilder
Update returns a new UpdateBuilder with the given table name.
func (*UpdateBuilder) Add ¶
func (b *UpdateBuilder) Add(column string) *UpdateBuilder
Add adds SET column=column+? clauses to the query.
func (*UpdateBuilder) AddNamed ¶
func (b *UpdateBuilder) AddNamed(column, name string) *UpdateBuilder
AddNamed adds SET column=column+? clauses to the query with a custom parameter name.
func (*UpdateBuilder) Existing ¶
func (b *UpdateBuilder) Existing() *UpdateBuilder
Existing sets a IF EXISTS clause on the query.
func (*UpdateBuilder) If ¶
func (b *UpdateBuilder) If(w ...Cmp) *UpdateBuilder
If adds an expression to the IF clause of the query. Expressions are ANDed together in the generated CQL.
func (*UpdateBuilder) Remove ¶
func (b *UpdateBuilder) Remove(column string) *UpdateBuilder
Remove adds SET column=column-? clauses to the query.
func (*UpdateBuilder) RemoveNamed ¶
func (b *UpdateBuilder) RemoveNamed(column, name string) *UpdateBuilder
RemoveNamed adds SET column=column-? clauses to the query with a custom parameter name.
func (*UpdateBuilder) Set ¶
func (b *UpdateBuilder) Set(columns ...string) *UpdateBuilder
Set adds SET clauses to the query.
func (*UpdateBuilder) SetFunc ¶
func (b *UpdateBuilder) SetFunc(column string, fn *Func) *UpdateBuilder
SetFunc adds SET column=someFunc(?...) clause to the query.
func (*UpdateBuilder) TTL ¶
func (b *UpdateBuilder) TTL() *UpdateBuilder
TTL sets a USING TTL clause on the query.
func (*UpdateBuilder) Table ¶
func (b *UpdateBuilder) Table(table string) *UpdateBuilder
Table sets the table to be updated.
func (*UpdateBuilder) Timestamp ¶
func (b *UpdateBuilder) Timestamp() *UpdateBuilder
Timestamp sets a USING TIMESTAMP clause on the query.
func (*UpdateBuilder) ToCql ¶
func (b *UpdateBuilder) ToCql() (stmt string, names []string)
ToCql builds the query into a CQL string and named args.
func (*UpdateBuilder) Where ¶
func (b *UpdateBuilder) Where(w ...Cmp) *UpdateBuilder
Where adds an expression to the WHERE clause of the query. Expressions are ANDed together in the generated CQL.