sql

package
v0.0.0-...-e79d762 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DateLayout = "2006-01-02"

DateLayout is the layout of the MySQL date format in the representation Go understands.

View Source
const TimestampLayout = "2006-01-02 15:04:05"

TimestampLayout is the formatting string with the layout of the timestamp using the format of Go "time" package.

Variables

View Source
var (
	// ErrInvalidType is thrown when there is an unexpected type at some part of
	// the execution tree.
	ErrInvalidType = errors.NewKind("invalid type: %s")

	// ErrTableAlreadyExists is thrown when someone tries to create a
	// table with a name of an existing one
	ErrTableAlreadyExists = errors.NewKind("table with name %s already exists")

	// ErrTableNotFound is returned when the table is not available from the
	// current scope.
	ErrTableNotFound = errors.NewKind("table not found: %s")

	//ErrUnexpectedRowLength is thrown when the obtained row has more columns than the schema
	ErrUnexpectedRowLength = errors.NewKind("expected %d values, got %d")
)
View Source
var (
	// ErrIndexIDAlreadyRegistered is the error returned when there is already
	// an index with the same ID.
	ErrIndexIDAlreadyRegistered = errors.NewKind("an index with id %q has already been registered")

	// ErrIndexExpressionAlreadyRegistered is the error returned when there is
	// already an index with the same expression.
	ErrIndexExpressionAlreadyRegistered = errors.NewKind("there is already an index registered for the expressions: %s")

	// ErrIndexNotFound is returned when the index could not be found.
	ErrIndexNotFound = errors.NewKind("index %q	was not found")

	// ErrIndexDeleteInvalidStatus is returned when the index trying to delete
	// does not have a ready state.
	ErrIndexDeleteInvalidStatus = errors.NewKind("can't delete index %q because it's not ready for usage")
)
View Source
var (
	// ErrNodeNotWritten is returned when the children are printed before the node.
	ErrNodeNotWritten = errors.New("treeprinter: a child was written before the node")
	// ErrNodeAlreadyWritten is returned when the node has already been written.
	ErrNodeAlreadyWritten = errors.New("treeprinter: node already written")
	// ErrChildrenAlreadyWritten is returned when the children have already been written.
	ErrChildrenAlreadyWritten = errors.New("treeprinter: children already written")
)
View Source
var (
	// ErrTypeNotSupported is thrown when a specific type is not supported
	ErrTypeNotSupported = errors.NewKind("Type not supported: %s")

	// ErrUnexpectedType is thrown when a received type is not the expected
	ErrUnexpectedType = errors.NewKind("value at %d has unexpected type: %s")

	// ErrConvertingToTime is thrown when a value cannot be converted to a Time
	ErrConvertingToTime = errors.NewKind("value %q can't be converted to time.Time")

	// ErrValueNotNil is thrown when a value that was expected to be nil, is not
	ErrValueNotNil = errors.NewKind("value not nil: %#v")

	// ErrNotTuple is retuned when the value is not a tuple.
	ErrNotTuple = errors.NewKind("value of type %T is not a tuple")

	// ErrInvalidColumnNumber is returned when a tuple has an invalid number of
	// arguments.
	ErrInvalidColumnNumber = errors.NewKind("tuple should contain %d column(s), but has %d")

	// ErrNotArray is returned when the value is not an array.
	ErrNotArray = errors.NewKind("value of type %T is not an array")
)
View Source
var (
	// Null represents the null type.
	Null nullT

	// Int32 is an integer of 32 bits.
	Int32 = numberT{/* contains filtered or unexported fields */}
	// Int64 is an integer of 64 bytes.
	Int64 = numberT{/* contains filtered or unexported fields */}
	// Uint32 is an unsigned integer of 32 bytes.
	Uint32 = numberT{/* contains filtered or unexported fields */}
	// Uint64 is an unsigned integer of 64 bytes.
	Uint64 = numberT{/* contains filtered or unexported fields */}
	// Float32 is a floating point number of 32 bytes.
	Float32 = numberT{/* contains filtered or unexported fields */}
	// Float64 is a floating point number of 64 bytes.
	Float64 = numberT{/* contains filtered or unexported fields */}

	// Timestamp is an UNIX timestamp.
	Timestamp timestampT
	// Date is a date with day, month and year.
	Date dateT
	// Text is a string type.
	Text textT
	// Boolean is a boolean type.
	Boolean booleanT
	// JSON is a type that holds any valid JSON object.
	JSON jsonT
	// Blob is a type that holds a chunk of binary data.
	Blob blobT
)
View Source
var ErrDatabaseNotFound = errors.NewKind("database not found: %s")

ErrDatabaseNotFound is thrown when a database is not found

View Source
var ErrFunctionNotFound = errors.NewKind("function not found: %s")

ErrFunctionNotFound is thrown when a function is not found

View Source
var ErrInvalidArgumentNumber = errors.NewKind("expecting %v arguments for calling this function, %d received")

ErrInvalidArgumentNumber is returned when the number of arguments to call a function is different from the function arity.

Functions

func EncodeExpressionHash

func EncodeExpressionHash(h ExpressionHash) string

EncodeExpressionHash encodes an ExpressionHash to hexadecimal string

func IsArray

func IsArray(t Type) bool

IsArray returns whether the given type is an array.

func IsDecimal

func IsDecimal(t Type) bool

IsDecimal checks if t is decimal type.

func IsInteger

func IsInteger(t Type) bool

IsInteger check if t is a (U)Int32/64 type

func IsNumber

func IsNumber(t Type) bool

IsNumber checks if t is a number type

func IsSigned

func IsSigned(t Type) bool

IsSigned checks if t is a signed type.

func IsText

func IsText(t Type) bool

IsText checks if t is a text type.

func IsTuple

func IsTuple(t Type) bool

IsTuple checks if t is a tuple type. Note that tupleT instances with just 1 value are not considered as a tuple, but a parenthesized value.

func IsUnsigned

func IsUnsigned(t Type) bool

IsUnsigned checks if t is an unsigned type.

func MustConvert

func MustConvert(t Type, v interface{}) interface{}

MustConvert calls the Convert function from a given Type, it err panics.

func NumColumns

func NumColumns(t Type) int

NumColumns returns the number of columns in a type. This is one for all types, except tuples.

Types

type Aggregation

type Aggregation interface {
	Expression
	// NewBuffer creates a new aggregation buffer and returns it as a Row.
	NewBuffer() Row
	// Update updates the given buffer with the given row.
	Update(ctx *Context, buffer, row Row) error
	// Merge merges a partial buffer into a global one.
	Merge(ctx *Context, buffer, partial Row) error
}

Aggregation implements an aggregation expression, where an aggregation buffer is created for each grouping (NewBuffer) and rows in the grouping are fed to the buffer (Update). Multiple buffers can be merged (Merge), making partial aggregations possible. Note that Eval must be called with the final aggregation buffer in order to get the final result.

type Alterable

type Alterable interface {
	Create(name string, schema Schema) error
}

Alterable should be implemented by databases that can handle DDL statements

type AscendIndex

type AscendIndex interface {
	// AscendGreaterOrEqual returns an IndexLookup for keys that are greater
	// or equal to the given keys.
	AscendGreaterOrEqual(keys ...interface{}) (IndexLookup, error)
	// AscendLessThan returns an IndexLookup for keys that are less than the
	// given keys.
	AscendLessThan(keys ...interface{}) (IndexLookup, error)
	// AscendRange returns an IndexLookup for keys that are within the given
	// range.
	AscendRange(greaterOrEqual, lessThan []interface{}) (IndexLookup, error)
}

AscendIndex is an index that is sorted in ascending order.

type BaseSession

type BaseSession struct {
}

BaseSession is the basic session type.

type Catalog

type Catalog struct {
	Databases
	FunctionRegistry
	*IndexRegistry
}

Catalog holds databases, tables and functions.

func NewCatalog

func NewCatalog() *Catalog

NewCatalog returns a new empty Catalog.

type Column

type Column struct {
	// Name is the name of the column.
	Name string
	// Type is the data type of the column.
	Type Type
	// Default contains the default value of the column or nil if it is NULL.
	Default interface{}
	// Nullable is true if the column can contain NULL values, or false
	// otherwise.
	Nullable bool
	// Source is the name of the table this column came from.
	Source string
}

Column is the definition of a table column. As SQL:2016 puts it:

A column is a named component of a table. It has a data type, a default,
and a nullability characteristic.

func (*Column) Check

func (c *Column) Check(v interface{}) bool

Check ensures the value is correct for this column.

func (*Column) Equals

func (c *Column) Equals(c2 *Column) bool

Equals checks whether two columns are equal.

type Context

type Context struct {
	context.Context
	Session
	// contains filtered or unexported fields
}

Context of the query execution.

func NewContext

func NewContext(
	ctx context.Context,
	opts ...ContextOption,
) *Context

NewContext creates a new query context. Options can be passed to configure the context. If some aspect of the context is not configure, the default value will be used. By default, the context will have an empty base session and a noop tracer.

func NewEmptyContext

func NewEmptyContext() *Context

NewEmptyContext returns a default context with default values.

func (*Context) Span

func (c *Context) Span(
	opName string,
	opts ...opentracing.StartSpanOption,
) (opentracing.Span, *Context)

Span creates a new tracing span with the given context. It will return the span and a new context that should be passed to all childrens of this span.

type ContextOption

type ContextOption func(*Context)

ContextOption is a function to configure the context.

func WithSession

func WithSession(s Session) ContextOption

WithSession adds the given session to the context.

func WithTracer

func WithTracer(t opentracing.Tracer) ContextOption

WithTracer adds the given tracer to the context.

type Database

type Database interface {
	Nameable
	// Tables returns the information of all tables.
	Tables() map[string]Table
}

Database represents the database.

type Databases

type Databases []Database

Databases is a collection of Database.

func (*Databases) AddDatabase

func (d *Databases) AddDatabase(db Database)

AddDatabase adds a new database.

func (Databases) Database

func (d Databases) Database(name string) (Database, error)

Database returns the Database with the given name if it exists.

func (Databases) Table

func (d Databases) Table(dbName string, tableName string) (Table, error)

Table returns the Table with the given name if it exists.

type DescendIndex

type DescendIndex interface {
	// DescendGreater returns an IndexLookup for keys that are greater
	// than the given keys.
	DescendGreater(keys ...interface{}) (IndexLookup, error)
	// DescendLessOrEqual returns an IndexLookup for keys that are less than or
	// equal to the given keys.
	DescendLessOrEqual(keys ...interface{}) (IndexLookup, error)
	// DescendRange returns an IndexLookup for keys that are within the given
	// range.
	DescendRange(lessOrEqual, greaterThan []interface{}) (IndexLookup, error)
}

DescendIndex is an index that is sorted in descending order.

type Expression

type Expression interface {
	Resolvable
	fmt.Stringer
	// Type returns the expression type.
	Type() Type
	// IsNullable returns whether the expression can be null.
	IsNullable() bool
	// Eval evaluates the given row and returns a result.
	Eval(*Context, Row) (interface{}, error)
	// TransformUp transforms the expression and all its children with the
	// given transform function.
	TransformUp(TransformExprFunc) (Expression, error)
	// Children returns the children expressions of this expression.
	Children() []Expression
}

Expression is a combination of one or more SQL expressions.

type ExpressionHash

type ExpressionHash []byte

ExpressionHash is a SHA-1 checksum

func DecodeExpressionHash

func DecodeExpressionHash(hexstr string) (ExpressionHash, error)

DecodeExpressionHash decodes a hexadecimal string to ExpressionHash

func NewExpressionHash

func NewExpressionHash(ex Expression) ExpressionHash

NewExpressionHash returns a new SHA1 hash for given Expression instance. SHA1 checksum will be calculated based on ex.String().

type Expressioner

type Expressioner interface {
	// Expressions returns the list of expressions contained by the node.
	Expressions() []Expression
	// TransformExpressions applies for each expression in this node
	// the expression's TransformUp method with the given function, and
	// return a new node with the transformed expressions.
	TransformExpressions(TransformExprFunc) (Node, error)
}

Expressioner is a node that contains expressions.

type Function

type Function interface {
	// Call invokes the function.
	Call(...Expression) (Expression, error)
	// contains filtered or unexported methods
}

Function is a function defined by the user that can be applied in a SQL query.

type Function1

type Function1 func(e Expression) Expression

Function1 is a function with 1 argument.

func (Function1) Call

func (fn Function1) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function2

type Function2 func(e1, e2 Expression) Expression

Function2 is a function with 2 arguments.

func (Function2) Call

func (fn Function2) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function3

type Function3 func(e1, e2, e3 Expression) Expression

Function3 is a function with 3 arguments.

func (Function3) Call

func (fn Function3) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function4

type Function4 func(e1, e2, e3, e4 Expression) Expression

Function4 is a function with 4 arguments.

func (Function4) Call

func (fn Function4) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function5

type Function5 func(e1, e2, e3, e4, e5 Expression) Expression

Function5 is a function with 5 arguments.

func (Function5) Call

func (fn Function5) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function6

type Function6 func(e1, e2, e3, e4, e5, e6 Expression) Expression

Function6 is a function with 6 arguments.

func (Function6) Call

func (fn Function6) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type Function7

type Function7 func(e1, e2, e3, e4, e5, e6, e7 Expression) Expression

Function7 is a function with 7 arguments.

func (Function7) Call

func (fn Function7) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type FunctionN

type FunctionN func(...Expression) (Expression, error)

FunctionN is a function with variable number of arguments. This function is expected to return ErrInvalidArgumentNumber if the arity does not match, since the check has to be done in the implementation.

func (FunctionN) Call

func (fn FunctionN) Call(args ...Expression) (Expression, error)

Call implements the Function interface.

type FunctionRegistry

type FunctionRegistry map[string]Function

FunctionRegistry is used to register functions. It is used both for builtin and User-Defined Functions.

func NewFunctionRegistry

func NewFunctionRegistry() FunctionRegistry

NewFunctionRegistry creates a new FunctionRegistry.

func (FunctionRegistry) Function

func (r FunctionRegistry) Function(name string) (Function, error)

Function returns a function with the given name.

func (FunctionRegistry) RegisterFunction

func (r FunctionRegistry) RegisterFunction(name string, f Function)

RegisterFunction registers a function with the given name.

func (FunctionRegistry) RegisterFunctions

func (r FunctionRegistry) RegisterFunctions(funcs Functions)

RegisterFunctions registers a map of functions.

type Functions

type Functions map[string]Function

Functions is a map of functions identified by their name.

type Index

type Index interface {
	// Get returns an IndexLookup for the given key in the index.
	Get(key ...interface{}) (IndexLookup, error)
	// Has checks if the given key is present in the index.
	Has(key ...interface{}) (bool, error)
	// ID returns the identifier of the index.
	ID() string
	// Database returns the database name this index belongs to.
	Database() string
	// Table returns the table name this index belongs to.
	Table() string
	// Expressions returns the indexed expressions. If the result is more than
	// one expression, it means the index has multiple columns indexed. If it's
	// just one, it means it may be an expression or a column.
	ExpressionHashes() []ExpressionHash
	// Driver ID of the index.
	Driver() string
}

Index is the basic representation of an index. It can be extended with more functionality by implementing more specific interfaces.

type IndexDriver

type IndexDriver interface {
	// ID returns the unique name of the driver.
	ID() string
	// Create a new index. If exprs is more than one expression, it means the
	// index has multiple columns indexed. If it's just one, it means it may
	// be an expression or a column.
	Create(db, table, id string, expressionHashes []ExpressionHash, config map[string]string) (Index, error)
	// LoadAll loads all indexes for given db and table
	LoadAll(db, table string) ([]Index, error)
	// Save the given index
	Save(ctx *Context, index Index, iter IndexKeyValueIter) error
	// Delete the given index.
	Delete(index Index) error
}

IndexDriver manages the coordination between the indexes and their representation on disk.

type IndexKeyValueIter

type IndexKeyValueIter interface {
	// Next returns the next tuple of index key values. The length of the
	// returned slice will be the same as the number of columns used to
	// create this iterator. The second returned parameter is a repo's location.
	Next() ([]interface{}, []byte, error)
	io.Closer
}

IndexKeyValueIter is an iterator of index key values, that is, a tuple of the values that will be index keys.

type IndexLookup

type IndexLookup interface {
	// Values returns the values in the subset of the index.
	Values() (IndexValueIter, error)
}

IndexLookup is a subset of an index. More specific interfaces can be implemented to grant more capabilities to the index lookup.

type IndexRegistry

type IndexRegistry struct {
	// Root path where all the data of the indexes is stored on disk.
	Root string
	// contains filtered or unexported fields
}

IndexRegistry keeps track of all indexes in the engine.

func NewIndexRegistry

func NewIndexRegistry() *IndexRegistry

NewIndexRegistry returns a new Index Registry.

func (*IndexRegistry) AddIndex

func (r *IndexRegistry) AddIndex(idx Index) (chan<- struct{}, error)

AddIndex adds the given index to the registry. The added index will be marked as creating, so nobody can't register two indexes with the same expression or id while the other is still being created. When something is sent through the returned channel, it means the index has finished it's creation and will be marked as ready.

func (*IndexRegistry) CanUseIndex

func (r *IndexRegistry) CanUseIndex(idx Index) bool

CanUseIndex returns whether the given index is ready to use or not.

func (*IndexRegistry) DefaultIndexDriver

func (r *IndexRegistry) DefaultIndexDriver() IndexDriver

DefaultIndexDriver returns the default index driver, which is the only driver when there is 1 driver in the registry. If there are more than 1 drivers in the registry, this will return the empty string, as there is no clear default driver.

func (*IndexRegistry) DeleteIndex

func (r *IndexRegistry) DeleteIndex(db, id string, force bool) (<-chan struct{}, error)

DeleteIndex deletes an index from the registry by its id. First, it marks the index for deletion but does not remove it, so queries that are using it may still do so. The returned channel will send a message when the index can be deleted from disk. If force is true, it will delete the index even if it's not ready for usage. Only use that parameter if you know what you're doing.

func (*IndexRegistry) ExpressionsWithIndexes

func (r *IndexRegistry) ExpressionsWithIndexes(
	db string,
	exprs ...Expression,
) [][]Expression

ExpressionsWithIndexes finds all the combinations of expressions with matching indexes. This only matches multi-column indexes.

func (*IndexRegistry) Index

func (r *IndexRegistry) Index(db, id string) Index

Index returns the index with the given id. It may return nil if the index is not found.

func (*IndexRegistry) IndexByExpression

func (r *IndexRegistry) IndexByExpression(db string, expr ...Expression) Index

IndexByExpression returns an index by the given expression. It will return nil it the index is not found. If more than one expression is given, all of them must match for the index to be matched.

func (*IndexRegistry) IndexDriver

func (r *IndexRegistry) IndexDriver(id string) IndexDriver

IndexDriver returns the IndexDriver with the given ID.

func (*IndexRegistry) LoadIndexes

func (r *IndexRegistry) LoadIndexes(dbs Databases) error

LoadIndexes loads all indexes for all dbs, tables and drivers.

func (*IndexRegistry) RegisterIndexDriver

func (r *IndexRegistry) RegisterIndexDriver(driver IndexDriver)

RegisterIndexDriver registers a new index driver.

func (*IndexRegistry) ReleaseIndex

func (r *IndexRegistry) ReleaseIndex(idx Index)

ReleaseIndex releases an index after it's been used.

type IndexStatus

type IndexStatus bool

IndexStatus represents the current status in which the index is.

const (
	// IndexNotReady means the index is not ready to be used.
	IndexNotReady IndexStatus = false
	// IndexReady means the index can be used.
	IndexReady IndexStatus = true
)

func (IndexStatus) IsUsable

func (s IndexStatus) IsUsable() bool

IsUsable returns whether the index can be used or not based on the status.

func (IndexStatus) String

func (s IndexStatus) String() string

type IndexValueIter

type IndexValueIter interface {
	// Next returns the next value (repo's location) - see IndexKeyValueIter.
	Next() ([]byte, error)
	io.Closer
}

IndexValueIter is an iterator of index values.

type Indexable

type Indexable interface {
	PushdownProjectionAndFiltersTable
	// IndexKeyValueIter returns an iterator with the values of each row in
	// the table for the given column names.
	IndexKeyValueIter(ctx *Context, colNames []string) (IndexKeyValueIter, error)
	// WithProjectFiltersAndIndex is meant to be called instead of RowIter
	// method of the table. Returns a new iterator given the columns,
	// filters and the index so the table can improve its speed instead of
	// making a full scan.
	WithProjectFiltersAndIndex(
		ctx *Context,
		columns, filters []Expression,
		index IndexValueIter,
	) (RowIter, error)
}

Indexable represents a table that supports being indexed and receiving indexes to be able to speed up its execution.

type Inserter

type Inserter interface {
	// Insert the given row.
	Insert(row Row) error
}

Inserter allow rows to be inserted in them.

type Mergeable

type Mergeable interface {
	// IsMergeable checks whether the current IndexLookup can be merged with
	// the given one.
	IsMergeable(IndexLookup) bool
}

Mergeable is a specialization of IndexLookup to check if an IndexLookup can be merged with another one.

type Nameable

type Nameable interface {
	// Name returns the name.
	Name() string
}

Nameable is something that has a name.

type Node

type Node interface {
	Resolvable
	Transformable
	fmt.Stringer
	// Schema of the node.
	Schema() Schema
	// Children nodes.
	Children() []Node
	// RowIter produces a row iterator from this node.
	RowIter(*Context) (RowIter, error)
}

Node is a node in the execution plan tree.

type PushdownProjectionAndFiltersTable

type PushdownProjectionAndFiltersTable interface {
	Table
	// HandledFilters returns the subset of filters that can be handled by this
	// table.
	HandledFilters(filters []Expression) []Expression
	// WithProjectAndFilters replaces the RowIter method of the table and
	// return a new row iterator given the column names that are projected
	// and the filters applied to this table.
	WithProjectAndFilters(ctx *Context, columns, filters []Expression) (RowIter, error)
}

PushdownProjectionAndFiltersTable is a table that can produce a specific RowIter that's more optimized given the columns that are projected and the filters for this table.

type PushdownProjectionTable

type PushdownProjectionTable interface {
	Table
	// WithProject replaces the RowIter method of the table and returns a new
	// row iterator given the column names that are projected.
	WithProject(ctx *Context, colNames []string) (RowIter, error)
}

PushdownProjectionTable is a table that can produce a specific RowIter that's more optimized given the columns that are projected.

type Resolvable

type Resolvable interface {
	// Resolved returns whether the node is resolved.
	Resolved() bool
}

Resolvable is something that can be resolved or not.

type Row

type Row []interface{}

Row is a tuple of values.

func NewRow

func NewRow(values ...interface{}) Row

NewRow creates a row from the given values.

func NodeToRows

func NodeToRows(ctx *Context, n Node) ([]Row, error)

NodeToRows converts a node to a slice of rows.

func RowIterToRows

func RowIterToRows(i RowIter) ([]Row, error)

RowIterToRows converts a row iterator to a slice of rows.

func (Row) Copy

func (r Row) Copy() Row

Copy creates a new row with the same values as the current one.

func (Row) Equals

func (r Row) Equals(row Row, schema Schema) (bool, error)

Equals checks whether two rows are equal given a schema.

type RowIter

type RowIter interface {
	// Next retrieves the next row. It will return io.EOF if it's the last row.
	// After retrieving the last row, Close will be automatically closed.
	Next() (Row, error)
	// Close the iterator.
	Close() error
}

RowIter is an iterator that produces rows.

func NewSpanIter

func NewSpanIter(span opentracing.Span, iter RowIter) RowIter

NewSpanIter creates a RowIter executed in the given span.

func RowsToRowIter

func RowsToRowIter(rows ...Row) RowIter

RowsToRowIter creates a RowIter that iterates over the given rows.

type Schema

type Schema []*Column

Schema is the definition of a table.

func (Schema) CheckRow

func (s Schema) CheckRow(row Row) error

CheckRow checks the row conforms to the schema.

func (Schema) Contains

func (s Schema) Contains(column string, source string) bool

Contains returns whether the schema contains a column with the given name.

func (Schema) Equals

func (s Schema) Equals(s2 Schema) bool

Equals checks whether the given schema is equal to this one.

func (Schema) IndexOf

func (s Schema) IndexOf(column, source string) int

IndexOf returns the index of the given column in the schema or -1 if it's not present.

type Session

type Session interface {
}

Session holds the session data.

func NewBaseSession

func NewBaseSession() Session

NewBaseSession creates a new basic session.

type SetOperations

type SetOperations interface {
	// Intersection returns a new index subset with the intersection of the
	// current IndexLookup and the ones given.
	Intersection(...IndexLookup) IndexLookup
	// Union returns a new index subset with the union of the current
	// IndexLookup and the ones given.
	Union(...IndexLookup) IndexLookup
	// Difference returns a new index subset with the difference between the
	// current IndexLookup and the ones given.
	Difference(...IndexLookup) IndexLookup
}

SetOperations is a specialization of IndexLookup that enables set operations between several IndexLookups.

type Table

type Table interface {
	Nameable
	Node
}

Table represents a SQL table.

type Tableable

type Tableable interface {
	// Table returns the table name.
	Table() string
}

Tableable is something that has a table.

type TransformExprFunc

type TransformExprFunc func(Expression) (Expression, error)

TransformExprFunc is a function that given an expression will return that expression as is or transformed along with an error, if any.

type TransformNodeFunc

type TransformNodeFunc func(Node) (Node, error)

TransformNodeFunc is a function that given a node will return that node as is or transformed along with an error, if any.

type Transformable

type Transformable interface {
	// TransformUp transforms all nodes and returns the result of this transformation.
	// Transformation is not propagated to subqueries.
	TransformUp(TransformNodeFunc) (Node, error)
	// TransformExpressionsUp transforms all expressions inside the node and all its
	// children and returns a node with the result of the transformations.
	// Transformation is not propagated to subqueries.
	TransformExpressionsUp(TransformExprFunc) (Node, error)
}

Transformable is a node which can be transformed.

type TreePrinter

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

TreePrinter is a printer for tree nodes.

func NewTreePrinter

func NewTreePrinter() *TreePrinter

NewTreePrinter creates a new tree printer.

func (*TreePrinter) String

func (p *TreePrinter) String() string

String returns the output of the printed tree.

func (*TreePrinter) WriteChildren

func (p *TreePrinter) WriteChildren(children ...string) error

WriteChildren writes a children of the tree.

func (*TreePrinter) WriteNode

func (p *TreePrinter) WriteNode(format string, args ...interface{}) error

WriteNode writes the main node.

type Type

type Type interface {
	// Type returns the query.Type for the given Type.
	Type() query.Type
	// Covert a value of a compatible type to a most accurate type.
	Convert(interface{}) (interface{}, error)
	// Compare returns an integer comparing two values.
	// The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
	Compare(interface{}, interface{}) (int, error)
	// SQL returns the sqltypes.Value for the given value.
	SQL(interface{}) sqltypes.Value
}

Type represent a SQL type.

func Array

func Array(underlying Type) Type

Array returns a new Array type of the given underlying type.

func MysqlTypeToType

func MysqlTypeToType(sql query.Type) (Type, error)

MysqlTypeToType gets the column type using the mysql type

func Tuple

func Tuple(types ...Type) Type

Tuple returns a new tuple type with the given element types.

type UnresolvedDatabase

type UnresolvedDatabase struct{}

UnresolvedDatabase is a database which has not been resolved yet.

func (*UnresolvedDatabase) Name

func (d *UnresolvedDatabase) Name() string

Name returns the database name, which is always "unresolved_database".

func (*UnresolvedDatabase) Tables

func (d *UnresolvedDatabase) Tables() map[string]Table

Tables returns the tables in the database.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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