spannercloud.google.com/go/spanner/spansql Index | Files

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

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.

Functions

func IsKeyword

func IsKeyword(id string) bool

IsKeyword reports whether the identifier is a reserved keyword.

Types

type AddColumn

type AddColumn struct{ Def ColumnDef }

func (AddColumn) SQL

func (ac AddColumn) SQL() string

type AddConstraint

type AddConstraint struct{ Constraint TableConstraint }

func (AddConstraint) SQL

func (ac AddConstraint) SQL() string

type AlterColumn

type AlterColumn struct {
	Name       string
	Alteration ColumnAlteration
}

func (AlterColumn) SQL

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

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, BitNot
}

func (ArithOp) SQL

func (ao ArithOp) SQL() string

type ArithOperator

type ArithOperator int
const (
	Neg    ArithOperator = iota // unary -
	BitNot                      // unary ~
	Mul                         // *
	Div                         // /
	Concat                      // ||
	Add                         // +
	Sub                         // -
	BitShl                      // <<
	BitShr                      // >>
	BitAnd                      // &
	BitXor                      // ^
	BitOr                       // |
)

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 ColumnAlteration

type ColumnAlteration interface {
	SQL() string
	// contains filtered or unexported methods
}

type ColumnDef

type ColumnDef struct {
	Name    string
	Type    Type
	NotNull bool

	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 (cd ColumnDef) Pos() Position

func (ColumnDef) SQL

func (cd ColumnDef) SQL() string

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 (c *Comment) Pos() Position

func (*Comment) String

func (c *Comment) String() 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 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

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

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

func ParseDDL(filename, s string) (*DDL, error)

ParseDDL parses a DDL file.

The provided filename is used for error reporting and will appear in the returned structure.

func (*DDL) InlineComment

func (ddl *DDL) InlineComment(n Node) *Comment

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

func (ddl *DDL) LeadingComment(n Node) *Comment

LeadingComment returns the comment that immediately precedes a node, or nil if there's no such comment.

type DDLStmt

type DDLStmt interface {
	SQL() string
	Node
	// contains filtered or unexported methods
}

DDLStmt is satisfied by a type that can appear in a DDL.

func ParseDDLStmt

func ParseDDLStmt(s string) (DDLStmt, error)

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

func ParseDMLStmt(s string) (DMLStmt, error)

ParseDMLStmt parses a single DML statement.

type Delete

type Delete struct {
	Table string
	Where BoolExpr
}

Delete represents a DELETE statement. https://cloud.google.com/spanner/docs/dml-syntax#delete-statement

func (*Delete) SQL

func (d *Delete) SQL() string

func (*Delete) String

func (d *Delete) String() string

type DropColumn

type DropColumn struct{ Name string }

func (DropColumn) SQL

func (dc DropColumn) SQL() string

type DropConstraint

type DropConstraint struct{ Name string }

func (DropConstraint) SQL

func (dc DropConstraint) SQL() string

type DropIndex

type DropIndex struct {
	Name string

	Position Position // position of the "DROP" token
}

DropIndex represents a DROP INDEX statement. https://cloud.google.com/spanner/docs/data-definition-language#drop-index

func (*DropIndex) Pos

func (di *DropIndex) Pos() Position

func (DropIndex) SQL

func (di DropIndex) SQL() string

func (*DropIndex) String

func (di *DropIndex) String() string

type DropTable

type DropTable struct {
	Name string

	Position Position // position of the "DROP" token
}

DropTable represents a DROP TABLE statement. https://cloud.google.com/spanner/docs/data-definition-language#drop_table

func (*DropTable) Pos

func (dt *DropTable) Pos() Position

func (DropTable) SQL

func (dt DropTable) SQL() string

func (*DropTable) String

func (dt *DropTable) String() 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    []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

func (fk ForeignKey) Pos() Position

func (ForeignKey) SQL

func (fk ForeignKey) SQL() string

type Func

type Func struct {
	Name string
	Args []Expr
}

Func represents a function call.

func (Func) SQL

func (f Func) SQL() string

type ID

type ID string

ID represents an identifier.

func (ID) SQL

func (id ID) SQL() string

type InOp

type InOp struct {
	LHS    Expr
	Neg    bool
	RHS    []Expr
	Unnest bool
}

func (InOp) SQL

func (io InOp) 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

type Interleave struct {
	Parent   string
	OnDelete OnDelete
}

Interleave represents an interleave clause of a CREATE TABLE statement.

type IsExpr

type IsExpr interface {
	SQL() string
	// contains filtered or unexported methods
}

type IsOp

type IsOp struct {
	LHS Expr
	Neg bool
	RHS IsExpr
}

func (IsOp) SQL

func (io IsOp) SQL() string

type KeyPart

type KeyPart struct {
	Column string
	Desc   bool
}

KeyPart represents a column specification as part of a primary key or index definition.

func (KeyPart) SQL

func (kp KeyPart) SQL() string

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 Neg, BitNot
}

func (LogicalOp) SQL

func (lo LogicalOp) SQL() string

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 (n NullLiteral) SQL() string

type OnDelete

type OnDelete int
const (
	NoActionOnDelete OnDelete = iota
	CascadeOnDelete
)

func (OnDelete) SQL

func (od OnDelete) SQL() string

type Order

type Order struct {
	Expr Expr
	Desc bool
}

func (Order) SQL

func (o Order) SQL() string

type Param

type Param string

Param represents a query parameter.

func (Param) SQL

func (p Param) SQL() string

type Paren

type Paren struct {
	Expr Expr
}

Paren represents a parenthesised expression.

func (Paren) SQL

func (p Paren) SQL() string

type Position

type Position struct {
	Line   int // 1-based line number
	Offset int // 0-based byte offset
}

Position describes a source position in an input DDL file. It is only valid if the line number is positive.

func (Position) IsValid

func (pos Position) IsValid() bool

func (Position) String

func (pos Position) String() 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

func ParseQuery(s string) (Query, error)

ParseQuery parses a query string.

func (Query) SQL

func (q Query) SQL() string

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

func (Select) SQL

func (sel Select) SQL() string

type SelectFrom

type SelectFrom struct {
	// This only supports a FROM clause directly from a table.
	Table string
	Alias string // empty if not aliased

	TableSample *TableSample // TODO: This isn't part of from_item; move elsewhere.
}

type SetColumnOptions

type SetColumnOptions struct{ Options ColumnOptions }

func (SetColumnOptions) SQL

func (sco SetColumnOptions) SQL() string

type SetColumnType

type SetColumnType struct {
	Type    Type
	NotNull bool
}

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

func (StarExpr) 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

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

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 Type

type Type struct {
	Array bool
	Base  TypeBase // Bool, Int64, Float64, String, Bytes, Date, Timestamp
	Len   int64    // if Base is String or Bytes; may be MaxLen
}

Type represents a column type.

func (Type) SQL

func (t Type) SQL() string

type TypeBase

type TypeBase int
const (
	Bool TypeBase = iota
	Int64
	Float64
	String
	Bytes
	Date
	Timestamp
)

func (TypeBase) SQL

func (tb TypeBase) SQL() string

Source Files

keywords.go parser.go sql.go types.go

Version
v1.9.0
Published
Aug 17, 2020
Platform
windows/amd64
Imports
7 packages
Last checked
2 minutes ago

Tools for package owners.