Documentation ¶
Overview ¶
Package spansql contains types and a parser for the Cloud Spanner SQL dialect.
To parse, use one of the Parse functions (ParseDDL, ParseDDLStmt, ParseQuery, etc.).
Sources:
https://cloud.google.com/spanner/docs/lexical https://cloud.google.com/spanner/docs/query-syntax https://cloud.google.com/spanner/docs/data-definition-language
Index ¶
- Constants
- func IsKeyword(id string) bool
- type AddColumn
- type AddConstraint
- type AlterColumn
- type AlterTable
- type ArithOp
- type ArithOperator
- type BoolExpr
- type BoolLiteral
- type BytesLiteral
- type ColumnDef
- type Comment
- type ComparisonOp
- type ComparisonOperator
- type CreateIndex
- type CreateTable
- type DDL
- type DDLStmt
- type DMLStmt
- type Delete
- type DropColumn
- type DropConstraint
- type DropIndex
- type DropTable
- type Expr
- type FloatLiteral
- type ForeignKey
- type Func
- type ID
- type InOp
- type IntegerLiteral
- type Interleave
- type IsExpr
- type IsOp
- type KeyPart
- type LiteralOrParam
- type LogicalOp
- type LogicalOperator
- type Node
- type NullLiteral
- type OnDelete
- type Order
- type Param
- type Paren
- type Position
- type Query
- type Select
- type SelectFrom
- type SetOnDelete
- type StarExpr
- type StringLiteral
- type TableAlteration
- type TableConstraint
- type TableSample
- type TableSampleMethod
- type TableSampleSizeType
- type Type
- type TypeBase
Constants ¶
const ( True = BoolLiteral(true) False = BoolLiteral(false) )
const MaxLen = math.MaxInt64
MaxLen is a sentinel for Type's Len field, representing the MAX value.
const Null = NullLiteral(0)
const Star = StarExpr(0)
Star represents a "*" in an expression.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AddConstraint ¶ added in v1.3.0
type AddConstraint struct{ Constraint TableConstraint }
func (AddConstraint) SQL ¶ added in v1.3.0
func (ac AddConstraint) SQL() string
type AlterColumn ¶ added in v1.3.0
type AlterColumn struct{ Def ColumnDef }
func (AlterColumn) SQL ¶ added in v1.3.0
func (ac AlterColumn) SQL() string
type AlterTable ¶
type AlterTable struct { Name string Alteration TableAlteration Position Position // position of the "ALTER" token }
AlterTable represents an ALTER TABLE statement. https://cloud.google.com/spanner/docs/data-definition-language#alter_table
func (*AlterTable) Pos ¶ added in v1.2.1
func (at *AlterTable) Pos() Position
func (AlterTable) SQL ¶
func (at AlterTable) SQL() string
func (*AlterTable) String ¶ added in v1.2.1
func (at *AlterTable) String() string
type ArithOp ¶ added in v1.2.1
type ArithOp struct { Op ArithOperator LHS, RHS Expr // only RHS is set for Neg, BitNot }
type ArithOperator ¶ added in v1.2.1
type ArithOperator int
const ( Neg ArithOperator = iota // unary - BitNot // unary ~ Mul // * Div // / Concat // || Add // + Sub // - BitShl // << BitShr // >> BitAnd // & BitXor // ^ BitOr // | )
type BytesLiteral ¶
type BytesLiteral string
BytesLiteral represents a bytes literal. https://cloud.google.com/spanner/docs/lexical#string-and-bytes-literals
func (BytesLiteral) SQL ¶
func (bl BytesLiteral) SQL() string
type ColumnDef ¶
type ColumnDef struct { Name string Type Type NotNull bool // AllowCommitTimestamp represents a column OPTIONS. // `true` if query is `OPTIONS (allow_commit_timestamp = true)` // `false` if query is `OPTIONS (allow_commit_timestamp = null)` // `nil` if there are no OPTIONS AllowCommitTimestamp *bool Position Position // position of the column name }
ColumnDef represents a column definition as part of a CREATE TABLE or ALTER TABLE statement.
type Comment ¶ added in v1.2.1
type Comment struct { Marker string // Opening marker; one of "#", "--", "/*". Isolated bool // Whether this comment is on its own line. // Start and End are the position of the opening and terminating marker. Start, End Position Text []string }
Comment represents a comment.
type ComparisonOp ¶
type ComparisonOp struct {
LHS, RHS Expr
Op ComparisonOperator
// RHS2 is the third operand for BETWEEN.
// "<LHS> BETWEEN <RHS> AND <RHS2>".
RHS2 Expr
}
func (ComparisonOp) SQL ¶
func (co ComparisonOp) SQL() string
type ComparisonOperator ¶
type ComparisonOperator int
const ( Lt ComparisonOperator = iota Le Gt Ge Eq Ne // both "!=" and "<>" Like NotLike Between NotBetween )
type CreateIndex ¶
type CreateIndex struct { Name string Table string Columns []KeyPart Unique bool NullFiltered bool Storing []string Interleave string Position Position // position of the "CREATE" token }
CreateIndex represents a CREATE INDEX statement. https://cloud.google.com/spanner/docs/data-definition-language#create-index
func (*CreateIndex) Pos ¶ added in v1.2.1
func (ci *CreateIndex) Pos() Position
func (CreateIndex) SQL ¶
func (ci CreateIndex) SQL() string
func (*CreateIndex) String ¶ added in v1.2.1
func (ci *CreateIndex) String() string
type CreateTable ¶
type CreateTable struct { Name string Columns []ColumnDef Constraints []TableConstraint PrimaryKey []KeyPart Interleave *Interleave Position Position // position of the "CREATE" token }
CreateTable represents a CREATE TABLE statement. https://cloud.google.com/spanner/docs/data-definition-language#create_table
func (*CreateTable) Pos ¶ added in v1.2.1
func (ct *CreateTable) Pos() Position
func (CreateTable) SQL ¶
func (ct CreateTable) SQL() string
func (*CreateTable) String ¶ added in v1.2.1
func (ct *CreateTable) String() string
type DDL ¶
type DDL struct { List []DDLStmt Filename string // if known at parse time Comments []*Comment // all comments, sorted by position }
DDL represents a Data Definition Language (DDL) file.
func ParseDDL ¶
ParseDDL parses a DDL file.
The provided filename is used for error reporting and will appear in the returned structure.
func (*DDL) InlineComment ¶ added in v1.2.1
InlineComment returns the comment on the same line as a node, or nil if there's no inline comment. The returned comment is guaranteed to be a single line.
func (*DDL) LeadingComment ¶ added in v1.2.1
LeadingComment returns the comment that immediately precedes a node, or nil if there's no such comment.
type DDLStmt ¶
DDLStmt is satisfied by a type that can appear in a DDL.
func ParseDDLStmt ¶
ParseDDLStmt parses a single DDL statement.
type DMLStmt ¶ added in v1.2.1
type DMLStmt interface { SQL() string // contains filtered or unexported methods }
DMLStmt is satisfied by a type that is a DML statement.
func ParseDMLStmt ¶ added in v1.2.1
ParseDMLStmt parses a single DML statement.
type Delete ¶ added in v1.2.1
Delete represents a DELETE statement. https://cloud.google.com/spanner/docs/dml-syntax#delete-statement
type DropColumn ¶
type DropColumn struct{ Name string }
func (DropColumn) SQL ¶
func (dc DropColumn) SQL() string
type DropConstraint ¶ added in v1.3.0
type DropConstraint struct{ Name string }
func (DropConstraint) SQL ¶ added in v1.3.0
func (dc DropConstraint) SQL() string
type DropIndex ¶
DropIndex represents a DROP INDEX statement. https://cloud.google.com/spanner/docs/data-definition-language#drop-index
type DropTable ¶
DropTable represents a DROP TABLE statement. https://cloud.google.com/spanner/docs/data-definition-language#drop_table
type FloatLiteral ¶
type FloatLiteral float64
FloatLiteral represents a floating point literal. https://cloud.google.com/spanner/docs/lexical#floating-point-literals
func (FloatLiteral) SQL ¶
func (fl FloatLiteral) SQL() string
type ForeignKey ¶ added in v1.3.0
type ForeignKey struct { Columns []string RefTable string RefColumns []string Position Position // position of the "FOREIGN" token }
ForeignKey represents a foreign key definition as part of a CREATE TABLE or ALTER TABLE statement.
func (ForeignKey) Pos ¶ added in v1.3.0
func (fk ForeignKey) Pos() Position
func (ForeignKey) SQL ¶ added in v1.3.0
func (fk ForeignKey) SQL() string
type IntegerLiteral ¶
type IntegerLiteral int64
IntegerLiteral represents an integer literal. https://cloud.google.com/spanner/docs/lexical#integer-literals
func (IntegerLiteral) SQL ¶
func (il IntegerLiteral) SQL() string
type Interleave ¶
Interleave represents an interleave clause of a CREATE TABLE statement.
type KeyPart ¶
KeyPart represents a column specification as part of a primary key or index definition.
type LiteralOrParam ¶ added in v1.3.0
type LiteralOrParam interface { SQL() string // contains filtered or unexported methods }
LiteralOrParam is implemented by integer literal and parameter values.
type LogicalOp ¶
type LogicalOp struct { Op LogicalOperator LHS, RHS BoolExpr // only RHS is set for Neg, BitNot }
type Node ¶ added in v1.2.1
type Node interface {
Pos() Position
}
Node is implemented by concrete types in this package that represent things appearing in a DDL file.
type Position ¶ added in v1.2.1
Position describes a source position in an input DDL file. It is only valid if the line number is positive.
type Query ¶
type Query struct { Select Select Order []Order Limit, Offset LiteralOrParam }
Query represents a query statement. https://cloud.google.com/spanner/docs/query-syntax#sql-syntax
type Select ¶
type Select struct { Distinct bool List []Expr From []SelectFrom Where BoolExpr GroupBy []Expr // If the SELECT list has explicit aliases ("AS alias"), // ListAliases will be populated 1:1 with List; // aliases that are present will be non-empty. ListAliases []string }
Select represents a SELECT statement. https://cloud.google.com/spanner/docs/query-syntax#select-list
type SelectFrom ¶
type SelectFrom struct { // This only supports a FROM clause directly from a table. Table string TableSample *TableSample }
type SetOnDelete ¶
type SetOnDelete struct{ Action OnDelete }
func (SetOnDelete) SQL ¶
func (sod SetOnDelete) SQL() string
type StringLiteral ¶
type StringLiteral string
StringLiteral represents a string literal. https://cloud.google.com/spanner/docs/lexical#string-and-bytes-literals
func (StringLiteral) SQL ¶
func (sl StringLiteral) SQL() string
type TableAlteration ¶
type TableAlteration interface { SQL() string // contains filtered or unexported methods }
TableAlteration is satisfied by AddColumn, DropColumn and SetOnDelete.
type TableConstraint ¶ added in v1.3.0
type TableConstraint struct { Name string // may be empty ForeignKey ForeignKey Position Position // position of the "CONSTRAINT" or "FOREIGN" token }
TableConstraint represents a constraint on a table.
func (TableConstraint) Pos ¶ added in v1.3.0
func (tc TableConstraint) Pos() Position
func (TableConstraint) SQL ¶ added in v1.3.0
func (tc TableConstraint) SQL() string
type TableSample ¶
type TableSample struct { Method TableSampleMethod Size Expr SizeType TableSampleSizeType }
type TableSampleMethod ¶
type TableSampleMethod int
const ( Bernoulli TableSampleMethod = iota Reservoir )
type TableSampleSizeType ¶
type TableSampleSizeType int
const ( PercentTableSample TableSampleSizeType = iota RowsTableSample )