qb

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2020 License: Apache-2.0 Imports: 5 Imported by: 56

README

GoCQLX Query Builder

Package qb provides CQL query builders. The builders create CQL statement and a list of named parameters that can later be bound using gocqlx.

The following CQL commands are supported: SELECT, INSERT, UPDATE, DELETE and BATCH.

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 gocqlx.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(column, name string) string

As is a helper for adding a column AS name result column to the query.

func TTL

func TTL(d time.Duration) int64

TTL converts duration to format expected in USING TTL clause.

func Timestamp

func Timestamp(t time.Time) int64

Timestamp converts time to format expected in USING TIMESTAMP clause.

Types

type BatchBuilder

type BatchBuilder struct {
	// contains filtered or unexported fields
}

BatchBuilder builds CQL BATCH statements.

func Batch

func Batch() *BatchBuilder

Batch returns a new BatchBuilder.

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, 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

TTL adds USING TTL clause to the query.

func (*BatchBuilder) TTLNamed

func (b *BatchBuilder) TTLNamed(name string) *BatchBuilder

TTLNamed adds USING TTL clause to the query with a custom parameter name.

func (*BatchBuilder) Timestamp

func (b *BatchBuilder) Timestamp(t time.Time) *BatchBuilder

Timestamp adds USING TIMESTAMP clause to the query.

func (*BatchBuilder) TimestampNamed

func (b *BatchBuilder) TimestampNamed(name string) *BatchBuilder

TimestampNamed adds a USING TIMESTAMP clause to the query with a custom parameter name.

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 Contains

func Contains(column string) Cmp

Contains produces column CONTAINS ?.

func ContainsKey added in v1.1.0

func ContainsKey(column string) Cmp

ContainsKey produces column CONTAINS KEY ?.

func ContainsKeyNamed added in v1.1.0

func ContainsKeyNamed(column, name string) Cmp

ContainsKeyNamed produces column CONTAINS KEY ? with a custom parameter name.

func ContainsKeyTuple added in v1.3.0

func ContainsKeyTuple(column string, count int) Cmp

ContainsKeyTuple produces column CONTAINS KEY (?,?,...) with count placehplders.

func ContainsLit

func ContainsLit(column, literal string) Cmp

ContainsLit produces column CONTAINS literal and does not add a parameter to the query.

func ContainsNamed

func ContainsNamed(column, name string) Cmp

ContainsNamed produces column CONTAINS ? with a custom parameter name.

func ContainsTuple added in v1.3.0

func ContainsTuple(column string, count int) Cmp

ContainsTuple produces column CONTAINS (?,?,...) with count placeholders.

func Eq

func Eq(column string) Cmp

Eq produces column=?.

func EqFunc

func EqFunc(column string, fn *Func) Cmp

EqFunc produces column=someFunc(?...).

func EqLit

func EqLit(column, literal string) Cmp

EqLit produces column=literal and does not add a parameter to the query.

func EqNamed

func EqNamed(column, name string) Cmp

EqNamed produces column=? with a custom parameter name.

func EqTuple added in v1.3.0

func EqTuple(column string, count int) Cmp

EqTuple produces column=(?,?,...) with count number of placeholders.

func Gt

func Gt(column string) Cmp

Gt produces column>?.

func GtFunc

func GtFunc(column string, fn *Func) Cmp

GtFunc produces column>someFunc(?...).

func GtLit

func GtLit(column, literal string) Cmp

GtLit produces column>literal and does not add a parameter to the query.

func GtNamed

func GtNamed(column, name string) Cmp

GtNamed produces column>? with a custom parameter name.

func GtOrEq

func GtOrEq(column string) Cmp

GtOrEq produces column>=?.

func GtOrEqFunc

func GtOrEqFunc(column string, fn *Func) Cmp

GtOrEqFunc produces column>=someFunc(?...).

func GtOrEqLit

func GtOrEqLit(column, literal string) Cmp

GtOrEqLit produces column>=literal and does not add a parameter to the query.

func GtOrEqNamed

func GtOrEqNamed(column, name string) Cmp

GtOrEqNamed produces column>=? with a custom parameter name.

func GtOrEqTuple added in v1.3.0

func GtOrEqTuple(column string, count int) Cmp

GtOrEqTuple produces column>=(?,?,...) with count placeholders.

func GtTuple added in v1.3.0

func GtTuple(column string, count int) Cmp

GtTuple produces column>(?,?,...) with count placeholders.

func In

func In(column string) Cmp

In produces column IN ?.

func InLit

func InLit(column, literal string) Cmp

InLit produces column IN literal and does not add a parameter to the query.

func InNamed

func InNamed(column, name string) Cmp

InNamed produces column IN ? with a custom parameter name.

func InTuple added in v1.3.0

func InTuple(column string, count int) Cmp

InTuple produces column IN ?.

func Like added in v1.2.0

func Like(column string) Cmp

Like produces column LIKE ?.

func LikeTuple added in v1.3.0

func LikeTuple(column string, count int) Cmp

LikeTuple produces column LIKE (?,?,...) with count placeholders.

func Lt

func Lt(column string) Cmp

Lt produces column<?.

func LtFunc

func LtFunc(column string, fn *Func) Cmp

LtFunc produces column<someFunc(?...).

func LtLit

func LtLit(column, literal string) Cmp

LtLit produces column<literal and does not add a parameter to the query.

func LtNamed

func LtNamed(column, name string) Cmp

LtNamed produces column<? with a custom parameter name.

func LtOrEq

func LtOrEq(column string) Cmp

LtOrEq produces column<=?.

func LtOrEqFunc

func LtOrEqFunc(column string, fn *Func) Cmp

LtOrEqFunc produces column<=someFunc(?...).

func LtOrEqLit

func LtOrEqLit(column, literal string) Cmp

LtOrEqLit produces column<=literal and does not add a parameter to the query.

func LtOrEqNamed

func LtOrEqNamed(column, name string) Cmp

LtOrEqNamed produces column<=? with a custom parameter name.

func LtOrEqTuple added in v1.3.0

func LtOrEqTuple(column string, count int) Cmp

LtOrEqTuple produces column<=(?,?,...) with count placeholders.

func LtTuple added in v1.3.0

func LtTuple(column string, count int) Cmp

LtTuple produces column<(?,?,...) with count placeholders.

func Ne added in v1.3.2

func Ne(column string) Cmp

Ne produces column!=?.

func NeFunc added in v1.3.2

func NeFunc(column string, fn *Func) Cmp

NeFunc produces column!=someFunc(?...).

func NeLit added in v1.3.2

func NeLit(column, literal string) Cmp

NeLit produces column!=literal and does not add a parameter to the query.

func NeNamed added in v1.3.2

func NeNamed(column, name string) Cmp

NeNamed produces column!=? with a custom parameter name.

func NeTuple added in v1.3.2

func NeTuple(column string, count int) Cmp

NeTuple produces column!=(?,?,...) with count number of placeholders.

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(t time.Time) *DeleteBuilder

Timestamp adds USING TIMESTAMP clause to the query.

func (*DeleteBuilder) TimestampNamed

func (b *DeleteBuilder) TimestampNamed(name string) *DeleteBuilder

TimestampNamed adds a USING TIMESTAMP clause to the query with a custom parameter name.

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
	// name of the function parameters
	ParamNames []string
}

Func is a custom database function invocation that can be use in a comparator or update statement.

func Fn

func Fn(name string, paramNames ...string) *Func

Fn creates Func.

func MaxTimeuuid

func MaxTimeuuid(name string) *Func

MaxTimeuuid produces maxTimeuuid(?).

func MinTimeuuid

func MinTimeuuid(name string) *Func

MinTimeuuid produces minTimeuuid(?).

func Now

func Now() *Func

Now produces now().

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) FuncColumn

func (b *InsertBuilder) FuncColumn(column string, fn *Func) *InsertBuilder

FuncColumn adds an insert column initialized by evaluating a CQL function.

func (*InsertBuilder) Into

func (b *InsertBuilder) Into(table string) *InsertBuilder

Into sets the INTO clause of the query.

func (*InsertBuilder) Json added in v1.3.0

func (b *InsertBuilder) Json() *InsertBuilder

Json sets the Json clause of the query.

func (*InsertBuilder) LitColumn

func (b *InsertBuilder) LitColumn(column, literal string) *InsertBuilder

LitColumn adds an insert column with a literal value to the query.

func (*InsertBuilder) NamedColumn

func (b *InsertBuilder) NamedColumn(column, name string) *InsertBuilder

NamedColumn adds an insert column with a custom parameter name.

func (*InsertBuilder) TTL

TTL adds USING TTL clause to the query.

func (*InsertBuilder) TTLNamed

func (b *InsertBuilder) TTLNamed(name string) *InsertBuilder

TTLNamed adds USING TTL clause to the query with a custom parameter name.

func (*InsertBuilder) Timestamp

func (b *InsertBuilder) Timestamp(t time.Time) *InsertBuilder

Timestamp adds USING TIMESTAMP clause to the query.

func (*InsertBuilder) TimestampNamed

func (b *InsertBuilder) TimestampNamed(name string) *InsertBuilder

TimestampNamed adds a USING TIMESTAMP clause to the query with a custom parameter name.

func (*InsertBuilder) ToCql

func (b *InsertBuilder) ToCql() (stmt string, names []string)

ToCql builds the query into a CQL string and named args.

func (*InsertBuilder) TupleColumn added in v1.3.0

func (b *InsertBuilder) TupleColumn(column string, count int) *InsertBuilder

TupleColumn adds an insert column for a tuple value to the query.

func (*InsertBuilder) Unique

func (b *InsertBuilder) Unique() *InsertBuilder

Unique sets a IF NOT EXISTS clause on the query.

type M

type M map[string]interface{}

M is a map.

type Order

type Order bool

Order specifies sorting order.

const (
	// ASC is ascending order
	ASC Order = true
	// DESC is descending order
	DESC = false
)

func (Order) String added in v1.1.0

func (o Order) String() string

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) Avg

func (b *SelectBuilder) Avg(column string) *SelectBuilder

Avg produces 'avg(column)' aggregation function.

func (*SelectBuilder) BypassCache added in v1.3.2

func (b *SelectBuilder) BypassCache() *SelectBuilder

BypassCache sets a BYPASS CACHE clause on the query.

BYPASS CACHE is a feature specific to ScyllaDB. See https://docs.scylladb.com/getting-started/dml/#bypass-cache

func (*SelectBuilder) Columns

func (b *SelectBuilder) Columns(columns ...string) *SelectBuilder

Columns adds result columns to the query.

func (*SelectBuilder) Count

func (b *SelectBuilder) Count(column string) *SelectBuilder

Count produces 'count(column)'.

func (*SelectBuilder) CountAll

func (b *SelectBuilder) CountAll() *SelectBuilder

CountAll produces 'count(*)'.

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) 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) Json added in v1.3.0

func (b *SelectBuilder) Json() *SelectBuilder

Json sets the clause of the query.

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) Max

func (b *SelectBuilder) Max(column string) *SelectBuilder

Max produces 'max(column)' aggregation function.

func (*SelectBuilder) Min

func (b *SelectBuilder) Min(column string) *SelectBuilder

Min produces 'min(column)' aggregation function.

func (*SelectBuilder) OrderBy

func (b *SelectBuilder) OrderBy(column string, o Order) *SelectBuilder

OrderBy sets ORDER BY clause on the query.

func (*SelectBuilder) Sum

func (b *SelectBuilder) Sum(column string) *SelectBuilder

Sum produces 'sum(column)' aggregation function.

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 Token

func Token(columns ...string) TokenBuilder

Token creates a new TokenBuilder.

func (TokenBuilder) Eq

func (t TokenBuilder) Eq() Cmp

Eq produces token(column)=token(?).

func (TokenBuilder) EqNamed

func (t TokenBuilder) EqNamed(names ...string) Cmp

EqNamed produces token(column)=token(?) with a custom parameter name.

func (TokenBuilder) EqValue added in v1.3.2

func (t TokenBuilder) EqValue() Cmp

EqValue produces token(column)=?

func (TokenBuilder) EqValueNamed added in v1.3.2

func (t TokenBuilder) EqValueNamed(name string) Cmp

EqValueNamed produces token(column)=? with a custom parameter name.

func (TokenBuilder) Gt

func (t TokenBuilder) Gt() Cmp

Gt produces token(column)>token(?).

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) GtOrEqValue added in v1.3.2

func (t TokenBuilder) GtOrEqValue() Cmp

GtOrEqValue produces token(column)>=?.

func (TokenBuilder) GtOrEqValueNamed added in v1.3.2

func (t TokenBuilder) GtOrEqValueNamed(name string) Cmp

GtOrEqValueNamed produces token(column)>=? with a custom parameter name.

func (TokenBuilder) GtValue added in v1.3.2

func (t TokenBuilder) GtValue() Cmp

GtValue produces token(column)>?.

func (TokenBuilder) GtValueNamed added in v1.3.2

func (t TokenBuilder) GtValueNamed(name string) Cmp

GtValueNamed produces token(column)>? with a custom parameter name.

func (TokenBuilder) Lt

func (t TokenBuilder) Lt() Cmp

Lt produces token(column)<token(?).

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.

func (TokenBuilder) LtOrEqValue added in v1.3.2

func (t TokenBuilder) LtOrEqValue() Cmp

LtOrEqValue produces token(column)<=?.

func (TokenBuilder) LtOrEqValueNamed added in v1.3.2

func (t TokenBuilder) LtOrEqValueNamed(name string) Cmp

LtOrEqValueNamed produces token(column)<=? with a custom parameter name.

func (TokenBuilder) LtValue added in v1.3.2

func (t TokenBuilder) LtValue() Cmp

LtValue produces token(column)<?.

func (TokenBuilder) LtValueNamed added in v1.3.2

func (t TokenBuilder) LtValueNamed(name string) Cmp

LtValueNamed produces token(column)<? 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) AddFunc

func (b *UpdateBuilder) AddFunc(column string, fn *Func) *UpdateBuilder

AddFunc adds SET column=column+someFunc(?...) clauses to the query.

func (*UpdateBuilder) AddLit

func (b *UpdateBuilder) AddLit(column, literal string) *UpdateBuilder

AddLit adds SET column=column+literal 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) RemoveFunc

func (b *UpdateBuilder) RemoveFunc(column string, fn *Func) *UpdateBuilder

RemoveFunc adds SET column=column-someFunc(?...) clauses to the query.

func (*UpdateBuilder) RemoveLit

func (b *UpdateBuilder) RemoveLit(column, literal string) *UpdateBuilder

RemoveLit adds SET column=column-literal 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. To set a tuple column use SetTuple instead.

func (*UpdateBuilder) SetFunc

func (b *UpdateBuilder) SetFunc(column string, fn *Func) *UpdateBuilder

SetFunc adds SET column=someFunc(?...) clause to the query.

func (*UpdateBuilder) SetLit

func (b *UpdateBuilder) SetLit(column, literal string) *UpdateBuilder

SetLit adds SET column=literal clause to the query.

func (*UpdateBuilder) SetNamed

func (b *UpdateBuilder) SetNamed(column, name string) *UpdateBuilder

SetNamed adds SET column=? clause to the query with a custom parameter name.

func (*UpdateBuilder) SetTuple added in v1.3.0

func (b *UpdateBuilder) SetTuple(column string, count int) *UpdateBuilder

SetTuple adds a SET clause for a tuple to the query.

func (*UpdateBuilder) TTL

TTL adds USING TTL clause to the query.

func (*UpdateBuilder) TTLNamed

func (b *UpdateBuilder) TTLNamed(name string) *UpdateBuilder

TTLNamed adds USING TTL clause to the query with a custom parameter name.

func (*UpdateBuilder) Table

func (b *UpdateBuilder) Table(table string) *UpdateBuilder

Table sets the table to be updated.

func (*UpdateBuilder) Timestamp

func (b *UpdateBuilder) Timestamp(t time.Time) *UpdateBuilder

Timestamp adds USING TIMESTAMP clause to the query.

func (*UpdateBuilder) TimestampNamed

func (b *UpdateBuilder) TimestampNamed(name string) *UpdateBuilder

TimestampNamed adds a USING TIMESTAMP clause to the query with a custom parameter name.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL