command

package
v0.0.0-...-65fd79d Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package command defines a command model, known as the intermediary representation. It can be compiled from an *ast.SQLStmt using a (compiler.Compiler).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddExpression

type AddExpression struct {
	BinaryBase
}

AddExpression represents the binary expression Left + Right.

func (AddExpression) String

func (e AddExpression) String() string

type BinaryBase

type BinaryBase struct {
	// Left is the left hand side argument of this binary expression.
	Left Expr
	// Right is the right hand side argument of this binary expression.
	Right Expr
}

BinaryBase is the base of a binary expression, implementing the Expr interface and holding the left and right hand side argument.

func (BinaryBase) LeftExpr

func (b BinaryBase) LeftExpr() Expr

LeftExpr returns the left hand side argument of the binary expression.

func (BinaryBase) RightExpr

func (b BinaryBase) RightExpr() Expr

RightExpr returns the right hand side argument of the binary expression.

type BinaryExpression

type BinaryExpression interface {
	Expr

	LeftExpr() Expr
	RightExpr() Expr
}

BinaryExpression describes an expression which has a left and a right hand side argument.

type Column

type Column struct {
	// Table is the table name that this column belongs to. May be empty, as
	// this is a representation derived from the AST. If this is empty, the
	// executor has to interpolate the table from the execution context.
	Table string
	// Expr is the name of the column.
	Expr Expr
	// Alias is the alias name for this table. May be empty.
	Alias string
}

Column represents a database table column.

func (Column) String

func (c Column) String() string

type ColumnDef

type ColumnDef struct {
	Name string
	Type types.Type
}

ColumnDef is a column definition.

type ColumnReference

type ColumnReference struct {
	Name string
}

ColumnReference is a string literal that represents a reference to a column. During resolving, if no column with such a name is present, an error must be risen.

func (ColumnReference) ReferencedColName

func (l ColumnReference) ReferencedColName() string

ReferencedColName returns the constant name of the referenced column name.

func (ColumnReference) String

func (l ColumnReference) String() string

type Command

type Command interface {
	fmt.Stringer
}

Command describes a structure that can be executed by the database executor. Instead of using bytecode, we use a hierarchical structure for the executor. This is mainly to increase readability.

type ConstantBooleanExpr

type ConstantBooleanExpr struct {
	// Value is the simple bool value of this expression.
	Value bool
}

ConstantBooleanExpr is a simple expression that represents a boolean value. It is rarely emitted by the compiler and rather used by optimizations.

func (ConstantBooleanExpr) String

func (b ConstantBooleanExpr) String() string

type ConstantLiteral

type ConstantLiteral struct {
	Value   string
	Numeric bool
}

ConstantLiteral is a constant literal expression. The Numeric flag determines whether or not this is a numeric literal.

func (ConstantLiteral) ConstantValue

func (l ConstantLiteral) ConstantValue() string

ConstantValue returns the constant value of this literal.

func (ConstantLiteral) String

func (l ConstantLiteral) String() string

type ConstantLiteralOrColumnReference

type ConstantLiteralOrColumnReference struct {
	ValueOrName string
}

ConstantLiteralOrColumnReference is a string literal that represents either a constant string value or a column reference. If this literal is resolved, the column reference takes precedence over the string literal, meaning that if a column exists, whose name is equal to the value of this expression, the value in that column must be used. Only if there is no such column present, the string literal is to be used.

func (ConstantLiteralOrColumnReference) ConstantValue

func (l ConstantLiteralOrColumnReference) ConstantValue() string

ConstantValue returns the constant value of this literal.

func (ConstantLiteralOrColumnReference) ReferencedColName

func (l ConstantLiteralOrColumnReference) ReferencedColName() string

ReferencedColName returns the constant name of the referenced column name.

func (ConstantLiteralOrColumnReference) String

type CreateTable

type CreateTable struct {
	// Overwrite determines whether an existing table with that name should be
	// replaced.
	Overwrite bool
	// Name is the name of the table to be created.
	Name string
	// ColumnDefs are the column definitions of the new table.
	ColumnDefs []ColumnDef
}

CreateTable instructs the executor to create a table according to this table definition.

func (CreateTable) String

func (c CreateTable) String() string

type Delete

type Delete struct {
	// Table is the table to delete datasets from.
	Table Table
	// Filter is an expression that a dataset has to match in order to be
	// deleted. This must not be nil. If all datasets from the table have to
	// be deleted, the filter will be a constant true expression.
	Filter Expr
}

Delete instructs the executor to delete all datasets from a table, that match the filter.

func (Delete) String

func (d Delete) String() string

type Distinct

type Distinct struct {
	// Input is the input list that is filtered.
	Input List
}

Distinct skips datasets from the list that already have been encountered and returns a list with only distinct entries.

func (Distinct) String

func (d Distinct) String() string

type DivExpression

type DivExpression struct {
	BinaryBase
}

DivExpression represents the binary expression Left / Right.

func (DivExpression) String

func (e DivExpression) String() string

type DropIndex

type DropIndex drop

DropIndex instructs the executor to drop the index with the name and schema defined in this command.

func (DropIndex) String

func (d DropIndex) String() string

type DropTable

type DropTable drop

DropTable instructs the executor to drop the table with the name and schema defined in this command.

func (DropTable) String

func (d DropTable) String() string

type DropTrigger

type DropTrigger drop

DropTrigger instructs the executor to drop the trigger with the name and schema defined in this command.

func (DropTrigger) String

func (d DropTrigger) String() string

type DropView

type DropView drop

DropView instructs the executor to drop the view with the name and schema defined in this command.

func (DropView) String

func (d DropView) String() string

type Empty

type Empty struct {
	// Cols are the columns in this empty list. This may be empty to
	// indicate a completely empty list.
	Cols []Column
}

Empty instructs the executor to consider an empty list of datasets.

func (Empty) String

func (e Empty) String() string

type EqualityExpr

type EqualityExpr struct {
	BinaryBase
	// Invert determines whether this equality expression must be considered
	// as in-equality expression.
	Invert bool
}

EqualityExpr represents the binary expression Left == Right. If Invert=true, the expression represents Left != Right.

func (EqualityExpr) String

func (e EqualityExpr) String() string

type Explain

type Explain struct {
	// Command is the command that will be explained, but not executed.
	Command Command
}

Explain instructs the executor to explain the nested command instead of executing it.

func (Explain) String

func (e Explain) String() string

type Expr

type Expr interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

Expr is a marker interface for anything that is an expression. Different implementations of this interface represent different productions of the expression rule in the SQL grammar.

type FunctionExpr

type FunctionExpr struct {
	// Name is the name of the function.
	Name string
	// Distinct determines, whether only distinct elements in the arguments'
	// input lists must be considered.
	Distinct bool
	// Args are the function argument expressions.
	Args []Expr
}

FunctionExpr represents a function call expression.

func (FunctionExpr) String

func (f FunctionExpr) String() string

type GreaterThanExpr

type GreaterThanExpr struct {
	BinaryBase
}

GreaterThanExpr represents the binary expression Left > Right.

func (GreaterThanExpr) String

func (e GreaterThanExpr) String() string

type GreaterThanOrEqualToExpr

type GreaterThanOrEqualToExpr struct {
	BinaryBase
}

GreaterThanOrEqualToExpr represents the binary expression Left >= Right.

func (GreaterThanOrEqualToExpr) String

func (e GreaterThanOrEqualToExpr) String() string

type Insert

type Insert struct {
	// InsertOr is the specified fallback to perform when the insertion
	// fails.
	InsertOr InsertOr
	// Table is the specified table, where the input list is inserted into.
	Table Table
	// Cols are the columns, which are modified. The columns of the input
	// list have to match these columns.
	Cols []Column
	// DefaultValues determines whether to insert default values for all
	// (specified) columns. If this is set to true, the input list must not
	// be present.
	DefaultValues bool
	// Input is the input list of datasets, that will be inserted.
	Input List
}

Insert instructs the executor to insert the input list into the specified table. The specified columns must match the columns from the input list.

func (Insert) String

func (i Insert) String() string

type InsertOr

type InsertOr uint8

InsertOr is the type of insert alternative that is specified in an insert statement.

const (
	InsertOrUnknown InsertOr = iota
	InsertOrReplace
	InsertOrRollback
	InsertOrAbort
	InsertOrFail
	InsertOrIgnore
)

Known InsertOrs

func (InsertOr) String

func (i InsertOr) String() string

type Join

type Join struct {
	// Natural indicates whether this join is a natural one.
	Natural bool
	// Type is the type of join that this join is.
	Type JoinType
	// Filter defines the condition that has to apply to two datasets from
	// the left and right list in order to be merged.
	Filter Expr
	// Left is the left input list.
	Left List
	// Right is the right input list.
	Right List
}

Join instructs the executor to produce a list from the left and right input list. Lists are merged with respect to the given filter.

func (Join) String

func (j Join) String() string

type JoinType

type JoinType uint8

JoinType is a type of join.

const (
	JoinUnknown JoinType = iota
	JoinLeft
	JoinLeftOuter
	JoinInner
	JoinCross
)

Known join types.

func (JoinType) String

func (i JoinType) String() string

type LessThanExpr

type LessThanExpr struct {
	BinaryBase
}

LessThanExpr represents the binary expression Left < Right.

func (LessThanExpr) String

func (e LessThanExpr) String() string

type LessThanOrEqualToExpr

type LessThanOrEqualToExpr struct {
	BinaryBase
}

LessThanOrEqualToExpr represents the binary expression Left <= Right.

func (LessThanOrEqualToExpr) String

func (e LessThanOrEqualToExpr) String() string

type Limit

type Limit struct {
	// Limit is the amount of datasets that are respected from the input
	// list (top to bottom).
	Limit Expr
	// Input is the input list of datasets.
	Input List
}

Limit instructs the executor to only respect the first Limit datasets from the input list.

func (Limit) String

func (l Limit) String() string

type List

type List interface {
	Command
	// contains filtered or unexported methods
}

List is a marker interface that facilitates creating a type hierarchy for the command model.

type ModExpression

type ModExpression struct {
	BinaryBase
}

ModExpression represents the binary expression Left % Right.

func (ModExpression) String

func (e ModExpression) String() string

type MulExpression

type MulExpression struct {
	BinaryBase
}

MulExpression represents the binary expression Left * Right.

func (MulExpression) String

func (e MulExpression) String() string

type Offset

type Offset struct {
	// Offset is the amount of datasets that should be skipped from the
	// input list.
	Offset Expr
	// Input is the input list to truncate.
	Input List
}

Offset instructs to executor to skip the first Offset datasets from the input list and return that truncated list. When used together with Limit, please notice that the function composition (Limit ∘ Offset)(x) is not commutative.

func (Offset) String

func (o Offset) String() string

type PowExpression

type PowExpression struct {
	BinaryBase
}

PowExpression represents the binary expression Left ** Right.

func (PowExpression) String

func (e PowExpression) String() string

type Project

type Project struct {
	// Cols are the columns that this projection projects. Most of the time,
	// this will be the columns from the SELECT statement.
	Cols []Column
	// Input is the input list over which the projection takes place.
	Input List
}

Project represents a projection that should be performed by the executor over the nested input. The projected columns are specified in (command.Project).Cols.

func (Project) String

func (p Project) String() string

type RangeExpr

type RangeExpr struct {
	// Needle is the value that is evaluated if it is between Lo and Hi.
	Needle Expr
	// Lo is the lower bound of this range.
	Lo Expr
	// Hi is the upper bound of this range.
	Hi Expr
	// Invert determines if Needle must be between or not between the bounds
	// of this range.
	Invert bool
}

RangeExpr is an expression with a needle, an upper and a lower bound. It must be evaluated to true, if needle is within the lower and upper bound, or if the needle is not between the bounds and the range is inverted.

func (RangeExpr) String

func (r RangeExpr) String() string

type Scan

type Scan struct {
	// Table is the table whose contents will be used.
	Table Table
}

Scan instructs the executor to use the contents of the nested table. It is up to the executor whether he performs a full table scan or applies possible optimizations, like a search through indices.

func (Scan) String

func (s Scan) String() string

type Select

type Select struct {
	// Filter is an expression that filters elements in this selection to
	// only elements, that pass this filter.
	Filter Expr
	// Input is the input list over which the selection takes place.
	Input List
}

Select represents a selection that should be performed by the executor over the nested input. Additionally, a filter can be specified which must be respected by the executor.

func (Select) String

func (s Select) String() string

type SimpleTable

type SimpleTable struct {
	// Schema name of the table. May be empty.
	Schema string
	// Table name of this table. Since this is a simple table, the table
	// name is a string and not an expression. Use other Table
	// implementations for more complex tables.
	Table string
	// Alias name of this table. May be empty.
	Alias string
	// Indexed indicates, whether this table is indexed by an index. If this
	// is false, Index must be the empty string.
	Indexed bool
	// Index is the name of the index that indexed this table, or empty, if
	// Indexed is false.
	Index string
}

SimpleTable is a table that is only specified by schema and table name, and an optional alias. It is also optionally indexed by an index.

SimpleTable represents the first grammar production of table-or-subquery.

func (SimpleTable) QualifiedName

func (t SimpleTable) QualifiedName() string

QualifiedName returns '<Schema>.<TableName>', or only '<TableName>' if no schema is specified.

func (SimpleTable) String

func (t SimpleTable) String() string

type SubExpression

type SubExpression struct {
	BinaryBase
}

SubExpression represents the binary expression Left - Right.

func (SubExpression) String

func (e SubExpression) String() string

type Table

type Table interface {
	QualifiedName() string
	// contains filtered or unexported methods
}

Table is a marker interface, allowing for different specifications of tables, such as a simple table, specified by schema and table name, or a more sophisticated table, such as a combination of multiple sub-tables or select statements.

type UnaryBase

type UnaryBase struct {
	Value Expr
}

UnaryBase is the base of all unary expressions, holding a single value.

type UnaryBitwiseNegationExpr

type UnaryBitwiseNegationExpr struct {
	UnaryBase
}

UnaryBitwiseNegationExpr represents the unary expression ~X, where X is the value of the expression.

func (UnaryBitwiseNegationExpr) String

func (e UnaryBitwiseNegationExpr) String() string

type UnaryNegationExpr

type UnaryNegationExpr struct {
	UnaryBase
}

UnaryNegationExpr represents the unary expression NOT X, where X is the value of the expression.

func (UnaryNegationExpr) String

func (e UnaryNegationExpr) String() string

type UnaryNegativeExpr

type UnaryNegativeExpr struct {
	UnaryBase
}

UnaryNegativeExpr represents the unary expression -X, where X is the value of the expression.

func (UnaryNegativeExpr) String

func (e UnaryNegativeExpr) String() string

type Update

type Update struct {
	// UpdateOr is the OR clause in an update statement.
	UpdateOr UpdateOr
	// Table is the table on which the update should be performed.
	Table Table
	// Updates is a list of updates that must be applied.
	Updates []UpdateSetter
	// Filter is the filter expression, that determines, which datasets are
	// to be updated.
	Filter Expr
}

Update instructs the executor to update all datasets, for which the filter expression evaluates to true, with the defined updates.

func (Update) String

func (u Update) String() string

type UpdateOr

type UpdateOr uint8

UpdateOr is the type of update alternative that is specified in an update statement.

const (
	UpdateOrUnknown UpdateOr = iota
	UpdateOrRollback
	UpdateOrAbort
	UpdateOrReplace
	UpdateOrFail
	UpdateOrIgnore
)

Known UpdateOrs

func (UpdateOr) String

func (i UpdateOr) String() string

type UpdateSetter

type UpdateSetter struct {
	// Cols are the columns of the dataset, that have to be updated. Because
	// the columns must be inside the table that this update refers to, and
	// no alias can be specified according to the grammar, this is just a
	// string, and not a full blown column.
	Cols []string
	// Value is the expression that the columns have to be set to.
	Value Expr
}

UpdateSetter is an update that can be applied to a value in a dataset.

func (UpdateSetter) String

func (u UpdateSetter) String() string

type Values

type Values struct {
	// Values are the values that represent the datasets in this list. Each
	// dataset consists of all expressions that are in the dataset.
	Values [][]Expr
}

Values returns a list of datasets from the evaluated expressions.

func (Values) String

func (v Values) String() string

Jump to

Keyboard shortcuts

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