jet

package
v2.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StringConcatOperator        = "||"
	StringRegexpLikeOperator    = "REGEXP"
	StringNotRegexpLikeOperator = "NOT REGEXP"
)

Operators

Variables

View Source
var (
	// NULL is jet equivalent of SQL NULL
	NULL = newNullLiteral()
	// STAR is jet equivalent of SQL *
	STAR = newStarLiteral()
	// PLUS_INFINITY is jet equivalent for sql infinity
	PLUS_INFINITY = String("infinity")
	// MINUS_INFINITY is jet equivalent for sql -infinity
	MINUS_INFINITY = String("-infinity")
)
View Source
var (
	Int4RangeExp = RangeExp[Int4Expression]
	Int8RangeExp = RangeExp[Int8Expression]
	NumRangeExp  = RangeExp[NumericExpression]
	DateRangeExp = RangeExp[DateExpression]
	TsRangeExp   = RangeExp[TimestampExpression]
	TstzRangeExp = RangeExp[TimestampzExpression]
)

different range expression wrappers

View Source
var (
	UNBOUNDED   = Keyword("UNBOUNDED")
	CURRENT_ROW = frameExtentKeyword{"CURRENT ROW"}
)

Window function keywords

Functions

func AVG

func AVG(numericExpression Expression) floatWindowExpression

AVG is aggregate function used to calculate avg value from numeric expression

func BIT_AND

func BIT_AND(integerExpression IntegerExpression) integerWindowExpression

BIT_AND is aggregate function used to calculates the bitwise AND of all non-null input values, or null if none.

func BIT_OR

func BIT_OR(integerExpression IntegerExpression) integerWindowExpression

BIT_OR is aggregate function used to calculates the bitwise OR of all non-null input values, or null if none.

func BOOL_AND

func BOOL_AND(boolExpression BoolExpression) boolWindowExpression

BOOL_AND is aggregate function. Returns true if all input values are true, otherwise false

func BOOL_OR

func BOOL_OR(boolExpression BoolExpression) boolWindowExpression

BOOL_OR is aggregate function. Returns true if at least one input value is true, otherwise false

func COUNT

func COUNT(expression Expression) integerWindowExpression

COUNT is aggregate function. Returns number of input rows for which the value of expression is not null.

func CUME_DIST

func CUME_DIST() floatWindowExpression

CUME_DIST calculates cumulative distribution: (number of partition rows preceding or peer with current row) / total partition rows

func DENSE_RANK

func DENSE_RANK() integerWindowExpression

DENSE_RANK returns rank of the current row without gaps; this function counts peer groups

func EVERY

func EVERY(boolExpression BoolExpression) boolWindowExpression

EVERY is aggregate function. Returns true if all input values are true, otherwise false

func FIRST_VALUE

func FIRST_VALUE(value Expression) windowExpression

FIRST_VALUE returns value evaluated at the row that is the first row of the window frame

func FixedLiteral

func FixedLiteral(value interface{}) *literalExpressionImpl

FixedLiteral is injected directly to SQL query, and does not appear in parametrized argument list.

func LAG

func LAG(expr Expression, offsetAndDefault ...interface{}) windowExpression

LAG returns value evaluated at the row that is offset rows before the current row within the partition; if there is no such row, instead return default (which must be of the same type as value). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to null

func LAST_VALUE

func LAST_VALUE(value Expression) windowExpression

LAST_VALUE returns value evaluated at the row that is the last row of the window frame

func LEAD

func LEAD(expr Expression, offsetAndDefault ...interface{}) windowExpression

LEAD returns value evaluated at the row that is offset rows after the current row within the partition; if there is no such row, instead return default (which must be of the same type as value). Both offset and default are evaluated with respect to the current row. If omitted, offset defaults to 1 and default to null

func LOWER_BOUND

func LOWER_BOUND[T Expression](rangeExpression Range[T]) T

LOWER_BOUND returns range expressions lower bound. Returns null if range is empty or the requested bound is infinite.

func Literal

func Literal(value interface{}) *literalExpressionImpl

Literal is injected directly to SQL query, and does not appear in parametrized argument list.

func MAXf

func MAXf(floatExpression FloatExpression) floatWindowExpression

MAXf is aggregate function. Returns maximum value of float expression across all input values

func MAXi

func MAXi(integerExpression IntegerExpression) integerWindowExpression

MAXi is aggregate function. Returns maximum value of int expression across all input values

func MINf

func MINf(floatExpression FloatExpression) floatWindowExpression

MINf is aggregate function. Returns minimum value of float expression across all input values

func MINi

func MINi(integerExpression IntegerExpression) integerWindowExpression

MINi is aggregate function. Returns minimum value of int expression across all input values

func NTH_VALUE

func NTH_VALUE(value Expression, nth int64) windowExpression

NTH_VALUE returns value evaluated at the row that is the nth row of the window frame (counting from 1); null if no such row

func NTILE

func NTILE(numOfBuckets int64) integerWindowExpression

NTILE returns integer ranging from 1 to the argument value, dividing the partition as equally as possible

func NewDateFunc

func NewDateFunc(name string, expressions ...Expression) *dateFunc

NewDateFunc creates new date function with name and expression parameters

func NewFloatWindowFunc

func NewFloatWindowFunc(name string, expressions ...Expression) floatWindowExpression

NewFloatWindowFunc creates new float function with name and expressions

func NewFunc

func NewFunc(name string, expressions []Expression, parent Expression) *funcExpressionImpl

NewFunc creates new function with name and expressions parameters

func NewRowLock

func NewRowLock(name string) func() RowLock

NewRowLock creates new RowLock

func NewSelectTable

func NewSelectTable(selectStmt SerializerHasProjections, alias string) selectTableImpl

NewSelectTable func

func NewTimeFunc

func NewTimeFunc(name string, expressions ...Expression) *timeFunc

NewTimeFunc creates new time function with name and expression parameters

func NewTimestampFunc

func NewTimestampFunc(name string, expressions ...Expression) *timestampFunc

NewTimestampFunc creates new timestamp function with name and expressions

func OptionalOrDefaultString

func OptionalOrDefaultString(defaultStr string, str ...string) string

OptionalOrDefaultString will return first value from variable argument list str or defaultStr if variable argument list is empty

func PERCENT_RANK

func PERCENT_RANK() floatWindowExpression

PERCENT_RANK calculates relative rank of the current row: (rank - 1) / (total partition rows - 1)

func RANK

func RANK() integerWindowExpression

RANK of the current row with gaps; same as row_number of its first peer

func ROW_NUMBER

func ROW_NUMBER() integerWindowExpression

ROW_NUMBER returns number of the current row within its partition, counting from 1

func SUMf

func SUMf(floatExpression FloatExpression) floatWindowExpression

SUMf is aggregate function. Returns sum of expression across all float expressions

func SUMi

func SUMi(integerExpression IntegerExpression) integerWindowExpression

SUMi is aggregate function. Returns sum of expression across all integer expression.

func Serialize

func Serialize(exp Serializer, statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize func

func SerializeClauseList

func SerializeClauseList(statement StatementType, clauses []Serializer, out *SQLBuilder)

SerializeClauseList func

func SerializeColumnExpressionNames

func SerializeColumnExpressionNames(columns []ColumnExpression, out *SQLBuilder)

SerializeColumnExpressionNames func

func SerializeColumnExpressions

func SerializeColumnExpressions(columns []ColumnExpression, statementType StatementType,
	out *SQLBuilder, options ...SerializeOption)

SerializeColumnExpressions func

func SerializeColumnNames

func SerializeColumnNames(columns []Column, out *SQLBuilder)

SerializeColumnNames func

func SerializeForOrderBy

func SerializeForOrderBy(exp Expression, statementType StatementType, out *SQLBuilder)

func SerializeForProjection

func SerializeForProjection(projection Projection, statementType StatementType, out *SQLBuilder)

SerializeForProjection is helper function for serializing projection outside of jet package

func SerializeProjectionList

func SerializeProjectionList(statement StatementType, projections []Projection, out *SQLBuilder)

SerializeProjectionList func

func SetLoggerFunc

func SetLoggerFunc(loggerFunc LoggerFunc)

SetLoggerFunc sets automatic statement logging

func SetQueryLogger

func SetQueryLogger(loggerFunc QueryLoggerFunc)

SetQueryLogger sets automatic query logging function.

func SetSubQuery

func SetSubQuery(columnExpression ColumnExpression, subQuery SelectTable)

SetSubQuery is utility function to set table name from outside of jet package to avoid making public setSubQuery

func SetTableName

func SetTableName(columnExpression ColumnExpression, tableName string)

SetTableName is utility function to set table name from outside of jet package to avoid making public setTableName

func UPPER_BOUND

func UPPER_BOUND[T Expression](rangeExpression Range[T]) T

UPPER_BOUND returns range expressions upper bound. Returns null if range is empty or the requested bound is infinite.

func UnwindRowsFromModels

func UnwindRowsFromModels(columns []Column, data interface{}) [][]Serializer

UnwindRowsFromModels func

func WITH

func WITH(dialect Dialect, recursive bool, cte ...*CommonTableExpression) func(statement Statement) Statement

WITH function creates new with statement from list of common table expressions for specified dialect

Types

type BoolExpression

type BoolExpression interface {
	Expression

	// Check if this expression is equal to rhs
	EQ(rhs BoolExpression) BoolExpression
	// Check if this expression is not equal to rhs
	NOT_EQ(rhs BoolExpression) BoolExpression
	// Check if this expression is distinct to rhs
	IS_DISTINCT_FROM(rhs BoolExpression) BoolExpression
	// Check if this expression is not distinct to rhs
	IS_NOT_DISTINCT_FROM(rhs BoolExpression) BoolExpression

	// Check if this expression is true
	IS_TRUE() BoolExpression
	// Check if this expression is not true
	IS_NOT_TRUE() BoolExpression
	// Check if this expression is false
	IS_FALSE() BoolExpression
	// Check if this expression is not false
	IS_NOT_FALSE() BoolExpression
	// Check if this expression is unknown
	IS_UNKNOWN() BoolExpression
	// Check if this expression is not unknown
	IS_NOT_UNKNOWN() BoolExpression

	// expression AND operator rhs
	AND(rhs BoolExpression) BoolExpression
	// expression OR operator rhs
	OR(rhs BoolExpression) BoolExpression
}

BoolExpression interface

func AND

func AND(expressions ...BoolExpression) BoolExpression

AND function adds AND operator between expressions. This function can be used, instead of method AND, to have a better inlining of a complex condition in the Go code and in the generated SQL.

func Bool

func Bool(value bool) BoolExpression

Bool creates new bool literal expression

func BoolExp

func BoolExp(expression Expression) BoolExpression

BoolExp is bool expression wrapper around arbitrary expression. Allows go compiler to see any expression as bool expression. Does not add sql cast to generated sql builder output.

func Contains

func Contains(lhs Expression, rhs Expression) BoolExpression

Contains returns a representation of "a @> b"

func EXISTS

func EXISTS(subQuery Expression) BoolExpression

EXISTS checks for existence of the rows in subQuery

func Eq

func Eq(lhs, rhs Expression) BoolExpression

Eq returns a representation of "a=b"

func Gt

func Gt(lhs, rhs Expression) BoolExpression

Gt returns a representation of "a>b"

func GtEq

func GtEq(lhs, rhs Expression) BoolExpression

GtEq returns a representation of "a>=b"

func IS_EMPTY

func IS_EMPTY[T Expression](rangeExpression Range[T]) BoolExpression

IS_EMPTY returns true if range is empty

func IsDistinctFrom

func IsDistinctFrom(lhs, rhs Expression) BoolExpression

IsDistinctFrom returns a representation of "a IS DISTINCT FROM b"

func IsNotDistinctFrom

func IsNotDistinctFrom(lhs, rhs Expression) BoolExpression

IsNotDistinctFrom returns a representation of "a IS NOT DISTINCT FROM b"

func LOWER_INC

func LOWER_INC[T Expression](rangeExpression Range[T]) BoolExpression

LOWER_INC returns true if lower bound is inclusive. Returns false for empty range.

func LOWER_INF

func LOWER_INF[T Expression](rangeExpression Range[T]) BoolExpression

LOWER_INF returns true if upper bound is infinite. Returns false for empty range.

func Lt

Lt returns a representation of "a<b"

func LtEq

func LtEq(lhs, rhs Expression) BoolExpression

LtEq returns a representation of "a<=b"

func NOT

NOT returns negation of bool expression result

func NewBetweenOperatorExpression

func NewBetweenOperatorExpression(expression, min, max Expression, notBetween bool) BoolExpression

NewBetweenOperatorExpression creates new BETWEEN operator expression

func NotEq

func NotEq(lhs, rhs Expression) BoolExpression

NotEq returns a representation of "a!=b"

func OR

func OR(expressions ...BoolExpression) BoolExpression

OR function adds OR operator between expressions. This function can be used, instead of method OR, to have a better inlining of a complex condition in the Go code and in the generated SQL.

func Overlap

func Overlap(lhs, rhs Expression) BoolExpression

Overlap returns a representation of "a && b"

func REGEXP_LIKE

func REGEXP_LIKE(stringExp StringExpression, pattern StringExpression, matchType ...string) BoolExpression

REGEXP_LIKE Returns 1 if the string expr matches the regular expression specified by the pattern pat, 0 otherwise.

func RawBool

func RawBool(raw string, namedArgs ...map[string]interface{}) BoolExpression

RawBool helper that for raw string boolean expressions

func UPPER_INC

func UPPER_INC[T Expression](rangeExpression Range[T]) BoolExpression

UPPER_INC returns true if upper bound is inclusive. Returns false for empty range.

func UPPER_INF

func UPPER_INF[T Expression](rangeExpression Range[T]) BoolExpression

UPPER_INF returns true if lower bound is infinite. Returns false for empty range.

type CaseOperator

type CaseOperator interface {
	Expression

	WHEN(condition Expression) CaseOperator
	THEN(then Expression) CaseOperator
	ELSE(els Expression) CaseOperator
}

CaseOperator is interface for SQL case operator

func CASE

func CASE(expression ...Expression) CaseOperator

CASE create CASE operator with optional list of expressions

type Cast

type Cast interface {
	AS(castType string) Expression
}

Cast interface

func NewCastImpl

func NewCastImpl(expression Expression) Cast

NewCastImpl creates new generic cast

type Clause

type Clause interface {
	Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)
}

Clause interface

type ClauseDelete

type ClauseDelete struct {
	Table SerializerTable

	// MySQL only
	OptimizerHints optimizerHints
}

ClauseDelete struct

func (*ClauseDelete) Serialize

func (d *ClauseDelete) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseFetch

type ClauseFetch struct {
	Count    IntegerExpression
	WithTies bool
}

ClauseFetch struct

func (*ClauseFetch) Serialize

func (o *ClauseFetch) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes ClauseFetch into sql builder output

type ClauseFor

type ClauseFor struct {
	Lock RowLock
}

ClauseFor struct

func (*ClauseFor) Serialize

func (f *ClauseFor) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseFrom

type ClauseFrom struct {
	Name   string
	Tables []Serializer
}

ClauseFrom struct

func (*ClauseFrom) Serialize

func (f *ClauseFrom) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseGroupBy

type ClauseGroupBy struct {
	List []GroupByClause
}

ClauseGroupBy struct

func (*ClauseGroupBy) Serialize

func (c *ClauseGroupBy) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseHaving

type ClauseHaving struct {
	Condition BoolExpression
}

ClauseHaving struct

func (*ClauseHaving) Serialize

func (c *ClauseHaving) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseIn

type ClauseIn struct {
	LockMode string
}

ClauseIn struct

func (*ClauseIn) Serialize

func (i *ClauseIn) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseInsert

type ClauseInsert struct {
	Table   SerializerTable
	Columns []Column

	// MySQL only
	OptimizerHints optimizerHints
}

ClauseInsert struct

func (*ClauseInsert) GetColumns

func (i *ClauseInsert) GetColumns() []Column

GetColumns gets list of columns for insert

func (*ClauseInsert) Serialize

func (i *ClauseInsert) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseLimit

type ClauseLimit struct {
	Count int64
}

ClauseLimit struct

func (*ClauseLimit) Serialize

func (l *ClauseLimit) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseOffset

type ClauseOffset struct {
	Count IntegerExpression
}

ClauseOffset struct

func (*ClauseOffset) Serialize

func (o *ClauseOffset) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseOptional

type ClauseOptional struct {
	Name      string
	Show      bool
	InNewLine bool
}

ClauseOptional struct

func (*ClauseOptional) Serialize

func (d *ClauseOptional) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseOrderBy

type ClauseOrderBy struct {
	List        []OrderByClause
	SkipNewLine bool
}

ClauseOrderBy struct

func (*ClauseOrderBy) Serialize

func (o *ClauseOrderBy) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseQuery

type ClauseQuery struct {
	Query          SerializerStatement
	SkipSelectWrap bool
}

ClauseQuery struct

func (*ClauseQuery) Serialize

func (v *ClauseQuery) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseReturning

type ClauseReturning struct {
	ProjectionList []Projection
}

ClauseReturning type

func (ClauseReturning) Projections

func (r ClauseReturning) Projections() ProjectionList

Projections for ClauseReturning

func (*ClauseReturning) Serialize

func (r *ClauseReturning) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize for ClauseReturning

type ClauseSelect

type ClauseSelect struct {
	Distinct          bool
	DistinctOnColumns []ColumnExpression
	ProjectionList    []Projection

	// MySQL only
	OptimizerHints optimizerHints
}

ClauseSelect struct

func (*ClauseSelect) Projections

func (s *ClauseSelect) Projections() ProjectionList

Projections returns list of projections for select clause

func (*ClauseSelect) Serialize

func (s *ClauseSelect) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseSetStmtOperator

type ClauseSetStmtOperator struct {
	Operator       string
	All            bool
	Selects        []SerializerStatement
	OrderBy        ClauseOrderBy
	Limit          ClauseLimit
	Offset         ClauseOffset
	SkipSelectWrap bool
}

ClauseSetStmtOperator struct

func (*ClauseSetStmtOperator) Projections

func (s *ClauseSetStmtOperator) Projections() ProjectionList

Projections returns set of projections for ClauseSetStmtOperator

func (*ClauseSetStmtOperator) Serialize

func (s *ClauseSetStmtOperator) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseStatementBegin

type ClauseStatementBegin struct {
	Name   string
	Tables []SerializerTable
}

ClauseStatementBegin struct

func (*ClauseStatementBegin) Serialize

func (d *ClauseStatementBegin) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseUpdate

type ClauseUpdate struct {
	Table SerializerTable

	// MySQL only
	OptimizerHints optimizerHints
}

ClauseUpdate struct

func (*ClauseUpdate) Serialize

func (u *ClauseUpdate) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseValues

type ClauseValues struct {
	Rows [][]Serializer
	As   string
}

ClauseValues struct

func (*ClauseValues) Serialize

func (v *ClauseValues) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseValuesQuery

type ClauseValuesQuery struct {
	ClauseValues
	ClauseQuery
}

ClauseValuesQuery struct

func (*ClauseValuesQuery) Serialize

func (v *ClauseValuesQuery) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseWhere

type ClauseWhere struct {
	Condition BoolExpression
	Mandatory bool
}

ClauseWhere struct

func (*ClauseWhere) Serialize

func (c *ClauseWhere) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseWindow

type ClauseWindow struct {
	Definitions []WindowDefinition
}

ClauseWindow struct

func (*ClauseWindow) Serialize

func (i *ClauseWindow) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type ClauseWithProjections

type ClauseWithProjections interface {
	Clause

	Projections() ProjectionList
}

ClauseWithProjections interface

type Column

type Column interface {
	Name() string
	TableName() string
	// contains filtered or unexported methods
}

Column is common column interface for all types of columns.

func UnwidColumnList

func UnwidColumnList(columns []Column) []Column

UnwidColumnList func

func UnwindColumns

func UnwindColumns(column1 Column, columns ...Column) []Column

UnwindColumns func

type ColumnAssigment

type ColumnAssigment interface {
	Serializer
	// contains filtered or unexported methods
}

ColumnAssigment is interface wrapper around column assigment

type ColumnBool

type ColumnBool interface {
	BoolExpression
	Column

	From(subQuery SelectTable) ColumnBool
	SET(boolExp BoolExpression) ColumnAssigment
}

ColumnBool is interface for SQL boolean columns.

func BoolColumn

func BoolColumn(name string) ColumnBool

BoolColumn creates named bool column.

type ColumnDate

type ColumnDate interface {
	DateExpression
	Column

	From(subQuery SelectTable) ColumnDate
	SET(dateExp DateExpression) ColumnAssigment
}

ColumnDate is interface of SQL date columns.

func DateColumn

func DateColumn(name string) ColumnDate

DateColumn creates named date column.

type ColumnExpression

type ColumnExpression interface {
	Column
	Expression
}

ColumnExpression interface

type ColumnExpressionImpl

type ColumnExpressionImpl struct {
	ExpressionInterfaceImpl
	// contains filtered or unexported fields
}

ColumnExpressionImpl is base type for sql columns.

func NewColumnImpl

func NewColumnImpl(name string, tableName string, parent ColumnExpression) ColumnExpressionImpl

NewColumnImpl creates new ColumnExpressionImpl

func (*ColumnExpressionImpl) Name

func (c *ColumnExpressionImpl) Name() string

Name returns name of the column

func (*ColumnExpressionImpl) TableName

func (c *ColumnExpressionImpl) TableName() string

TableName returns column table name

type ColumnFloat

type ColumnFloat interface {
	FloatExpression
	Column

	From(subQuery SelectTable) ColumnFloat
	SET(floatExp FloatExpression) ColumnAssigment
}

ColumnFloat is interface for SQL real, numeric, decimal or double precision column.

func FloatColumn

func FloatColumn(name string) ColumnFloat

FloatColumn creates named float column.

type ColumnInteger

type ColumnInteger interface {
	IntegerExpression
	Column

	From(subQuery SelectTable) ColumnInteger
	SET(intExp IntegerExpression) ColumnAssigment
}

ColumnInteger is interface for SQL smallint, integer, bigint columns.

func IntegerColumn

func IntegerColumn(name string) ColumnInteger

IntegerColumn creates named integer column.

type ColumnList

type ColumnList []ColumnExpression

ColumnList is a helper type to support list of columns as single projection

func (ColumnList) As

func (cl ColumnList) As(tableAlias string) ProjectionList

As will create new projection list where each column is wrapped with a new table alias. tableAlias should be in the form 'name' or 'name.*', or it can also be an empty string. For instance: If projection list has a column 'Artist.Name', and tableAlias is 'Musician.*', returned projection list will have a column wrapped in alias 'Musician.Name'. If tableAlias is empty string, it removes existing table alias ('Artist.Name' becomes 'Name').

func (ColumnList) Except

func (cl ColumnList) Except(excludedColumns ...Column) ColumnList

Except will create new column list in which columns contained in list of excluded column names are removed

Address.AllColumns.Except(Address.PostalCode, Address.Phone)

func (ColumnList) Name

func (cl ColumnList) Name() string

Name is placeholder for ColumnList to implement Column interface

func (ColumnList) SET

func (cl ColumnList) SET(expression Expression) ColumnAssigment

SET creates column assigment for each column in column list. expression should be created by ROW function

Link.UPDATE().
	SET(Link.MutableColumns.SET(ROW(String("github.com"), Bool(false))).
	WHERE(Link.ID.EQ(Int(0)))

func (ColumnList) TableName

func (cl ColumnList) TableName() string

TableName is placeholder for ColumnList to implement Column interface

type ColumnRange

type ColumnRange[T Expression] interface {
	Range[T]
	Column

	From(subQuery SelectTable) ColumnRange[T]
	SET(rangeExp Range[T]) ColumnAssigment
}

ColumnRange is interface for range columns which can be int range, string range timestamp range or date range.

func RangeColumn

func RangeColumn[T Expression](name string) ColumnRange[T]

RangeColumn creates named range column.

type ColumnSerializer

type ColumnSerializer interface {
	Serializer
	Column
}

ColumnSerializer is interface for all serializable columns

type ColumnString

type ColumnString interface {
	StringExpression
	Column

	From(subQuery SelectTable) ColumnString
	SET(stringExp StringExpression) ColumnAssigment
}

ColumnString is interface for SQL text, character, character varying bytea, uuid columns and enums types.

func StringColumn

func StringColumn(name string) ColumnString

StringColumn creates named string column.

type ColumnTime

type ColumnTime interface {
	TimeExpression
	Column

	From(subQuery SelectTable) ColumnTime
	SET(timeExp TimeExpression) ColumnAssigment
}

ColumnTime is interface for SQL time column.

func TimeColumn

func TimeColumn(name string) ColumnTime

TimeColumn creates named time column

type ColumnTimestamp

type ColumnTimestamp interface {
	TimestampExpression
	Column

	From(subQuery SelectTable) ColumnTimestamp
	SET(timestampExp TimestampExpression) ColumnAssigment
}

ColumnTimestamp is interface of SQL timestamp columns.

func TimestampColumn

func TimestampColumn(name string) ColumnTimestamp

TimestampColumn creates named timestamp column

type ColumnTimestampz

type ColumnTimestampz interface {
	TimestampzExpression
	Column

	From(subQuery SelectTable) ColumnTimestampz
	SET(timestampzExp TimestampzExpression) ColumnAssigment
}

ColumnTimestampz is interface of SQL timestamp with timezone columns.

func TimestampzColumn

func TimestampzColumn(name string) ColumnTimestampz

TimestampzColumn creates named timestamp with time zone column.

type ColumnTimez

type ColumnTimez interface {
	TimezExpression
	Column

	From(subQuery SelectTable) ColumnTimez
	SET(timeExp TimezExpression) ColumnAssigment
}

ColumnTimez is interface of SQL time with time zone columns.

func TimezColumn

func TimezColumn(name string) ColumnTimez

TimezColumn creates named time with time zone column.

type CommonTableExpression

type CommonTableExpression struct {
	NotMaterialized bool
	Columns         []ColumnExpression
	// contains filtered or unexported fields
}

CommonTableExpression contains information about a CTE.

func CTE

func CTE(name string, columns ...ColumnExpression) CommonTableExpression

CTE creates new named CommonTableExpression

func (CommonTableExpression) Alias

func (s CommonTableExpression) Alias() string

func (CommonTableExpression) AllColumns

func (c CommonTableExpression) AllColumns() ProjectionList

AllColumns returns list of all projections in the CTE

type DateExpression

DateExpression is interface for date types

func CURRENT_DATE

func CURRENT_DATE() DateExpression

CURRENT_DATE returns current date

func Date

func Date(year int, month time.Month, day int) DateExpression

Date creates new date literal expression

func DateExp

func DateExp(expression Expression) DateExpression

DateExp is date expression wrapper around arbitrary expression. Allows go compiler to see any expression as date expression. Does not add sql cast to generated sql builder output.

func DateT

func DateT(t time.Time) DateExpression

DateT creates new date literal expression from time.Time object

func RawDate

func RawDate(raw string, namedArgs ...map[string]interface{}) DateExpression

RawDate helper that for date expressions

func TO_DATE

func TO_DATE(dateStr, format StringExpression) DateExpression

TO_DATE converts string to date using format

type Dialect

type Dialect interface {
	Name() string
	PackageName() string
	OperatorSerializeOverride(operator string) SerializeOverride
	FunctionSerializeOverride(function string) SerializeOverride
	AliasQuoteChar() byte
	IdentifierQuoteChar() byte
	ArgumentPlaceholder() QueryPlaceholderFunc
	IsReservedWord(name string) bool
	SerializeOrderBy() func(expression Expression, ascending, nullsFirst *bool) SerializerFunc
}

Dialect interface

func NewDialect

func NewDialect(params DialectParams) Dialect

NewDialect creates new dialect with params

type DialectParams

type DialectParams struct {
	Name                       string
	PackageName                string
	OperatorSerializeOverrides map[string]SerializeOverride
	FunctionSerializeOverrides map[string]SerializeOverride
	AliasQuoteChar             byte
	IdentifierQuoteChar        byte
	ArgumentPlaceholder        QueryPlaceholderFunc
	ReservedWords              []string
	SerializeOrderBy           func(expression Expression, ascending, nullsFirst *bool) SerializerFunc
}

DialectParams struct

type Expression

type Expression interface {
	Serializer
	Projection
	GroupByClause
	OrderByClause

	// IS_NULL tests expression whether it is a NULL value.
	IS_NULL() BoolExpression
	// IS_NOT_NULL tests expression whether it is a non-NULL value.
	IS_NOT_NULL() BoolExpression

	// IN checks if this expressions matches any in expressions list
	IN(expressions ...Expression) BoolExpression
	// NOT_IN checks if this expressions is different of all expressions in expressions list
	NOT_IN(expressions ...Expression) BoolExpression

	// AS the temporary alias name to assign to the expression
	AS(alias string) Projection

	// ASC expression will be used to sort query result in ascending order
	ASC() OrderByClause
	// DESC expression will be used to sort query result in descending order
	DESC() OrderByClause
}

Expression is common interface for all expressions. Can be Bool, Int, Float, String, Date, Time, Timez, Timestamp or Timestampz expressions.

func Add

func Add(lhs, rhs Serializer) Expression

Add notEq returns a representation of "a + b"

func BinaryOperator

func BinaryOperator(lhs Expression, rhs Expression, operator string) Expression

func BoolExpressionListToExpressionList

func BoolExpressionListToExpressionList(expressions []BoolExpression) []Expression

BoolExpressionListToExpressionList converts list of bool expressions to list of expressions

func COALESCE

func COALESCE(value Expression, values ...Expression) Expression

COALESCE function returns the first of its arguments that is not null.

func CustomExpression

func CustomExpression(parts ...Serializer) Expression

func DISTINCT

func DISTINCT(expr Expression) Expression

DISTINCT operator can be used to return distinct values of expr

func Div

func Div(lhs, rhs Serializer) Expression

Div returns a representation of "a / b"

func EXTRACT

func EXTRACT(field string, from Expression) Expression

EXTRACT extracts time component from time expression

func Func

func Func(name string, expressions ...Expression) Expression

Func can be used to call custom or unsupported database functions.

func GREATEST

func GREATEST(value Expression, values ...Expression) Expression

GREATEST selects the largest value from a list of expressions

func LEAST

func LEAST(value Expression, values ...Expression) Expression

LEAST selects the smallest value from a list of expressions

func MAX

func MAX(expression Expression) Expression

MAX is aggregate function. Returns minimum value of expression across all input values.

func MIN

func MIN(expression Expression) Expression

MIN is aggregate function. Returns minimum value of expression across all input values.

func Mod

func Mod(lhs, rhs Serializer) Expression

Mod returns a representation of "a % b"

func Mul

func Mul(lhs, rhs Serializer) Expression

Mul returns a representation of "a * b"

func NULLIF

func NULLIF(value1, value2 Expression) Expression

NULLIF function returns a null value if value1 equals value2; otherwise it returns value1.

func NewBinaryOperatorExpression

func NewBinaryOperatorExpression(lhs, rhs Serializer, operator string, additionalParam ...Expression) Expression

NewBinaryOperatorExpression creates new binaryOperatorExpression

func OptionalOrDefaultExpression

func OptionalOrDefaultExpression(defaultExpression Expression, expression ...Expression) Expression

OptionalOrDefaultExpression will return first value from variable argument list expression or defaultExpression if variable argument list is empty

func ROW

func ROW(expressions ...Expression) Expression

ROW function is used to create a tuple value that consists of a set of expressions or column values.

func Raw

func Raw(raw string, namedArgs ...map[string]interface{}) Expression

Raw can be used for any unsupported functions, operators or expressions. For example: Raw("current_database()")

func RawWithParent

func RawWithParent(raw string, parent ...Expression) Expression

RawWithParent is a Raw constructor used for construction dialect specific expression

func SUM

func SUM(expression Expression) Expression

SUM is aggregate function. Returns sum of all expressions

func Sub

func Sub(lhs, rhs Serializer) Expression

Sub notEq returns a representation of "a - b"

func WRAP

func WRAP(expression ...Expression) Expression

WRAP wraps list of expressions with brackets - ( expression1, expression2, ... )

type ExpressionInterfaceImpl

type ExpressionInterfaceImpl struct {
	Parent Expression
}

ExpressionInterfaceImpl implements Expression interface methods

func (*ExpressionInterfaceImpl) AS

AS the temporary alias name to assign to the expression

func (*ExpressionInterfaceImpl) ASC

ASC expression will be used to sort a query result in ascending order

func (*ExpressionInterfaceImpl) DESC

DESC expression will be used to sort a query result in descending order

func (*ExpressionInterfaceImpl) IN

func (e *ExpressionInterfaceImpl) IN(expressions ...Expression) BoolExpression

IN checks if this expressions matches any in expressions list

func (*ExpressionInterfaceImpl) IS_NOT_NULL

func (e *ExpressionInterfaceImpl) IS_NOT_NULL() BoolExpression

IS_NOT_NULL tests expression whether it is a non-NULL value.

func (*ExpressionInterfaceImpl) IS_NULL

IS_NULL tests expression whether it is a NULL value.

func (*ExpressionInterfaceImpl) NOT_IN

func (e *ExpressionInterfaceImpl) NOT_IN(expressions ...Expression) BoolExpression

NOT_IN checks if this expressions is different of all expressions in expressions list

func (*ExpressionInterfaceImpl) NULLS_FIRST

func (e *ExpressionInterfaceImpl) NULLS_FIRST() OrderByClause

NULLS_FIRST specifies sort where null values appear before all non-null values

func (*ExpressionInterfaceImpl) NULLS_LAST

func (e *ExpressionInterfaceImpl) NULLS_LAST() OrderByClause

NULLS_LAST specifies sort where null values appear after all non-null values

type ExpressionStatement

type ExpressionStatement interface {
	Expression
	Statement
	HasProjections
}

ExpressionStatement interfacess

func NewExpressionStatementImpl

func NewExpressionStatementImpl(Dialect Dialect, statementType StatementType, parent ExpressionStatement, clauses ...Clause) ExpressionStatement

NewExpressionStatementImpl creates new expression statement

type FloatExpression

FloatExpression is interface for SQL float columns

func ABSf

func ABSf(floatExpression FloatExpression) FloatExpression

ABSf calculates absolute value from float expression

func CBRT

func CBRT(numericExpression NumericExpression) FloatExpression

CBRT calculates cube root of numeric expression

func CEIL

func CEIL(floatExpression FloatExpression) FloatExpression

CEIL calculates ceil of float expression

func Decimal

func Decimal(value string) FloatExpression

Decimal creates new float literal from string value

func FLOOR

func FLOOR(floatExpression FloatExpression) FloatExpression

FLOOR calculates floor of float expression

func Float

func Float(value float64) FloatExpression

Float creates new float literal from float64 value

func FloatExp

func FloatExp(expression Expression) FloatExpression

FloatExp is date expression wrapper around arbitrary expression. Allows go compiler to see any expression as float expression. Does not add sql cast to generated sql builder output.

func LN

func LN(floatExpression FloatExpression) FloatExpression

LN calculates natural algorithm of float expression

func LOG

func LOG(floatExpression FloatExpression) FloatExpression

LOG calculates logarithm of float expression

func NewFloatFunc

func NewFloatFunc(name string, expressions ...Expression) FloatExpression

NewFloatFunc creates new float function with name and expressions

func POW

func POW(base, exponent NumericExpression) FloatExpression

POW calculates power of base with exponent

func POWER

func POWER(base, exponent NumericExpression) FloatExpression

POWER calculates power of base with exponent

func ROUND

func ROUND(floatExpression FloatExpression, precision ...IntegerExpression) FloatExpression

ROUND calculates round of a float expressions with optional precision

func RawFloat

func RawFloat(raw string, namedArgs ...map[string]interface{}) FloatExpression

RawFloat helper that for float expressions

func SIGN

func SIGN(floatExpression FloatExpression) FloatExpression

SIGN returns sign of float expression

func SQRT

func SQRT(numericExpression NumericExpression) FloatExpression

SQRT calculates square root of numeric expression

func TO_NUMBER

func TO_NUMBER(floatStr, format StringExpression) FloatExpression

TO_NUMBER converts string to numeric using format

func TRUNC

func TRUNC(floatExpression FloatExpression, precision ...IntegerExpression) FloatExpression

TRUNC calculates trunc of float expression with optional precision

type FrameExtent

type FrameExtent interface {
	Serializer
	// contains filtered or unexported methods
}

FrameExtent interface

func FOLLOWING

func FOLLOWING(offset Serializer) FrameExtent

FOLLOWING window frame clause

func PRECEDING

func PRECEDING(offset Serializer) FrameExtent

PRECEDING window frame clause

type GroupByClause

type GroupByClause interface {
	// contains filtered or unexported methods
}

GroupByClause interface

func CUBE

func CUBE(expressions ...Expression) GroupByClause

CUBE operator is used with the GROUP BY clause to generate subtotals for all possible combinations of a group of columns. It creates extra rows in the result set that represent the subtotal values for each combination of columns.

func GROUPING_SETS

func GROUPING_SETS(expressions ...Expression) GroupByClause

GROUPING_SETS operator allows grouping of the rows in a table by multiple sets of columns in a single query. This can be useful when we want to analyze data by different combinations of columns, without having to write separate queries for each combination.

func ROLLUP

func ROLLUP(expressions ...Expression) GroupByClause

ROLLUP operator is used with the GROUP BY clause to generate all prefixes of a group of columns including the empty list. It creates extra rows in the result set that represent the subtotal values for each combination of columns.

func WITH_ROLLUP

func WITH_ROLLUP(expressions ...Expression) GroupByClause

WITH_ROLLUP operator is used with the GROUP BY clause to generate all prefixes of a group of columns including the empty list. It creates extra rows in the result set that represent the subtotal values for each combination of columns.

type HasProjections

type HasProjections interface {
	// contains filtered or unexported methods
}

HasProjections interface

type Int4Expression

type Int4Expression IntegerExpression

additional integer expression subtypes, used in range expressions.

type Int8Expression

type Int8Expression IntegerExpression

additional integer expression subtypes, used in range expressions.

type IntegerExpression

IntegerExpression interface

func ABSi

func ABSi(integerExpression IntegerExpression) IntegerExpression

ABSi calculates absolute value from int expression

func BIT_LENGTH

func BIT_LENGTH(stringExpression StringExpression) IntegerExpression

BIT_LENGTH returns number of bits in string expression

func BIT_NOT

BIT_NOT inverts every bit in integer expression result

func CHAR_LENGTH

func CHAR_LENGTH(stringExpression StringExpression) IntegerExpression

CHAR_LENGTH returns number of characters in string expression

func GROUPING

func GROUPING(expressions ...Expression) IntegerExpression

GROUPING function is used to identify which columns are included in a grouping set or a subtotal row. It takes as input the name of a column and returns 1 if the column is not included in the current grouping set, and 0 otherwise. It can be also used with multiple parameters to check if a set of columns is included in the current grouping set. The result of the GROUPING function would then be an integer bit mask having 1’s for the arguments which have GROUPING(argument) as 1.

func Int

func Int(value int64) IntegerExpression

Int creates a new 64 bit signed integer literal

func Int16

func Int16(value int16) IntegerExpression

Int16 creates a new 16 bit signed integer literal

func Int32

func Int32(value int32) IntegerExpression

Int32 creates a new 32 bit signed integer literal

func Int8

func Int8(value int8) IntegerExpression

Int8 creates a new 8 bit signed integer literal

func IntExp

func IntExp(expression Expression) IntegerExpression

IntExp is int expression wrapper around arbitrary expression. Allows go compiler to see any expression as int expression. Does not add sql cast to generated sql builder output.

func OCTET_LENGTH

func OCTET_LENGTH(stringExpression StringExpression) IntegerExpression

OCTET_LENGTH returns number of bytes in string expression

func RawInt

func RawInt(raw string, namedArgs ...map[string]interface{}) IntegerExpression

RawInt helper that for integer expressions

func STRPOS

func STRPOS(str, substring StringExpression) IntegerExpression

STRPOS returns location of specified substring (same as position(substring in string), but note the reversed argument order)

func Uint16

func Uint16(value uint16) IntegerExpression

Uint16 creates a new 16 bit unsigned integer literal

func Uint32

func Uint32(value uint32) IntegerExpression

Uint32 creates a new 32 bit unsigned integer literal

func Uint64

func Uint64(value uint64) IntegerExpression

Uint64 creates a new 64 bit unsigned integer literal

func Uint8

func Uint8(value uint8) IntegerExpression

Uint8 creates a new 8 bit unsigned integer literal

type Interval

type Interval interface {
	Serializer
	IsInterval
}

Interval is internal common representation of sql interval

type IntervalImpl

type IntervalImpl struct {
	Value Serializer
	IsIntervalImpl
}

IntervalImpl is implementation of Interval type

func NewInterval

func NewInterval(s Serializer) *IntervalImpl

NewInterval creates new interval from serializer

type IsInterval

type IsInterval interface {
	// contains filtered or unexported methods
}

IsInterval interface

type IsIntervalImpl

type IsIntervalImpl struct{}

IsIntervalImpl is implementation of IsInterval interface

type JoinTable

type JoinTable SerializerTable

JoinTable interface

func NewJoinTable

func NewJoinTable(lhs Serializer, rhs Serializer, joinType JoinType, onCondition BoolExpression) JoinTable

NewJoinTable creates new join table

type JoinType

type JoinType int

JoinType is type of table join

const (
	InnerJoin JoinType = iota
	LeftJoin
	RightJoin
	FullJoin
	CrossJoin
)

Table join types

type Keyword

type Keyword string

Keyword type

const (
	// DEFAULT is jet equivalent of SQL DEFAULT
	DEFAULT Keyword = "DEFAULT"
)

type KeywordClause

type KeywordClause struct {
	Keyword
}

KeywordClause type

func (KeywordClause) Serialize

func (k KeywordClause) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize for KeywordClause

type ListSerializer

type ListSerializer struct {
	Serializers []Serializer
	Separator   string
}

ListSerializer serializes list of serializers with separator

type LiteralExpression

type LiteralExpression interface {
	Expression

	Value() interface{}
	SetConstant(constant bool)
}

LiteralExpression is representation of an escaped literal

type LoggerFunc

type LoggerFunc func(ctx context.Context, statement PrintableStatement)

LoggerFunc is a function user can implement to support automatic statement logging.

type NumericExpression

type NumericExpression interface {
	Expression
	// contains filtered or unexported methods
}

NumericExpression is common interface for all integer and float expressions

type OptimizerHint

type OptimizerHint string

OptimizerHint provides a way to optimize query execution per-statement basis

type OrderByClause

type OrderByClause interface {
	// NULLS_FIRST specifies sort where null values appear before all non-null values.
	// For some dialects(mysql,mariadb), which do not support NULL_FIRST, NULL_FIRST is simulated
	// with additional IS_NOT_NULL expression.
	// For instance,
	//        Rental.ReturnDate.DESC().NULLS_FIRST()
	// would translate to,
	//        rental.return_date IS NOT NULL, rental.return_date DESC
	NULLS_FIRST() OrderByClause

	// NULLS_LAST specifies sort where null values appear after all non-null values.
	// For some dialects(mysql,mariadb), which do not support NULLS_LAST, NULLS_LAST is simulated
	// with additional IS_NULL expression.
	// For instance,
	//        Rental.ReturnDate.ASC().NULLS_LAST()
	// would translate to,
	//        rental.return_date IS NULL, rental.return_date ASC
	NULLS_LAST() OrderByClause
	// contains filtered or unexported methods
}

OrderByClause interface

type OrderSetAggregateFunc

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

OrderSetAggregateFunc implementation of order set aggregate function

func MODE

func MODE() *OrderSetAggregateFunc

MODE computes the most frequent value of the aggregated argument

func PERCENTILE_CONT

func PERCENTILE_CONT(fraction FloatExpression) *OrderSetAggregateFunc

PERCENTILE_CONT computes a value corresponding to the specified fraction within the ordered set of aggregated argument values. This will interpolate between adjacent input items if needed.

func PERCENTILE_DISC

func PERCENTILE_DISC(fraction FloatExpression) *OrderSetAggregateFunc

PERCENTILE_DISC computes the first value within the ordered set of aggregated argument values whose position in the ordering equals or exceeds the specified fraction. The aggregated argument must be of a sortable type.

func (*OrderSetAggregateFunc) WITHIN_GROUP_ORDER_BY

func (p *OrderSetAggregateFunc) WITHIN_GROUP_ORDER_BY(orderBy OrderByClause) Expression

WITHIN_GROUP_ORDER_BY specifies ordered set of aggregated argument values

type PrintableStatement

type PrintableStatement interface {
	Sql() (query string, args []interface{})
	DebugSql() (query string)
}

PrintableStatement is a statement which sql query can be logged

type Projection

type Projection interface {
	// contains filtered or unexported methods
}

Projection is interface for all projection types. Types that can be part of, for instance SELECT clause.

func ColumnListToProjectionList

func ColumnListToProjectionList(columns []ColumnExpression) []Projection

ColumnListToProjectionList func

type ProjectionList

type ProjectionList []Projection

ProjectionList is a redefined type, so that ProjectionList can be used as a Projection.

func (ProjectionList) As

func (pl ProjectionList) As(tableAlias string) ProjectionList

As will create new projection list where each column is wrapped with a new table alias. tableAlias should be in the form 'name' or 'name.*', or it can be an empty string, which will remove existing table alias. For instance: If projection list has a column 'Artist.Name', and tableAlias is 'Musician.*', returned projection list will have a column wrapped in alias 'Musician.Name'. If tableAlias is empty string, it removes existing table alias ('Artist.Name' becomes 'Name').

func (ProjectionList) Except

func (pl ProjectionList) Except(toExclude ...Column) ProjectionList

Except will create new projection list in which columns contained in excluded column names are removed

type QueryInfo

type QueryInfo struct {
	Statement PrintableStatement
	// Depending on how the statement is executed, RowsProcessed is:
	// 	- Number of rows returned for Query() and QueryContext() methods
	// 	- RowsAffected() for Exec() and ExecContext() methods
	// 	- Always 0 for Rows() method.
	RowsProcessed int64
	Duration      time.Duration
	Err           error
}

QueryInfo contains information about executed query

func (QueryInfo) Caller

func (q QueryInfo) Caller() (file string, line int, function string)

Caller returns information about statement caller

type QueryLoggerFunc

type QueryLoggerFunc func(ctx context.Context, info QueryInfo)

QueryLoggerFunc is a function user can implement to retrieve more information about statement executed.

type QueryPlaceholderFunc

type QueryPlaceholderFunc func(ord int) string

QueryPlaceholderFunc func

type Range

type Range[T Expression] interface {
	Expression

	EQ(rhs Range[T]) BoolExpression
	NOT_EQ(rhs Range[T]) BoolExpression

	LT(rhs Range[T]) BoolExpression
	LT_EQ(rhs Range[T]) BoolExpression
	GT(rhs Range[T]) BoolExpression
	GT_EQ(rhs Range[T]) BoolExpression

	CONTAINS(rhs T) BoolExpression
	CONTAINS_RANGE(rhs Range[T]) BoolExpression
	OVERLAP(rhs Range[T]) BoolExpression
	UNION(rhs Range[T]) Range[T]
	INTERSECTION(rhs Range[T]) Range[T]
	DIFFERENCE(rhs Range[T]) Range[T]

	UPPER_BOUND() T
	LOWER_BOUND() T
	IS_EMPTY() BoolExpression
	LOWER_INC() BoolExpression
	UPPER_INC() BoolExpression
	LOWER_INF() BoolExpression
	UPPER_INF() BoolExpression
}

Range Expression is interface for date range types

func DateRange

func DateRange(lowTs, highTs DateExpression, bounds ...StringExpression) Range[DateExpression]

func Int4Range

func Int4Range(lowNum, highNum IntegerExpression, bounds ...StringExpression) Range[Int4Expression]

func Int8Range

func Int8Range(lowNum, highNum Int8Expression, bounds ...StringExpression) Range[Int8Expression]

func NumRange

func NumRange(lowNum, highNum NumericExpression, bounds ...StringExpression) Range[NumericExpression]

func RangeExp

func RangeExp[T Expression](expression Expression) Range[T]

RangeExp is range expression wrapper around arbitrary expression. Allows go compiler to see any expression as range expression. Does not add sql cast to generated sql builder output.

func RawRange

func RawRange[T Expression](raw string, namedArgs ...map[string]interface{}) Range[T]

RawRange helper that for range expressions

func TsRange

func TsRange(lowTs, highTs TimestampExpression, bounds ...StringExpression) Range[TimestampExpression]

func TstzRange

func TstzRange(lowTs, highTs TimestampzExpression, bounds ...StringExpression) Range[TimestampzExpression]

type RowLock

type RowLock interface {
	Serializer

	OF(...Table) RowLock
	NOWAIT() RowLock
	SKIP_LOCKED() RowLock
}

RowLock is interface for SELECT statement row lock types

type Rows

type Rows struct {
	*sql.Rows
	// contains filtered or unexported fields
}

Rows wraps sql.Rows type with a support for query result mapping

func (*Rows) Scan

func (r *Rows) Scan(destination interface{}) error

Scan will map the Row values into struct destination

type SQLBuilder

type SQLBuilder struct {
	Dialect Dialect
	Buff    bytes.Buffer
	Args    []interface{}

	Debug bool
	// contains filtered or unexported fields
}

SQLBuilder generates output SQL

func (*SQLBuilder) DecreaseIdent

func (s *SQLBuilder) DecreaseIdent(ident ...int)

DecreaseIdent removes ident or defaultIdent number of spaces for each new line

func (*SQLBuilder) IncreaseIdent

func (s *SQLBuilder) IncreaseIdent(ident ...int)

IncreaseIdent adds ident or defaultIdent number of spaces to each new line

func (*SQLBuilder) NewLine

func (s *SQLBuilder) NewLine()

NewLine adds new line to output SQL

func (*SQLBuilder) WriteAlias

func (s *SQLBuilder) WriteAlias(str string)

WriteAlias is used to add alias to output SQL

func (*SQLBuilder) WriteByte

func (s *SQLBuilder) WriteByte(b byte)

WriteByte writes byte to output SQL

func (*SQLBuilder) WriteIdentifier

func (s *SQLBuilder) WriteIdentifier(name string, alwaysQuote ...bool)

WriteIdentifier adds identifier to output SQL

func (*SQLBuilder) WriteProjections

func (s *SQLBuilder) WriteProjections(statement StatementType, projections []Projection)

WriteProjections func

func (*SQLBuilder) WriteString

func (s *SQLBuilder) WriteString(str string)

WriteString writes sting to output SQL

type SelectTable

type SelectTable interface {
	SerializerHasProjections
	Alias() string
	AllColumns() ProjectionList
}

SelectTable is interface for SELECT sub-queries

func NewLateral

func NewLateral(selectStmt SerializerStatement, alias string) SelectTable

NewLateral creates new lateral expression from select statement with alias

type SerializeOption

type SerializeOption int

SerializeOption type

const (
	NoWrap SerializeOption = iota
	SkipNewLine
	Ident

	ShortName
)

Serialize options

func FallTrough

func FallTrough(options []SerializeOption) []SerializeOption

FallTrough filters fall-trough options from the list

func (SerializeOption) WithFallTrough

func (s SerializeOption) WithFallTrough(options []SerializeOption) []SerializeOption

WithFallTrough extends existing serialize options with additional

type SerializeOverride

type SerializeOverride func(expressions ...Serializer) SerializerFunc

SerializeOverride func

type Serializer

type Serializer interface {
	// contains filtered or unexported methods
}

Serializer interface

func ExpressionListToSerializerList

func ExpressionListToSerializerList(expressions []Expression) []Serializer

ExpressionListToSerializerList converts list of expressions to list of serializers

func NewSerializerClauseImpl

func NewSerializerClauseImpl(clauses ...Clause) Serializer

NewSerializerClauseImpl is constructor for Seralizer with list of clauses

func ToSerializerValue

func ToSerializerValue(value interface{}) Serializer

ToSerializerValue creates Serializer type from the value

func UnwindRowFromModel

func UnwindRowFromModel(columns []Column, data interface{}) []Serializer

UnwindRowFromModel func

func UnwindRowFromValues

func UnwindRowFromValues(value interface{}, values []interface{}) []Serializer

UnwindRowFromValues func

type SerializerFunc

type SerializerFunc func(statement StatementType, out *SQLBuilder, options ...SerializeOption)

SerializerFunc func

type SerializerHasProjections

type SerializerHasProjections interface {
	Serializer
	HasProjections
}

SerializerHasProjections interface is combination of Serializer and HasProjections interface

type SerializerStatement

type SerializerStatement interface {
	Serializer
	Statement
	HasProjections
}

SerializerStatement interface

func NewStatementImpl

func NewStatementImpl(Dialect Dialect, statementType StatementType, parent SerializerStatement, clauses ...Clause) SerializerStatement

NewStatementImpl creates new statementImpl

type SerializerTable

type SerializerTable interface {
	Serializer
	Table
}

SerializerTable interface

func NewTable

func NewTable(schemaName, name, alias string, columns ...ColumnExpression) SerializerTable

NewTable creates new table with schema Name, table Name and list of columns

type SetClause

type SetClause struct {
	Columns []Column
	Values  []Serializer
}

SetClause struct

func (*SetClause) Serialize

func (s *SetClause) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize serializes clause into SQLBuilder

type SetClauseNew

type SetClauseNew []ColumnAssigment

SetClauseNew clause

func (SetClauseNew) Serialize

func (s SetClauseNew) Serialize(statementType StatementType, out *SQLBuilder, options ...SerializeOption)

Serialize for SetClauseNew

type SetPair

type SetPair struct {
	Column ColumnSerializer
	Value  Serializer
}

SetPair clause

type Statement

type Statement interface {
	// Sql returns parametrized sql query with list of arguments.
	Sql() (query string, args []interface{})
	// DebugSql returns debug query where every parametrized placeholder is replaced with its argument string representation.
	// Do not use it in production. Use it only for debug purposes.
	DebugSql() (query string)
	// Query executes statement over database connection/transaction db and stores row results in destination.
	// Destination can be either pointer to struct or pointer to a slice.
	// If destination is pointer to struct and query result set is empty, method returns qrm.ErrNoRows.
	Query(db qrm.Queryable, destination interface{}) error
	// QueryContext executes statement with a context over database connection/transaction db and stores row result in destination.
	// Destination can be either pointer to struct or pointer to a slice.
	// If destination is pointer to struct and query result set is empty, method returns qrm.ErrNoRows.
	QueryContext(ctx context.Context, db qrm.Queryable, destination interface{}) error
	// Exec executes statement over db connection/transaction without returning any rows.
	Exec(db qrm.Executable) (sql.Result, error)
	// ExecContext executes statement with context over db connection/transaction without returning any rows.
	ExecContext(ctx context.Context, db qrm.Executable) (sql.Result, error)
	// Rows executes statements over db connection/transaction and returns rows
	Rows(ctx context.Context, db qrm.Queryable) (*Rows, error)
}

Statement is common interface for all statements(SELECT, INSERT, UPDATE, DELETE, LOCK)

func RawStatement

func RawStatement(dialect Dialect, rawQuery string, namedArgument ...map[string]interface{}) Statement

RawStatement creates new sql statements from raw query and optional map of named arguments

type StatementType

type StatementType string

StatementType is type of the SQL statement

const (
	SelectStatementType StatementType = "SELECT"
	InsertStatementType StatementType = "INSERT"
	UpdateStatementType StatementType = "UPDATE"
	DeleteStatementType StatementType = "DELETE"
	SetStatementType    StatementType = "SET"
	LockStatementType   StatementType = "LOCK"
	UnLockStatementType StatementType = "UNLOCK"
	WithStatementType   StatementType = "WITH"
)

Statement types

type StringExpression

type StringExpression interface {
	Expression

	EQ(rhs StringExpression) BoolExpression
	NOT_EQ(rhs StringExpression) BoolExpression
	IS_DISTINCT_FROM(rhs StringExpression) BoolExpression
	IS_NOT_DISTINCT_FROM(rhs StringExpression) BoolExpression

	LT(rhs StringExpression) BoolExpression
	LT_EQ(rhs StringExpression) BoolExpression
	GT(rhs StringExpression) BoolExpression
	GT_EQ(rhs StringExpression) BoolExpression
	BETWEEN(min, max StringExpression) BoolExpression
	NOT_BETWEEN(min, max StringExpression) BoolExpression

	CONCAT(rhs Expression) StringExpression

	LIKE(pattern StringExpression) BoolExpression
	NOT_LIKE(pattern StringExpression) BoolExpression

	REGEXP_LIKE(pattern StringExpression, caseSensitive ...bool) BoolExpression
	NOT_REGEXP_LIKE(pattern StringExpression, caseSensitive ...bool) BoolExpression
}

StringExpression interface

func BTRIM

func BTRIM(stringExpression StringExpression, trimChars ...StringExpression) StringExpression

BTRIM removes the longest string consisting only of characters in characters (a space by default) from the start and end of string

func CHR

func CHR(integerExpression IntegerExpression) StringExpression

CHR returns character with the given code.

func CONCAT

func CONCAT(expressions ...Expression) StringExpression

CONCAT adds two or more expressions together

func CONCAT_WS

func CONCAT_WS(separator Expression, expressions ...Expression) StringExpression

CONCAT_WS adds two or more expressions together with a separator.

func CONVERT

func CONVERT(str StringExpression, srcEncoding StringExpression, destEncoding StringExpression) StringExpression

CONVERT converts string to dest_encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding.

func CONVERT_FROM

func CONVERT_FROM(str StringExpression, srcEncoding StringExpression) StringExpression

CONVERT_FROM converts string to the database encoding. The original encoding is specified by src_encoding. The string must be valid in this encoding.

func CONVERT_TO

func CONVERT_TO(str StringExpression, toEncoding StringExpression) StringExpression

CONVERT_TO converts string to dest_encoding.

func DECODE

DECODE decodes binary data from textual representation in string. Options for format are same as in encode.

func ENCODE

ENCODE encodes binary data into a textual representation. Supported formats are: base64, hex, escape. escape converts zero bytes and high-bit-set bytes to octal sequences (\nnn) and doubles backslashes.

func FORMAT

func FORMAT(formatStr StringExpression, formatArgs ...Expression) StringExpression

FORMAT formats a number to a format like "#,###,###.##", rounded to a specified number of decimal places, then it returns the result as a string.

func INITCAP

INITCAP converts the first letter of each word to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters.

func LEFT

LEFT returns first n characters in the string. When n is negative, return all but last |n| characters.

func LENGTH

func LENGTH(str StringExpression, encoding ...StringExpression) StringExpression

LENGTH returns number of characters in string with a given encoding

func LOWER

func LOWER(stringExpression StringExpression) StringExpression

LOWER returns string expression in lower case

func LPAD

LPAD fills up the string to length length by prepending the characters fill (a space by default). If the string is already longer than length then it is truncated (on the right).

func LTRIM

func LTRIM(str StringExpression, trimChars ...StringExpression) StringExpression

LTRIM removes the longest string containing only characters from characters (a space by default) from the start of string

func MD5

func MD5(stringExpression StringExpression) StringExpression

MD5 calculates the MD5 hash of string, returning the result in hexadecimal

func NewEnumValue

func NewEnumValue(name string) StringExpression

NewEnumValue creates new named enum value

func NewStringFunc

func NewStringFunc(name string, expressions ...Expression) StringExpression

NewStringFunc creates new string function with name and expression parameters

func REPEAT

REPEAT repeats string the specified number of times

func REPLACE

func REPLACE(text, from, to StringExpression) StringExpression

REPLACE replaces all occurrences in string of substring from with substring to

func REVERSE

func REVERSE(stringExpression StringExpression) StringExpression

REVERSE returns reversed string.

RIGHT returns last n characters in the string. When n is negative, return all but first |n| characters.

func RPAD

RPAD fills up the string to length length by appending the characters fill (a space by default). If the string is already longer than length then it is truncated.

func RTRIM

func RTRIM(str StringExpression, trimChars ...StringExpression) StringExpression

RTRIM removes the longest string containing only characters from characters (a space by default) from the end of string

func RawString

func RawString(raw string, namedArgs ...map[string]interface{}) StringExpression

RawString helper that for string expressions

func SUBSTR

SUBSTR extracts substring

func String

func String(value string) StringExpression

String creates new string literal expression

func StringExp

func StringExp(expression Expression) StringExpression

StringExp is string expression wrapper around arbitrary expression. Allows go compiler to see any expression as string expression. Does not add sql cast to generated sql builder output.

func TO_ASCII

func TO_ASCII(str StringExpression, encoding ...StringExpression) StringExpression

TO_ASCII convert string to ASCII from another encoding

func TO_CHAR

func TO_CHAR(expression Expression, format StringExpression) StringExpression

TO_CHAR converts expression to string with format

func TO_HEX

func TO_HEX(number IntegerExpression) StringExpression

TO_HEX converts number to its equivalent hexadecimal representation

func UPPER

func UPPER(stringExpression StringExpression) StringExpression

UPPER returns string expression in upper case

func UUID

func UUID(value fmt.Stringer) StringExpression

UUID is a helper function to create string literal expression from uuid object value can be any uuid type with a String method

type Table

type Table interface {
	SchemaName() string
	TableName() string
	Alias() string
	// contains filtered or unexported methods
}

Table interface

type TimeExpression

type TimeExpression interface {
	Expression

	EQ(rhs TimeExpression) BoolExpression
	NOT_EQ(rhs TimeExpression) BoolExpression
	IS_DISTINCT_FROM(rhs TimeExpression) BoolExpression
	IS_NOT_DISTINCT_FROM(rhs TimeExpression) BoolExpression

	LT(rhs TimeExpression) BoolExpression
	LT_EQ(rhs TimeExpression) BoolExpression
	GT(rhs TimeExpression) BoolExpression
	GT_EQ(rhs TimeExpression) BoolExpression
	BETWEEN(min, max TimeExpression) BoolExpression
	NOT_BETWEEN(min, max TimeExpression) BoolExpression

	ADD(rhs Interval) TimeExpression
	SUB(rhs Interval) TimeExpression
}

TimeExpression interface

func LOCALTIME

func LOCALTIME(precision ...int) TimeExpression

LOCALTIME returns local time of day using optional precision

func RawTime

func RawTime(raw string, namedArgs ...map[string]interface{}) TimeExpression

RawTime helper that for time expressions

func Time

func Time(hour, minute, second int, nanoseconds ...time.Duration) TimeExpression

Time creates new time literal expression

func TimeExp

func TimeExp(expression Expression) TimeExpression

TimeExp is time expression wrapper around arbitrary expression. Allows go compiler to see any expression as time expression. Does not add sql cast to generated sql builder output.

func TimeT

func TimeT(t time.Time) TimeExpression

TimeT creates new time literal expression from time.Time object

type TimestampExpression

TimestampExpression interface

func LOCALTIMESTAMP

func LOCALTIMESTAMP(precision ...int) TimestampExpression

LOCALTIMESTAMP returns current date and time using optional precision

func RawTimestamp

func RawTimestamp(raw string, namedArgs ...map[string]interface{}) TimestampExpression

RawTimestamp helper that for timestamp expressions

func Timestamp

func Timestamp(year int, month time.Month, day, hour, minute, second int, nanoseconds ...time.Duration) TimestampExpression

Timestamp creates new timestamp literal expression

func TimestampExp

func TimestampExp(expression Expression) TimestampExpression

TimestampExp is timestamp expression wrapper around arbitrary expression. Allows go compiler to see any expression as timestamp expression. Does not add sql cast to generated sql builder output.

func TimestampT

func TimestampT(t time.Time) TimestampExpression

TimestampT creates new timestamp literal expression from time.Time object

type TimestampzExpression

TimestampzExpression interface

func CURRENT_TIMESTAMP

func CURRENT_TIMESTAMP(precision ...int) TimestampzExpression

CURRENT_TIMESTAMP returns current timestamp with time zone

func NOW

NOW returns current date and time

func RawTimestampz

func RawTimestampz(raw string, namedArgs ...map[string]interface{}) TimestampzExpression

RawTimestampz helper that for timestamp with time zone expressions

func TO_TIMESTAMP

func TO_TIMESTAMP(timestampzStr, format StringExpression) TimestampzExpression

TO_TIMESTAMP converts string to time stamp with time zone using format

func Timestampz

func Timestampz(year int, month time.Month, day, hour, minute, second int, nanoseconds time.Duration, timezone string) TimestampzExpression

Timestampz creates new timestamp with time zone literal expression

func TimestampzExp

func TimestampzExp(expression Expression) TimestampzExpression

TimestampzExp is timestamp with time zone expression wrapper around arbitrary expression. Allows go compiler to see any expression as timestamp with time zone expression. Does not add sql cast to generated sql builder output.

func TimestampzT

func TimestampzT(t time.Time) TimestampzExpression

TimestampzT creates new timestamp literal expression from time.Time object

type TimezExpression

TimezExpression interface for 'time with time zone' types

func CURRENT_TIME

func CURRENT_TIME(precision ...int) TimezExpression

CURRENT_TIME returns current time with time zone

func RawTimez

func RawTimez(raw string, namedArgs ...map[string]interface{}) TimezExpression

RawTimez helper that for time with time zone expressions

func Timez

func Timez(hour, minute, second int, nanoseconds time.Duration, timezone string) TimezExpression

Timez creates new time with time zone literal expression

func TimezExp

func TimezExp(expression Expression) TimezExpression

TimezExp is time with time zone expression wrapper around arbitrary expression. Allows go compiler to see any expression as time with time zone expression. Does not add sql cast to generated sql builder output.

func TimezT

func TimezT(t time.Time) TimezExpression

TimezT creates new time with time zone literal expression from time.Time object

type Token

type Token string

Token can be used to construct complex custom expressions

type Window

type Window interface {
	Serializer
	ORDER_BY(expr ...OrderByClause) Window
	ROWS(start FrameExtent, end ...FrameExtent) Window
	RANGE(start FrameExtent, end ...FrameExtent) Window
	GROUPS(start FrameExtent, end ...FrameExtent) Window
}

Window interface

func ORDER_BY

func ORDER_BY(expr ...OrderByClause) Window

ORDER_BY window function constructor

func PARTITION_BY

func PARTITION_BY(exp Expression, exprs ...Expression) Window

PARTITION_BY window function constructor

func WindowName

func WindowName(name string) Window

WindowName is used to specify window reference from WINDOW clause

type WindowDefinition

type WindowDefinition struct {
	Name   string
	Window Window
}

WindowDefinition struct

Jump to

Keyboard shortcuts

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