sql

package
v0.0.0-...-630ccd6 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArithOperator

type ArithOperator string

ArithOperator - arithmetic operator.

const (
	// Add operator '+'.
	Add ArithOperator = "+"

	// Subtract operator '-'.
	Subtract ArithOperator = "-"

	// Multiply operator '*'.
	Multiply ArithOperator = "*"

	// Divide operator '/'.
	Divide ArithOperator = "/"

	// Modulo operator '%'.
	Modulo ArithOperator = "%"
)

type ComparisonOperator

type ComparisonOperator string

ComparisonOperator - comparison operator.

const (
	// Equal operator '='.
	Equal ComparisonOperator = "="

	// NotEqual operator '!=' or '<>'.
	NotEqual ComparisonOperator = "!="

	// LessThan operator '<'.
	LessThan ComparisonOperator = "<"

	// GreaterThan operator '>'.
	GreaterThan ComparisonOperator = ">"

	// LessThanEqual operator '<='.
	LessThanEqual ComparisonOperator = "<="

	// GreaterThanEqual operator '>='.
	GreaterThanEqual ComparisonOperator = ">="

	// Between operator 'BETWEEN'
	Between ComparisonOperator = "between"

	// In operator 'IN'
	In ComparisonOperator = "in"

	// Like operator 'LIKE'
	Like ComparisonOperator = "like"

	// NotBetween operator 'NOT BETWEEN'
	NotBetween ComparisonOperator = "not between"

	// NotIn operator 'NOT IN'
	NotIn ComparisonOperator = "not in"

	// NotLike operator 'NOT LIKE'
	NotLike ComparisonOperator = "not like"

	// IsNull operator 'IS NULL'
	IsNull ComparisonOperator = "is null"

	// IsNotNull operator 'IS NOT NULL'
	IsNotNull ComparisonOperator = "is not null"
)

func (ComparisonOperator) String

func (operator ComparisonOperator) String() string

String - returns string representation of this operator.

type Expr

type Expr interface {
	AggregateValue() (*Value, error)
	Eval(record Record) (*Value, error)
	ReturnType() Type
	Type() Type
}

Expr - a SQL expression type.

type FuncName

type FuncName string

FuncName - SQL function name.

const (
	// Avg - aggregate SQL function AVG().
	Avg FuncName = "AVG"

	// Count - aggregate SQL function COUNT().
	Count FuncName = "COUNT"

	// Max - aggregate SQL function MAX().
	Max FuncName = "MAX"

	// Min - aggregate SQL function MIN().
	Min FuncName = "MIN"

	// Sum - aggregate SQL function SUM().
	Sum FuncName = "SUM"

	// Coalesce - conditional SQL function COALESCE().
	Coalesce FuncName = "COALESCE"

	// NullIf - conditional SQL function NULLIF().
	NullIf FuncName = "NULLIF"

	// ToTimestamp - conversion SQL function TO_TIMESTAMP().
	ToTimestamp FuncName = "TO_TIMESTAMP"

	// UTCNow - date SQL function UTCNOW().
	UTCNow FuncName = "UTCNOW"

	// CharLength - string SQL function CHAR_LENGTH().
	CharLength FuncName = "CHAR_LENGTH"

	// CharacterLength - string SQL function CHARACTER_LENGTH() same as CHAR_LENGTH().
	CharacterLength FuncName = "CHARACTER_LENGTH"

	// Lower - string SQL function LOWER().
	Lower FuncName = "LOWER"

	// Substring - string SQL function SUBSTRING().
	Substring FuncName = "SUBSTRING"

	// Trim - string SQL function TRIM().
	Trim FuncName = "TRIM"

	// Upper - string SQL function UPPER().
	Upper FuncName = "UPPER"
)

type Record

type Record interface {
	Get(name string) (*Value, error)
	Set(name string, value *Value) error
	MarshalCSV(fieldDelimiter rune) ([]byte, error)
	MarshalJSON() ([]byte, error)
}

Record - is a type containing columns and their values.

type Select

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

Select - SQL Select statement.

func NewSelect

func NewSelect(sql string) (*Select, error)

NewSelect - creates new Select by parsing sql.

func (*Select) AggregateResult

func (statement *Select) AggregateResult(output Record) error

AggregateResult - returns aggregate result as record.

func (*Select) Eval

func (statement *Select) Eval(input, output Record) (Record, error)

Eval - evaluates this Select expressions for given record.

func (*Select) IsAggregated

func (statement *Select) IsAggregated() bool

IsAggregated - returns whether aggregated functions are used in select expression or not.

func (*Select) IsSelectAll

func (statement *Select) IsSelectAll() bool

IsSelectAll - returns whether '*' is used in select expression or not.

func (*Select) TableAlias

func (statement *Select) TableAlias() string

TableAlias - returns table alias name.

type Type

type Type string

Type - value type.

const (
	// Null - represents NULL value type.
	Null Type = "null"

	// Bool - represents boolean value type.
	Bool Type = "bool"

	// Int - represents integer value type.
	Int Type = "int"

	// Float - represents floating point value type.
	Float Type = "float"

	// String - represents string value type.
	String Type = "string"

	// Timestamp - represents time value type.
	Timestamp Type = "timestamp"

	// Array - represents array of values where each value type is one of above.
	Array Type = "array"
)

type Value

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

Value - represents any primitive value of bool, int, float, string and time.

func NewArray

func NewArray(values []*Value) *Value

NewArray - creates new Array value of values.

func NewBool

func NewBool(b bool) *Value

NewBool - creates new Bool value of b.

func NewFloat

func NewFloat(f float64) *Value

NewFloat - creates new Float value of f.

func NewInt

func NewInt(i int64) *Value

NewInt - creates new Int value of i.

func NewNull

func NewNull() *Value

NewNull - creates new null value.

func NewString

func NewString(s string) *Value

NewString - creates new Sring value of s.

func NewTime

func NewTime(t time.Time) *Value

NewTime - creates new Time value of t.

func NewValue

func NewValue(v *sqlparser.SQLVal) (*Value, error)

NewValue - creates new Value from SQLVal v.

func (*Value) ArrayValue

func (value *Value) ArrayValue() []*Value

ArrayValue - returns underlying value array. It panics if value is not Array type.

func (*Value) BoolValue

func (value *Value) BoolValue() bool

BoolValue - returns underlying bool value. It panics if value is not Bool type.

func (*Value) CSVString

func (value *Value) CSVString() string

CSVString - encodes to CSV string.

func (*Value) FloatValue

func (value *Value) FloatValue() float64

FloatValue - returns underlying int/float value as float64. It panics if value is not Int/Float type.

func (*Value) IntValue

func (value *Value) IntValue() int64

IntValue - returns underlying int value. It panics if value is not Int type.

func (*Value) MarshalJSON

func (value *Value) MarshalJSON() ([]byte, error)

MarshalJSON - encodes to JSON data.

func (*Value) NullValue

func (value *Value) NullValue() *struct{}

NullValue - returns underlying null value. It panics if value is not null type.

func (*Value) String

func (value *Value) String() string

String - represents value as string.

func (*Value) StringValue

func (value *Value) StringValue() string

StringValue - returns underlying string value. It panics if value is not String type.

func (*Value) TimeValue

func (value *Value) TimeValue() time.Time

TimeValue - returns underlying time value. It panics if value is not Timestamp type.

func (*Value) Type

func (value *Value) Type() Type

Type - returns value type.

func (*Value) Value

func (value *Value) Value() interface{}

Value - returns underneath value interface.

Jump to

Keyboard shortcuts

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