package spansql
import "cloud.google.com/go/spanner/spansql"
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
- func (at *AlterTable) Pos() Position
- func (at AlterTable) SQL() string
- func (at *AlterTable) String() string
- type ArithOp
- type ArithOperator
- type Array
- type BoolExpr
- type BoolLiteral
- type BytesLiteral
- type Check
- type ColumnAlteration
- type ColumnDef
- type ColumnOptions
- type Comment
- type ComparisonOp
- type ComparisonOperator
- type Constraint
- type CreateIndex
- func (ci *CreateIndex) Pos() Position
- func (ci CreateIndex) SQL() string
- func (ci *CreateIndex) String() string
- type CreateTable
- func (ct *CreateTable) Pos() Position
- func (ct CreateTable) SQL() string
- func (ct *CreateTable) String() string
- type DDL
- func ParseDDL(filename, s string) (*DDL, error)
- func (ddl *DDL) InlineComment(n Node) *Comment
- func (ddl *DDL) LeadingComment(n Node) *Comment
- type DDLStmt
- type DMLStmt
- type DateLiteral
- type Delete
- type DropColumn
- type DropConstraint
- type DropIndex
- func (di *DropIndex) Pos() Position
- func (di DropIndex) SQL() string
- func (di *DropIndex) String() string
- type DropTable
- func (dt *DropTable) Pos() Position
- func (dt DropTable) SQL() string
- func (dt *DropTable) String() string
- type Expr
- type FloatLiteral
- type ForeignKey
- type Func
- type ID
- type InOp
- type IntegerLiteral
- type Interleave
- type IsExpr
- type IsOp
- type JoinType
- type KeyPart
- type LiteralOrParam
- type LogicalOp
- type LogicalOperator
- type Node
- type NullLiteral
- type OnDelete
- type Order
- type Param
- type Paren
- type PathExp
- type Position
- type Query
- type Select
- type SelectFrom
- type SelectFromJoin
- type SelectFromTable
- type SelectFromUnnest
- type SetColumnOptions
- type SetColumnType
- type SetOnDelete
- type StarExpr
- type StringLiteral
- type TableAlteration
- type TableConstraint
- type TableSample
- type TableSampleMethod
- type TableSampleSizeType
- type TimestampLiteral
- type Type
- type TypeBase
- type Update
- type UpdateItem
Constants ¶
const ( True = BoolLiteral(true) False = BoolLiteral(false) )
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.
Functions ¶
func IsKeyword ¶
IsKeyword reports whether the identifier is a reserved keyword.
Types ¶
type AddColumn ¶
type AddColumn struct{ Def ColumnDef }
func (AddColumn) SQL ¶
type AddConstraint ¶
type AddConstraint struct{ Constraint TableConstraint }
func (AddConstraint) SQL ¶
func (ac AddConstraint) SQL() string
type AlterColumn ¶
type AlterColumn struct { Name ID Alteration ColumnAlteration }
func (AlterColumn) SQL ¶
func (ac AlterColumn) SQL() string
type AlterTable ¶
type AlterTable struct { Name ID 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 ¶
func (at *AlterTable) Pos() Position
func (AlterTable) SQL ¶
func (at AlterTable) SQL() string
func (*AlterTable) String ¶
func (at *AlterTable) String() string
type ArithOp ¶
type ArithOp struct { Op ArithOperator LHS, RHS Expr // only RHS is set for Neg, Plus, BitNot }
func (ArithOp) SQL ¶
type ArithOperator ¶
type ArithOperator int
const ( Neg ArithOperator = iota // unary - Plus // unary + BitNot // unary ~ Mul // * Div // / Concat // || Add // + Sub // - BitShl // << BitShr // >> BitAnd // & BitXor // ^ BitOr // | )
type Array ¶
type Array []Expr
Array represents an array literal.
func (Array) SQL ¶
type BoolExpr ¶
type BoolExpr interface { Expr // contains filtered or unexported methods }
type BoolLiteral ¶
type BoolLiteral bool
func (BoolLiteral) SQL ¶
func (b BoolLiteral) SQL() string
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 Check ¶
Check represents a check constraint as part of a CREATE TABLE or ALTER TABLE statement.
func (Check) Pos ¶
func (Check) SQL ¶
type ColumnAlteration ¶
type ColumnAlteration interface { SQL() string // contains filtered or unexported methods }
ColumnAlteration is satisfied by SetColumnType and SetColumnOptions.
type ColumnDef ¶
type ColumnDef struct { Name ID Type Type NotNull bool Generated Expr // set of this is a generated column Options ColumnOptions Position Position // position of the column name }
ColumnDef represents a column definition as part of a CREATE TABLE or ALTER TABLE statement.
func (ColumnDef) Pos ¶
func (ColumnDef) SQL ¶
type ColumnOptions ¶
type ColumnOptions struct { // 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 }
ColumnOptions represents options on a column as part of a CREATE TABLE or ALTER TABLE statement.
func (ColumnOptions) SQL ¶
func (co ColumnOptions) SQL() string
type Comment ¶
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.
func (*Comment) Pos ¶
func (*Comment) String ¶
type ComparisonOp ¶
type ComparisonOp struct { Op ComparisonOperator LHS, RHS Expr // 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 Constraint ¶
type CreateIndex ¶
type CreateIndex struct { Name ID Table ID Columns []KeyPart Unique bool NullFiltered bool Storing []ID Interleave ID 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 ¶
func (ci *CreateIndex) Pos() Position
func (CreateIndex) SQL ¶
func (ci CreateIndex) SQL() string
func (*CreateIndex) String ¶
func (ci *CreateIndex) String() string
type CreateTable ¶
type CreateTable struct { Name ID 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 ¶
func (ct *CreateTable) Pos() Position
func (CreateTable) SQL ¶
func (ct CreateTable) SQL() string
func (*CreateTable) String ¶
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 ¶
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 ¶
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 ¶
type DMLStmt interface { SQL() string // contains filtered or unexported methods }
DMLStmt is satisfied by a type that is a DML statement.
func ParseDMLStmt ¶
ParseDMLStmt parses a single DML statement.
type DateLiteral ¶
DateLiteral represents a date literal. https://cloud.google.com/spanner/docs/lexical#date_literals
func (DateLiteral) SQL ¶
func (dl DateLiteral) SQL() string
type Delete ¶
Delete represents a DELETE statement. https://cloud.google.com/spanner/docs/dml-syntax#delete-statement
func (*Delete) SQL ¶
func (*Delete) String ¶
type DropColumn ¶
type DropColumn struct{ Name ID }
func (DropColumn) SQL ¶
func (dc DropColumn) SQL() string
type DropConstraint ¶
type DropConstraint struct{ Name ID }
func (DropConstraint) SQL ¶
func (dc DropConstraint) SQL() string
type DropIndex ¶
DropIndex represents a DROP INDEX statement. https://cloud.google.com/spanner/docs/data-definition-language#drop-index
func (*DropIndex) Pos ¶
func (DropIndex) SQL ¶
func (*DropIndex) String ¶
type DropTable ¶
DropTable represents a DROP TABLE statement. https://cloud.google.com/spanner/docs/data-definition-language#drop_table
func (*DropTable) Pos ¶
func (DropTable) SQL ¶
func (*DropTable) String ¶
type Expr ¶
type Expr interface { SQL() string // contains filtered or unexported methods }
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 ¶
type ForeignKey struct { Columns []ID RefTable ID RefColumns []ID 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 ¶
func (fk ForeignKey) Pos() Position
func (ForeignKey) SQL ¶
func (fk ForeignKey) SQL() string
type Func ¶
Func represents a function call.
func (Func) SQL ¶
type ID ¶
type ID string
ID represents an identifier. https://cloud.google.com/spanner/docs/lexical#identifiers
func (ID) SQL ¶
type InOp ¶
func (InOp) SQL ¶
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 IsExpr ¶
type IsExpr interface { Expr // contains filtered or unexported methods }
type IsOp ¶
func (IsOp) SQL ¶
type JoinType ¶
type JoinType int
type KeyPart ¶
KeyPart represents a column specification as part of a primary key or index definition.
func (KeyPart) SQL ¶
type LiteralOrParam ¶
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 Not }
func (LogicalOp) SQL ¶
type LogicalOperator ¶
type LogicalOperator int
const ( And LogicalOperator = iota Or Not )
type Node ¶
type Node interface { Pos() Position }
Node is implemented by concrete types in this package that represent things appearing in a DDL file.
type NullLiteral ¶
type NullLiteral int
func (NullLiteral) SQL ¶
func (NullLiteral) SQL() string
type OnDelete ¶
type OnDelete int
func (OnDelete) SQL ¶
type Order ¶
func (Order) SQL ¶
type Param ¶
type Param string
Param represents a query parameter.
func (Param) SQL ¶
type Paren ¶
type Paren struct { Expr Expr }
Paren represents a parenthesised expression.
func (Paren) SQL ¶
type PathExp ¶
type PathExp []ID
PathExp represents a path expression.
The grammar for path expressions is not defined (see b/169017423 internally), so this captures the most common form only, namely a dotted sequence of identifiers.
func (PathExp) SQL ¶
type Position ¶
Position describes a source position in an input DDL file. It is only valid if the line number is positive.
func (Position) IsValid ¶
func (Position) String ¶
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
func ParseQuery ¶
ParseQuery parses a query string.
func (Query) SQL ¶
type Select ¶
type Select struct { Distinct bool List []Expr From []SelectFrom Where BoolExpr GroupBy []Expr // When the FROM clause has TABLESAMPLE operators, // TableSamples will be populated 1:1 with From; // FROM clauses without will have a nil value. TableSamples []*TableSample // 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 []ID }
Select represents a SELECT statement. https://cloud.google.com/spanner/docs/query-syntax#select-list
func (Select) SQL ¶
type SelectFrom ¶
type SelectFrom interface { SQL() string // contains filtered or unexported methods }
SelectFrom represents the FROM clause of a SELECT. https://cloud.google.com/spanner/docs/query-syntax#from_clause
type SelectFromJoin ¶
type SelectFromJoin struct { Type JoinType LHS, RHS SelectFrom // Join condition. // At most one of {On,Using} may be set. On BoolExpr Using []ID // Hints are suggestions for how to evaluate a join. // https://cloud.google.com/spanner/docs/query-syntax#join-hints Hints map[string]string }
SelectFromJoin is a SelectFrom that joins two other SelectFroms. https://cloud.google.com/spanner/docs/query-syntax#join_types
func (SelectFromJoin) SQL ¶
func (sfj SelectFromJoin) SQL() string
type SelectFromTable ¶
SelectFromTable is a SelectFrom that specifies a table to read from.
func (SelectFromTable) SQL ¶
func (sft SelectFromTable) SQL() string
type SelectFromUnnest ¶
SelectFromUnnest is a SelectFrom that yields a virtual table from an array. https://cloud.google.com/spanner/docs/query-syntax#unnest
func (SelectFromUnnest) SQL ¶
func (sfu SelectFromUnnest) SQL() string
type SetColumnOptions ¶
type SetColumnOptions struct{ Options ColumnOptions }
func (SetColumnOptions) SQL ¶
func (sco SetColumnOptions) SQL() string
type SetColumnType ¶
func (SetColumnType) SQL ¶
func (sct SetColumnType) SQL() string
type SetOnDelete ¶
type SetOnDelete struct{ Action OnDelete }
func (SetOnDelete) SQL ¶
func (sod SetOnDelete) SQL() string
type StarExpr ¶
type StarExpr int
func (StarExpr) SQL ¶
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, AddConstraint, DropConstraint, SetOnDelete and AlterColumn.
type TableConstraint ¶
type TableConstraint struct { Name ID // may be empty Constraint Constraint Position Position // position of the "CONSTRAINT" token, or Constraint.Pos() }
TableConstraint represents a constraint on a table.
func (TableConstraint) Pos ¶
func (tc TableConstraint) Pos() Position
func (TableConstraint) SQL ¶
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 )
type TimestampLiteral ¶
TimestampLiteral represents a timestamp literal. https://cloud.google.com/spanner/docs/lexical#timestamp_literals
func (TimestampLiteral) SQL ¶
func (tl TimestampLiteral) SQL() string
type Type ¶
type Type struct { Array bool Base TypeBase // Bool, Int64, Float64, Numeric, String, Bytes, Date, Timestamp Len int64 // if Base is String or Bytes; may be MaxLen }
Type represents a column type.
func (Type) SQL ¶
type TypeBase ¶
type TypeBase int
func (TypeBase) SQL ¶
type Update ¶
type Update struct { Table ID Items []UpdateItem Where BoolExpr }
Update represents an UPDATE statement. https://cloud.google.com/spanner/docs/dml-syntax#update-statement
func (*Update) SQL ¶
func (*Update) String ¶
type UpdateItem ¶
Source Files ¶
keywords.go parser.go sql.go types.go
- Version
- v1.15.0
- Published
- Feb 24, 2021
- Platform
- windows/amd64
- Imports
- 9 packages
- Last checked
- 1 minute ago –
Tools for package owners.