jet

package
v2.1.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2019 License: Apache-2.0, BSD-3-Clause, MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

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

Operators

View Source
const (
	// DEFAULT is jet equivalent of SQL DEFAULT
	DEFAULT keywordClause = "DEFAULT"
)

Variables

View Source
var (
	// NULL is jet equivalent of SQL NULL
	NULL = newNullLiteral()
	// STAR is jet equivalent of SQL *
	STAR = newStarLiteral()
)
View Source
var (
	UNBOUNDED   = keywordClause("UNBOUNDED")
	CURRENT_ROW = frameExtentKeyword{"CURRENT ROW"}
)

Window function keywords

Functions

func AVG

func AVG(numericExpression NumericExpression) 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 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 NewFloatWindowFunc

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

NewFloatWindowFunc creates new float function with name and expressions

func NewRowLock

func NewRowLock(name string) func() RowLock

NewRowLock creates new RowLock

func NewTimestampFunc

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

NewTimestampFunc creates new timestamp function with name and expressions

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 SerializeColumnNames

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

SerializeColumnNames func

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 UnwindRowsFromModels

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

UnwindRowsFromModels func

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

func EXISTS(subQuery Expression) BoolExpression

EXISTS checks for existence of the rows in subQuery

func NOT

NOT returns negation of bool expression result

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.

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

Clause interface

type ClauseDelete

type ClauseDelete struct {
	Table SerializerTable
}

ClauseDelete struct

func (*ClauseDelete) Serialize

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

Serialize serializes clause into SQLBuilder

type ClauseFor

type ClauseFor struct {
	Lock RowLock
}

ClauseFor struct

func (*ClauseFor) Serialize

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

Serialize serializes clause into SQLBuilder

type ClauseFrom

type ClauseFrom struct {
	Table Serializer
}

ClauseFrom struct

func (*ClauseFrom) Serialize

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

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)

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)

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)

Serialize serializes clause into SQLBuilder

type ClauseInsert

type ClauseInsert struct {
	Table   SerializerTable
	Columns []Column
}

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)

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)

Serialize serializes clause into SQLBuilder

type ClauseOffset

type ClauseOffset struct {
	Count int64
}

ClauseOffset struct

func (*ClauseOffset) Serialize

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

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)

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)

Serialize serializes clause into SQLBuilder

type ClauseQuery

type ClauseQuery struct {
	Query SerializerStatement
}

ClauseQuery struct

func (*ClauseQuery) Serialize

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

Serialize serializes clause into SQLBuilder

type ClauseSelect

type ClauseSelect struct {
	Distinct    bool
	Projections []Projection
}

ClauseSelect struct

func (*ClauseSelect) Serialize

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

Serialize serializes clause into SQLBuilder

type ClauseSet

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

ClauseSet struct

func (*ClauseSet) Serialize

func (s *ClauseSet) Serialize(statementType StatementType, out *SQLBuilder)

Serialize serializes clause into SQLBuilder

type ClauseSetStmtOperator

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

ClauseSetStmtOperator struct

func (*ClauseSetStmtOperator) Serialize

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

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)

Serialize serializes clause into SQLBuilder

type ClauseUpdate

type ClauseUpdate struct {
	Table SerializerTable
}

ClauseUpdate struct

func (*ClauseUpdate) Serialize

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

Serialize serializes clause into SQLBuilder

type ClauseValues

type ClauseValues struct {
	Rows [][]Serializer
}

ClauseValues struct

func (*ClauseValues) Serialize

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

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)

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)

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)

Serialize serializes clause into SQLBuilder

type ClauseWithProjections

type ClauseWithProjections interface {
	Clause
	// contains filtered or unexported methods
}

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 ColumnBool

type ColumnBool interface {
	BoolExpression
	Column

	From(subQuery SelectTable) ColumnBool
}

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
}

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 ColumnFloat

type ColumnFloat interface {
	FloatExpression
	Column

	From(subQuery SelectTable) ColumnFloat
}

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
}

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

func (cl ColumnList) Name() string

Name is placeholder for ColumnList to implement Column interface

func (ColumnList) TableName

func (cl ColumnList) TableName() string

TableName is placeholder for ColumnList to implement Column interface

type ColumnString

type ColumnString interface {
	StringExpression
	Column

	From(subQuery SelectTable) ColumnString
}

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
}

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
}

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
}

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
}

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 DateExpression

type DateExpression interface {
	Expression

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

	LT(rhs DateExpression) BoolExpression
	LT_EQ(rhs DateExpression) BoolExpression
	GT(rhs DateExpression) BoolExpression
	GT_EQ(rhs DateExpression) BoolExpression
}

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

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
}

DialectParams struct

type Expression

type Expression interface {
	Serializer
	Projection
	GroupByClause
	OrderByClause

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

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

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

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

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

func COALESCE

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

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

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 NULLIF

func NULLIF(value1, value2 Expression) Expression

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

func ROW

func ROW(expressions ...Expression) Expression

ROW is construct one table row from list of expressions.

func Raw

func Raw(raw string) Expression

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

func WRAP

func WRAP(expression ...Expression) Expression

WRAP wraps list of expressions with brackets '(' and ')'

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 FLOOR

func FLOOR(floatExpression FloatExpression) FloatExpression

FLOOR calculates floor of float expression

func Float

func Float(value float64) FloatExpression

Float creates new float literal

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

type HasProjections

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

HasProjections interface

type IntegerExpression

type IntegerExpression interface {
	Expression

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

	// Check if expression is less then rhs
	LT(rhs IntegerExpression) BoolExpression
	// Check if expression is less then equal rhs
	LT_EQ(rhs IntegerExpression) BoolExpression
	// Check if expression is greater then rhs
	GT(rhs IntegerExpression) BoolExpression
	// Check if expression is greater then equal rhs
	GT_EQ(rhs IntegerExpression) BoolExpression

	// expression + rhs
	ADD(rhs IntegerExpression) IntegerExpression
	// expression - rhs
	SUB(rhs IntegerExpression) IntegerExpression
	// expression * rhs
	MUL(rhs IntegerExpression) IntegerExpression
	// expression / rhs
	DIV(rhs IntegerExpression) IntegerExpression
	// expression % rhs
	MOD(rhs IntegerExpression) IntegerExpression
	// expression ^ rhs
	POW(rhs IntegerExpression) IntegerExpression

	// expression & rhs
	BIT_AND(rhs IntegerExpression) IntegerExpression
	// expression | rhs
	BIT_OR(rhs IntegerExpression) IntegerExpression
	// expression # rhs
	BIT_XOR(rhs IntegerExpression) IntegerExpression
	// expression << rhs
	BIT_SHIFT_LEFT(shift IntegerExpression) IntegerExpression
	// expression >> rhs
	BIT_SHIFT_RIGHT(shift IntegerExpression) IntegerExpression
	// contains filtered or unexported methods
}

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 Int

func Int(value int64) IntegerExpression

Int creates new 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 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)

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 LiteralExpression

type LiteralExpression interface {
	Expression

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

LiteralExpression is representation of an escaped literal

type NumericExpression

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

NumericExpression is common interface for all integer and float expressions

type OrderByClause

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

OrderByClause interface

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.

type QueryPlaceholderFunc

type QueryPlaceholderFunc func(ord int) string

QueryPlaceholderFunc func

type RowLock

type RowLock interface {
	Serializer

	NOWAIT() RowLock
	SKIP_LOCKED() RowLock
}

RowLock is interface for SELECT statement row lock types

type SQLBuilder

type SQLBuilder struct {
	Dialect Dialect
	Buff    bytes.Buffer
	Args    []interface{}
	// 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 {
	Serializer
	Alias() string
	AllColumns() ProjectionList
}

SelectTable is interface for SELECT sub-queries

func NewSelectTable

func NewSelectTable(selectStmt StatementWithProjections, alias string) SelectTable

NewSelectTable func

type SerializeFunc

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

SerializeFunc func

type SerializeOption

type SerializeOption int

SerializeOption type

type SerializeOverride

type SerializeOverride func(expressions ...Expression) SerializeFunc

SerializeOverride func

type Serializer

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

Serializer interface

func UnwindRowFromModel

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

UnwindRowFromModel func

func UnwindRowFromValues

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

UnwindRowFromValues func

type SerializerStatement

type SerializerStatement interface {
	Serializer
	Statement
}

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 string, column ColumnExpression, columns ...ColumnExpression) SerializerTable

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

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.
	// Do not use it in production. Use it only for debug purposes.
	DebugSql() (query string)

	// Query executes statement over database connection 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.
	Query(db qrm.DB, destination interface{}) error
	// QueryContext executes statement with a context over database connection 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(context context.Context, db qrm.DB, destination interface{}) error

	//Exec executes statement over db connection without returning any rows.
	Exec(db qrm.DB) (sql.Result, error)
	//Exec executes statement with context over db connection without returning any rows.
	ExecContext(context context.Context, db qrm.DB) (sql.Result, error)
}

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

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

Statement types

type StatementWithProjections

type StatementWithProjections interface {
	Statement
	HasProjections
	Serializer
}

StatementWithProjections interface

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

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

type Table

type Table interface {
	SchemaName() string
	TableName() string
	AS(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
}

TimeExpression interface

func LOCALTIME

func LOCALTIME(precision ...int) TimeExpression

LOCALTIME returns local time of day using optional precision

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

type TimezExpression interface {
	Expression

	//EQ
	EQ(rhs TimezExpression) BoolExpression
	//NOT_EQ
	NOT_EQ(rhs TimezExpression) BoolExpression
	//IS_DISTINCT_FROM
	IS_DISTINCT_FROM(rhs TimezExpression) BoolExpression
	//IS_NOT_DISTINCT_FROM
	IS_NOT_DISTINCT_FROM(rhs TimezExpression) BoolExpression

	//LT
	LT(rhs TimezExpression) BoolExpression
	//LT_EQ
	LT_EQ(rhs TimezExpression) BoolExpression
	//GT
	GT(rhs TimezExpression) BoolExpression
	//GT_EQ
	GT_EQ(rhs TimezExpression) BoolExpression
}

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