query

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	NotPrimaryKey    = -1
	SinglePrimaryKey = 0
)
View Source
const (
	StmtSelect   = vitesssp.StmtSelect
	StmtStream   = vitesssp.StmtStream
	StmtInsert   = vitesssp.StmtInsert
	StmtReplace  = vitesssp.StmtReplace
	StmtUpdate   = vitesssp.StmtUpdate
	StmtDelete   = vitesssp.StmtDelete
	StmtDDL      = vitesssp.StmtDDL
	StmtBegin    = vitesssp.StmtBegin
	StmtCommit   = vitesssp.StmtCommit
	StmtRollback = vitesssp.StmtRollback
	StmtSet      = vitesssp.StmtSet
	StmtShow     = vitesssp.StmtShow
	StmtUse      = vitesssp.StmtUse
	StmtOther    = vitesssp.StmtOther
	StmtUnknown  = vitesssp.StmtUnknown
	StmtComment  = vitesssp.StmtComment
	StmtPriv     = vitesssp.StmtPriv
)

These constants are used to identify the SQL statement type. Changing this list will require reviewing all calls to Preview.

View Source
const (
	Unknown = -1
	// NULL_TYPE specifies a NULL type.
	Null = vitessst.Null
	// INT8 specifies a TINYINT type.
	Int8 = vitessst.Int8
	// UINT8 specifies a TINYINT UNSIGNED type.
	Uint8 = vitessst.Uint8
	// INT16 specifies a SMALLINT type.
	Int16 = vitessst.Int16
	// UINT16 specifies a SMALLINT UNSIGNED type.
	Uint16 = vitessst.Uint16
	// INT24 specifies a MEDIUMINT type.
	Int24 = vitessst.Int24
	// UINT24 specifies a MEDIUMINT UNSIGNED type.
	Uint24 = vitessst.Uint24
	// INT32 specifies a INTEGER type.
	Int32 = vitessst.Int32
	// UINT32 specifies a INTEGER UNSIGNED type.
	Uint32 = vitessst.Uint32
	// INT64 specifies a BIGINT type.
	Int64 = vitessst.Int64
	// UINT64 specifies a BIGINT UNSIGNED type.
	Uint64 = vitessst.Uint64
	// FLOAT32 specifies a FLOAT type.
	Float32 = vitessst.Float32
	// FLOAT64 specifies a DOUBLE or REAL type.
	Float64 = vitessst.Float64
	// TIMESTAMP specifies a TIMESTAMP type.
	Timestamp = vitessst.Timestamp
	// DATE specifies a DATE type.
	Date = vitessst.Date
	// TIME specifies a TIME type.
	Time = vitessst.Time
	// DATETIME specifies a DATETIME type.
	Datetime = vitessst.Datetime
	// YEAR specifies a YEAR type.
	Year = vitessst.Year
	// DECIMAL specifies a DECIMAL or NUMERIC type.
	Decimal = vitessst.Decimal
	// TEXT specifies a TEXT type.
	Text = vitessst.Text
	// BLOB specifies a BLOB type.
	Blob = vitessst.Blob
	// VARCHAR specifies a VARCHAR type.
	VarChar = vitessst.VarChar
	// VARBINARY specifies a VARBINARY type.
	VarBinary = vitessst.VarBinary
	// CHAR specifies a CHAR type.
	Char = vitessst.Char
	// BINARY specifies a BINARY type.
	Binary = vitessst.Binary
	// BIT specifies a BIT type.
	Bit = vitessst.Bit
	// ENUM specifies an ENUM type.
	Enum = vitessst.Enum
	// SET specifies a SET type.
	SetType = vitessst.Set
	// GEOMETRY specifies a GEOMETRY type.
	Geometry = vitessst.Geometry
	// JSON specifies a JSON type.
	TypeJSON = vitessst.TypeJSON
	// EXPRESSION specifies a SQL expression.
	Expression = vitessst.Expression
)

Vitess data types. These are idiomatically named synonyms for the vitess.Type values.

View Source
const (
	StrVal   = vitesssp.StrVal
	IntVal   = vitesssp.IntVal
	FloatVal = vitesssp.FloatVal
	HexNum   = vitesssp.HexNum
	HexVal   = vitesssp.HexVal
	BitVal   = vitesssp.BitVal
)
View Source
const (
	// NOTE: TestSchemaFindColumn checks whether ColKeyPrimary equals vt.sqlparser.colKeyPrimary
	// because it is an internal constant variable.
	ColKeyPrimary = vitesssp.ColumnKeyOption(1)
)

Variables

This section is empty.

Functions

func GetTableName

func GetTableName(v vitesssp.TableExpr) (string, error)

GetTableName returns the table name when the specified TableExpr is a known type.

Types

type AccessMode

type AccessMode = vitesssp.AccessMode

AccessMode is ReadOnly/ReadWrite.

type AndExpr

type AndExpr = vitesssp.AndExpr

AndExpr represents an AND expression.

type Begin

type Begin = vitesssp.Begin

Begin represents a Begin statement.

type Characteristic

type Characteristic = vitesssp.Characteristic

Characteristic is a transaction related change.

type ColName

type ColName = vitesssp.ColName

ColName represents a column name.

type Column

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

Column represents a column.

func NewBigIntColumnWithValue

func NewBigIntColumnWithValue(val interface{}) (*Column, error)

NewBigIntColumnWithValue returns a big int column with the specified value.

func NewBinaryColumnWithValue

func NewBinaryColumnWithValue(val interface{}) (*Column, error)

NewBinaryColumnWithValue returns a binary column with the specified value.

func NewColumn

func NewColumn() *Column

NewColumn returns a new column.

func NewColumnWithColumnDefinition

func NewColumnWithColumnDefinition(column *vitesssp.ColumnDefinition) *Column

NewColumnWithColumnDefinition returns a column with the specified vitess column definition.

func NewColumnWithName

func NewColumnWithName(name string) *Column

NewColumnWithName returns a column with the specified name.

func NewColumnWithNameAndType

func NewColumnWithNameAndType(name string, t ColumnType) *Column

NewColumnWithNameAndType returns a column with the specified name and type.

func NewColumnWithNameAndValue

func NewColumnWithNameAndValue(name string, val interface{}) (*Column, error)

NewColumnWithNameAndValue returns a column with the specified name and value.

func NewColumnWithTypeAndValue

func NewColumnWithTypeAndValue(typ ColumnType, val interface{}) (*Column, error)

NewColumnWithTypeAndValue returns a column with the specified type and value.

func NewColumnWithValue

func NewColumnWithValue(val interface{}) (*Column, error)

NewColumnWithValue returns a column with the specified value.

func NewDateColumnWithValue

func NewDateColumnWithValue(val interface{}) (*Column, error)

NewDateColumnWithValue returns a date column with the specified value.

func NewDatetimeColumnWithValue

func NewDatetimeColumnWithValue(val interface{}) (*Column, error)

NewDatetimeColumnWithValue returns a date column with the specified value.

func NewDoubleColumnWithValue

func NewDoubleColumnWithValue(val interface{}) (*Column, error)

NewDoubleColumnWithValue returns a double column with the specified value.

func NewFloatColumnWithValue

func NewFloatColumnWithValue(val interface{}) (*Column, error)

NewFloatColumnWithValue returns a float column with the specified value.

func NewIntegerColumnWithValue

func NewIntegerColumnWithValue(val interface{}) (*Column, error)

NewIntegerColumnWithValue returns an integer column with the specified value.

func NewNullColumn

func NewNullColumn() *Column

NewNullColumn returns a null column.

func NewShortIntColumnWithValue

func NewShortIntColumnWithValue(val interface{}) (*Column, error)

NewShortIntColumnWithValue returns a short int column with the specified value.

func NewTextColumnWithValue

func NewTextColumnWithValue(val interface{}) (*Column, error)

NewTextColumnWithValue returns a text column with the specified value.

func NewTimeColumnWithValue

func NewTimeColumnWithValue(val interface{}) (*Column, error)

NewTimeColumnWithValue returns a time column with the specified value.

func NewTimestampColumnWithValue

func NewTimestampColumnWithValue(val interface{}) (*Column, error)

NewTimestampColumnWithValue returns a timestamp column with the specified value.

func NewTinyIntColumnWithValue

func NewTinyIntColumnWithValue(val interface{}) (*Column, error)

NewTinyIntColumnWithValue returns a tiny int column with the specified value.

func (*Column) Equals

func (col *Column) Equals(other *Column) bool

Equals returns true when the specified column is equals to this column, otherwise false.

func (*Column) ForValue added in v1.0.5

func (col *Column) ForValue(t SQLType) (vitessst.Value, error)

ForValue converts a column to a vitess value for the specified SQL type.

func (*Column) Name

func (col *Column) Name() string

Name returns the column name.

func (*Column) SetName

func (col *Column) SetName(name string)

SetName sets a column name.

func (*Column) SetValue

func (col *Column) SetValue(val interface{}) error

SetValue sets a value.

func (*Column) String

func (col *Column) String() string

String returns the string representation.

func (*Column) ToValue

func (col *Column) ToValue() (vitessst.Value, error)

ToValue converts a column to a vitess value.

func (*Column) Type

func (col *Column) Type() ColumnType

Type returns the SQL type.

func (*Column) Value

func (col *Column) Value() interface{}

Value returns the value.

type ColumnDefinition

type ColumnDefinition = vitesssp.ColumnDefinition

ColumnDefinition describes a column in a CREATE TABLE statement.

type ColumnType

type ColumnType = vitesspq.Type

Type defines the various supported data types in bind vars and query results.

type Columns

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

Columns represents a column array.

func NewColumns

func NewColumns() *Columns

NewColumns returns a null columns.

func NewColumnsWithColumns

func NewColumnsWithColumns(columns []*Column) *Columns

NewColumnsWithColumns returns a columns with the specified columns.

func (*Columns) AddColumn

func (cols *Columns) AddColumn(col *Column)

AddColumn adds a column.

func (*Columns) AddColumns

func (cols *Columns) AddColumns(columns []*Column)

AddColumns adds columns.

func (*Columns) AllColumns

func (cols *Columns) AllColumns() []*Column

AllColumns returns the all columns.

func (*Columns) Clear

func (cols *Columns) Clear()

Clear clears all columns.

func (*Columns) ColumnAt

func (cols *Columns) ColumnAt(n int) (*Column, bool)

ColumnAt returns a column of the specified index.

func (*Columns) ColumnByName

func (cols *Columns) ColumnByName(name string) (*Column, bool)

ColumnByName returns a column by the specified name.

func (*Columns) Columns

func (cols *Columns) Columns() []*Column

Columns returns the all columns.

func (*Columns) Equals

func (cols *Columns) Equals(otherCols *Columns) bool

Equals returns true when the specified columns are equals to this columns, otherwise false.

func (*Columns) HasColumn

func (cols *Columns) HasColumn(name string) bool

HasColumn returns true when the query has the specified column.

func (*Columns) IsAllColumn

func (cols *Columns) IsAllColumn() bool

IsAllColumn returns true when the query has only "*" column.

func (*Columns) Size

func (cols *Columns) Size() int

Size returns the all column count.

func (*Columns) String

func (cols *Columns) String() string

String returns the string representation.

type Commit

type Commit = vitesssp.Commit

Commit represents a Commit statement.

type ComparisonExpr

type ComparisonExpr = vitesssp.ComparisonExpr

ComparisonExpr represents a two-value comparison expression.

type Condition

type Condition = vitesssp.Where

Condition represents a WHERE or HAVING clause.

type DBDDL

type DBDDL = vitesssp.DBDDLStatement

DBDDL represents a CREATE, DROP, or ALTER database statement.

type DDL

type DDL = vitesssp.DDLStatement

DDL represents a CREATE, ALTER, DROP, RENAME, TRUNCATE or ANALYZE statement.

type Database

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

Database represents a destination or source database of query.

func NewDatabase

func NewDatabase() *Database

NewDatabase returns a new database.

func NewDatabaseWithDBDDL

func NewDatabaseWithDBDDL(dbddl DBDDL) *Database

NewDatabaseWithDBDDL returns a new database with the specified DBDDL.

func NewDatabaseWithName

func NewDatabaseWithName(name string) *Database

NewDatabaseWithName returns a new database with the specified string.

func (*Database) IfExists

func (db *Database) IfExists() bool

IfExists returns true when the IF EXISTS option is enabled.

func (*Database) IfNotExists

func (db *Database) IfNotExists() bool

IfNotExists returns true when the IF NOT EXISTS option is enabled.

func (*Database) Name

func (db *Database) Name() string

Name returns the database name.

type Delete

type Delete struct {
	*vitesssp.Delete
}

Delete represents a DELETE statement.

func NewDeleteWithDelete

func NewDeleteWithDelete(stmt *vitesssp.Delete) *Delete

NewDeleteWithDelete creates a delete statement from the raw query.

func NewDeleteWithName

func NewDeleteWithName(name string) (*Delete, error)

NewDeleteWithName creates a delete statement from the table name.

func (*Delete) Tables

func (stmt *Delete) Tables() Tables

Tables returns all tables.

type Explain

type Explain = vitesssp.Explain

Explain represents an EXPLAIN statement.

type Expr

type Expr = vitesssp.Expr

Expr represents an expression.

type Field

type Field = vitesspq.Field

Field represents a field.

type IndexDefinition added in v0.9.2

type IndexDefinition = vitesssp.IndexDefinition

IndexDefinition describes an index in a CREATE TABLE statement.

type Insert

type Insert struct {
	*vitesssp.Insert
}

Insert represents an INSERT or REPLACE statement.

func NewInsertWithInsert

func NewInsertWithInsert(stmt *vitesssp.Insert) *Insert

NewInsertWithInsert creates a insert statement from the raw query.

func (*Insert) Columns

func (stmt *Insert) Columns() (*Columns, error)

Columns returns all column values with nil when the all columns can be converted, otherwith with a last error.

func (*Insert) TableName

func (stmt *Insert) TableName() string

TableName returns the target table name.

type IsolationLevel

type IsolationLevel = vitesssp.IsolationLevel

IsolationLevel is self-explanatory in this context.

type Limit added in v1.0.3

type Limit = vitesssp.Limit

Condition represents a WHERE or HAVING clause.

type Literal

type Literal = vitesssp.Literal

Literal represents a fixed value.

type NotExpr

type NotExpr = vitesssp.NotExpr

NotExpr represents a NOT expression.

type OrExpr

type OrExpr = vitesssp.OrExpr

OrExpr represents an OR expression.

type Order added in v1.0.3

type Order = vitesssp.Order

Order represents an ordering expression.

type OrderBy added in v1.0.3

type OrderBy = vitesssp.OrderBy

OrderBy represents an ORDER By clause.

type Parser

type Parser struct {
}

Parser represents a SQL parser.

func NewParser

func NewParser() *Parser

NewParser returns a new Parser instance.

func (*Parser) Parse

func (parser *Parser) Parse(query string) (Statement, error)

Parse parses a query string and returns the statement result.

type RangeCond added in v0.9.2

type RangeCond = vitesssp.RangeCond

RangeCond represents a BETWEEN or a NOT BETWEEN expression.

type Rollback

type Rollback = vitesssp.Rollback

Rollback represents a Rollback statement.

type Row

type Row struct {
	*Columns
}

Row represents a row object which includes query execution results.

func NewRow

func NewRow() *Row

NewRow return a row instance.

func NewRowWithColumns

func NewRowWithColumns(columns *Columns) *Row

NewRowWithColumns return a row instance with the specified columns.

func NewRowWithInsert

func NewRowWithInsert(stmt *Insert) (*Row, error)

NewRowWithInsert return a row instance with the specified INSERT statement.

func (*Row) Equals

func (row *Row) Equals(other *Row) bool

Equals returns true when the specified row is equals to this row, otherwise false.

func (*Row) HasMatchedColumn

func (row *Row) HasMatchedColumn(column *Column) bool

HasMatchedColumn returns true when the row has the specified column, otherwise false.

func (*Row) IsMatched

func (row *Row) IsMatched(cond *Condition) bool

IsMatched returns true when the row satisfies the specified condition, otherwise false.

func (*Row) String

func (row *Row) String() string

String returns the string representation.

func (*Row) Update

func (row *Row) Update(columns *Columns) error

Update updates row the specified columns.

type Rows

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

Rows represents a row array.

func NewRows

func NewRows() *Rows

NewRows returns a row array.

func NewRowsWithRows

func NewRowsWithRows(rawRows []*Row) *Rows

NewRowsWithRows returns a row array with the specified rows.

func (*Rows) AddRow

func (rows *Rows) AddRow(row *Row) error

AddRow adds a row.

func (*Rows) AddRows

func (rows *Rows) AddRows(row *Rows) error

AddRows adds all rows.

func (*Rows) DeleteRow

func (rows *Rows) DeleteRow(targetRow *Row) int64

DeleteRow deletes the specified row.

func (*Rows) FindMatchedRows

func (rows *Rows) FindMatchedRows(cond *Condition) *Rows

FindMatchedRows returns only matched rows by the specified condition.

func (*Rows) Row

func (rows *Rows) Row(n int) (*Row, bool)

Row returns a row of the specified index.

func (*Rows) Rows

func (rows *Rows) Rows() []*Row

Rows returns the all rows.

func (*Rows) Size

func (rows *Rows) Size() int

Size returns the all row count.

type SQLType added in v1.0.5

type SQLType = vitessstpq.Type

SQLType defines the various supported data types in bind vars.

type SQLVal

type SQLVal = vitessst.Value

SQLVal represents a single value.

type Schema

type Schema struct {
	DDL
}

Schema represents a table schema.

func NewSchemaWithDDL

func NewSchemaWithDDL(ddl DDL) *Schema

NewSchemaWithDDL returns a schema with the specified DDL.

func NewSchemaWithName

func NewSchemaWithName(name string) *Schema

NewSchemaWithName returns a schema with the specified table name.

func (*Schema) FindColumn

func (schema *Schema) FindColumn(name string) (*ColumnDefinition, bool)

FindColumn returns the specified columns definition.

func (*Schema) FindPrimaryColumn

func (schema *Schema) FindPrimaryColumn() (*ColumnDefinition, bool)

FindPrimaryColumn returns the specified columns definition.

func (*Schema) TableName

func (schema *Schema) TableName() string

TableName returns the table name.

func (*Schema) ToFields

func (schema *Schema) ToFields(db *Database) ([]*Field, error)

ToFields converts a column definitions to a vitess fields. nolint: exhaustive

type Select

type Select struct {
	*vitesssp.Select
}

Select represents an SELECT statement.

func NewSelectWithSelect

func NewSelectWithSelect(stmt *vitesssp.Select) *Select

NewSelectWithSelect creates a select statement from the raw query.

func (*Select) From

func (stmt *Select) From() Tables

From returns all tables.

type SelectStatement

type SelectStatement = vitesssp.SelectStatement

SelectStatement any SELECT statement.

type Set

type Set = vitesssp.Set

Set represents a SET statement.

type SetTransaction

type SetTransaction = vitesssp.SetTransaction

SetTransaction represents a SET TRANSACTION statement.

type Show

type Show = vitesssp.Show

Show represents a show statement.

type Statement

type Statement = vitesssp.Statement

Statement represents a query statement.

type StatementType

type StatementType = vitesssp.StatementType

StatementType encodes the type of a SQL statement.

type Stream

type Stream = vitesssp.Stream

Stream represents a SELECT statement.

type Table

type Table struct {
	vitesssp.TableExpr
}

Table represents a destination or source database of query.

func NewTableWitExpr

func NewTableWitExpr(expr vitesssp.TableExpr) *Table

NewTableWitExpr returns a table with the specified expression.

func (*Table) Name

func (tbl *Table) Name() (string, error)

Name returns the table name.

type Tables

type Tables = []*Table

Tables represents a table array.

func NewTablesWitExprs

func NewTablesWitExprs(exprs vitesssp.TableExprs) Tables

NewTablesWitExprs returns a tables with the specified expressions.

type Union

type Union = vitesssp.Union

Union represents a UNION statement.

type Update

type Update struct {
	*vitesssp.Update
}

Update represents an INSERT or REPLACE statement.

func NewUpdateWithUpdate

func NewUpdateWithUpdate(stmt *vitesssp.Update) *Update

NewUpdateWithUpdate creates a insert statement from the raw query.

func (*Update) Columns

func (stmt *Update) Columns() (*Columns, error)

GetColumns returns all column values with nil when the all columns can be converted, otherwith with a last error.

func (*Update) Tables

func (stmt *Update) Tables() Tables

Tables returns all tables.

type UpdateExprs

type UpdateExprs = vitesssp.UpdateExprs

UpdateExprs represents a list of update expressions.

type Use

type Use = vitesssp.Use

Use represents a use statement.

type ValTuple

type ValTuple = vitesssp.ValTuple

ValTuple represents a tuple of actual values.

type ValType

type ValType = vitesspq.Type

ValType specifies the type for SQLVal.

type Value

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

Value represents a query value.

func NewValue

func NewValue() *Value

NewValue creates a query value .

func NewValueWith added in v0.9.2

func NewValueWith(valType ValType, val interface{}) *Value

NewValueWith creates a query value with the specified type.

func (*Value) SetType

func (value *Value) SetType(t ValType)

SetType sets a value type.

func (*Value) SetValue

func (value *Value) SetValue(val interface{}) error

SetValue sets a value.

func (*Value) Type

func (value *Value) Type() ValType

Type returns the type.

func (*Value) Value

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

Value returns the value.

type XorExpr

type XorExpr = vitesssp.XorExpr

XorExpr represents an XOR expression.

Jump to

Keyboard shortcuts

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