command

package
v0.0.0-...-f5d25ad Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 3 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 BinaryExpr

type BinaryExpr struct {
	// Operator is the binary operator of the expression.
	Operator string
	// Left is the left hand side argument of the operator.
	Left Expr
	// Right is the right hand side argument of the operator.
	Right Expr
}

BinaryExpr represents a binary expression of the form <Left><Operand><Right>.

func (BinaryExpr) String

func (e BinaryExpr) String() string

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
	// Column is the name of the column.
	Column 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 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 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 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 {
	// Left is the left hand side expression.
	Left Expr
	// Right is the right hand side expression.
	Right Expr
	// Invert determines whether this equality expression must be considered
	// as in-equality expression.
	Invert bool
}

EqualityExpr is an expression with a left and right side expression, and represents the condition that both expressions are equal. If this equality expression is inverted, the condition is, that both sides are un-equal.

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

type LiteralExpr struct {
	// Value is the simple string value of this expression.
	Value string
}

LiteralExpr is a simple literal expression that has a single string value.

func (LiteralExpr) String

func (l LiteralExpr) 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 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 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 UnaryExpr

type UnaryExpr struct {
	// Operator is the unary operator of the expression.
	Operator string
	// Value is the value that the unary operator operates on.
	Value Expr
}

UnaryExpr represents a unary expression of the form <Operand><Value>.

func (UnaryExpr) String

func (e UnaryExpr) 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