Documentation
¶
Overview ¶
Package chsql provides fluent Clickhouse SQL query builder.
Index ¶
- func CollectTokens[S ~string | ~[]byte](s S, cb func(s S) bool)
- func IsSingleToken[S ~string | ~[]byte](s S) bool
- func PutPrinter(*Printer)
- type Expr
- func And(left, right Expr) Expr
- func Array(args ...Expr) Expr
- func ArrayConcat(args ...Expr) Expr
- func ArrayJoin(args ...Expr) Expr
- func Bool(v bool) Expr
- func Cast(x Expr, typ string) Expr
- func Coalesce(args ...Expr) Expr
- func ColumnEq[V litValue](column string, right V) Expr
- func Contains(column, needle string) Expr
- func Eq(left, right Expr) Expr
- func Float[I litFloat](v I) Expr
- func Function(name string, args ...Expr) Expr
- func Gt(left, right Expr) Expr
- func Gte(left, right Expr) Expr
- func Has(arr, elem Expr) Expr
- func HasToken(haystack Expr, token string) Expr
- func Hex(arg Expr) Expr
- func Ident(tok string) Expr
- func In(left, right Expr) Expr
- func InTimeRange(column string, start, end time.Time) Expr
- func Integer[I litInt](v I) Expr
- func JSONExtract(from Expr, typ string) Expr
- func JSONExtractField(from Expr, field, typ string) Expr
- func JSONExtractKeys(from Expr) Expr
- func JSONExtractString(from Expr, field string) Expr
- func JoinAnd(args ...Expr) Expr
- func JoinOr(args ...Expr) Expr
- func Length(arg Expr) Expr
- func Like(haystack, pattern Expr) Expr
- func Lt(left, right Expr) Expr
- func Lte(left, right Expr) Expr
- func Map(args ...Expr) Expr
- func MapConcat(args ...Expr) Expr
- func Match(haystack, pattern Expr) Expr
- func Minus(left, right Expr) Expr
- func Not(sub Expr) Expr
- func NotEq(left, right Expr) Expr
- func Or(left, right Expr) Expr
- func Position(haystack, needle Expr) Expr
- func PositionUTF8(haystack, needle Expr) Expr
- func SimpleJSONHas(json Expr, field string) Expr
- func String(v string) Expr
- func SubQuery(q Query) Expr
- func ToFloat64(arg Expr) Expr
- func ToString(arg Expr) Expr
- func ToUnixTimestamp64Nano(arg Expr) Expr
- func Tuple(args ...Expr) Expr
- func TupleValues[V litValue](vals ...V) Expr
- func Unhex(arg Expr) Expr
- func UnixNano(t time.Time) Expr
- func Value[V litValue](v V) Expr
- type OnResult
- type Order
- type Printer
- func (p *Printer) And()
- func (p *Printer) Asc()
- func (p *Printer) By()
- func (p *Printer) CloseParen()
- func (p *Printer) Comma()
- func (p *Printer) Desc()
- func (p *Printer) Distinct()
- func (p *Printer) From()
- func (p *Printer) Group()
- func (p *Printer) Ident(tok string)
- func (p *Printer) Limit()
- func (p *Printer) Literal(lit string)
- func (p *Printer) OpenParen()
- func (p *Printer) Order()
- func (p *Printer) Prewhere()
- func (p *Printer) Select()
- func (p *Printer) String() string
- func (p *Printer) Where()
- func (p *Printer) WriteExpr(e Expr) error
- type Query
- type ResultColumn
- type SelectQuery
- func (q *SelectQuery) Distinct(b bool) *SelectQuery
- func (q *SelectQuery) GroupBy(groups ...Expr) *SelectQuery
- func (q *SelectQuery) Limit(n int) *SelectQuery
- func (q *SelectQuery) Order(e Expr, order Order) *SelectQuery
- func (q *SelectQuery) Prepare(onResult OnResult) (ch.Query, error)
- func (q *SelectQuery) Prewhere(filters ...Expr) *SelectQuery
- func (q *SelectQuery) Results() (r proto.Results)
- func (q *SelectQuery) Where(filters ...Expr) *SelectQuery
- func (q *SelectQuery) WriteSQL(p *Printer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectTokens ¶ added in v0.15.0
CollectTokens iterates over tokens in given string.
func IsSingleToken ¶
IsSingleToken whether if given string is a single token.
See https://clickhouse.com/docs/en/sql-reference/functions/string-search-functions#hastoken. See https://github.com/ClickHouse/ClickHouse/blob/755b73f3fc99847f40ac4d9186bb19116e709c37/src/Interpreters/ITokenExtractor.cpp#L84.
Types ¶
type Expr ¶
type Expr struct {
// contains filtered or unexported fields
}
Expr is a Clickhouse expression.
func ArrayConcat ¶
ArrayConcat returns `arrayConcat(<args>...)` function call expression.
func InTimeRange ¶
InTimeRange returns boolean expression to filter by [start:end].
func JSONExtract ¶
JSONExtract returns `JSONExtract(<from>, <typ>)` function call expression.
func JSONExtractField ¶
JSONExtractField returns `JSONExtract(<from>, <field>, <typ>)` function call expression.
func JSONExtractKeys ¶
JSONExtractKeys returns `JSONExtractKeys(<from>)` function call expression.
func JSONExtractString ¶
JSONExtractString returns `JSONExtractString(<from>, <field>)` function call expression.
func JoinAnd ¶
JoinAnd joins given expressions using AND op.
- If len(args) == 0, returns `true` literal.
- If len(args) == 1, returns first argument.
- Otherwise, joins arguments with AND.
func JoinOr ¶
JoinOr joins given expressions using OR op.
- If len(args) == 0, returns `true` literal.
- If len(args) == 1, returns first argument.
- Otherwise, joins arguments with OR.
func PositionUTF8 ¶
PositionUTF8 returns `positionUTF8(<haystack>, <needle>)` function call expression.
func SimpleJSONHas ¶
SimpleJSONHas returns `simpleJSONHas(<json>, <field>)` function call expression.
func ToUnixTimestamp64Nano ¶
ToUnixTimestamp64Nano returns `toUnixTimestamp64Nano(<arg>)` function call expression.
func TupleValues ¶
func TupleValues[V litValue](vals ...V) Expr
TupleValues returns tuple of given values.
type OnResult ¶
OnResult defines ch.Query.OnResult callback type.
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer prints SQL query.
type ResultColumn ¶
ResultColumn defines a column result.
type SelectQuery ¶
type SelectQuery struct {
// contains filtered or unexported fields
}
SelectQuery is a SELECT query builder.
func Select ¶
func Select(table string, columns ...ResultColumn) *SelectQuery
Select creates a new SelectQuery.
func SelectFrom ¶
func SelectFrom(sub *SelectQuery, columns ...ResultColumn) *SelectQuery
SelectFrom creates a new SelectQuery from subquery.
func (*SelectQuery) Distinct ¶
func (q *SelectQuery) Distinct(b bool) *SelectQuery
Distinct sets if query is `DISTINCT`.
func (*SelectQuery) GroupBy ¶ added in v0.16.0
func (q *SelectQuery) GroupBy(groups ...Expr) *SelectQuery
GroupBy adds grouping to query.
func (*SelectQuery) Limit ¶
func (q *SelectQuery) Limit(n int) *SelectQuery
Limit sets query limit.
If n is equal to or less than zero, limit is ignored.
func (*SelectQuery) Order ¶
func (q *SelectQuery) Order(e Expr, order Order) *SelectQuery
Order adds order to query.
func (*SelectQuery) Prepare ¶
func (q *SelectQuery) Prepare(onResult OnResult) (ch.Query, error)
Prepare builds SQL query and passes columns to ch.Query.
func (*SelectQuery) Prewhere ¶
func (q *SelectQuery) Prewhere(filters ...Expr) *SelectQuery
Prewhere adds filters to query.
func (*SelectQuery) Results ¶
func (q *SelectQuery) Results() (r proto.Results)
Results returns list of result columns.
func (*SelectQuery) Where ¶
func (q *SelectQuery) Where(filters ...Expr) *SelectQuery
Where adds filters to query.
func (*SelectQuery) WriteSQL ¶
func (q *SelectQuery) WriteSQL(p *Printer) error
WriteSQL writes SQL query.