Package cloud.google.com/go/spanner/spansql (v1.62.0)

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

Constants

True, False

const (
	True  = BoolLiteral(true)
	False = BoolLiteral(false)
)

MaxLen

const MaxLen = math.MaxInt64

MaxLen is a sentinel for Type's Len field, representing the MAX value.

Null

const Null = NullLiteral(0)

Star

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.

AddColumn

type AddColumn struct {
	IfNotExists bool
	Def         ColumnDef
}

func (AddColumn) SQL

func (ac AddColumn) SQL() string

AddConstraint

type AddConstraint struct{ Constraint TableConstraint }

func (AddConstraint) SQL

func (ac AddConstraint) SQL() string

AddRowDeletionPolicy

type AddRowDeletionPolicy struct{ RowDeletionPolicy RowDeletionPolicy }

func (AddRowDeletionPolicy) SQL

func (ardp AddRowDeletionPolicy) SQL() string

AddStoredColumn

type AddStoredColumn struct{ Name ID }

func (AddStoredColumn) SQL

func (asc AddStoredColumn) SQL() string

AddSynonym

type AddSynonym struct{ Name ID }

func (AddSynonym) SQL

func (as AddSynonym) SQL() string

AggregateHaving

type AggregateHaving struct {
	Condition AggregateHavingCondition
	Expr      Expr
}

AggregateHaving represents the HAVING clause specific to aggregate functions, restricting rows based on a maximal or minimal value.

AggregateHavingCondition

type AggregateHavingCondition int

AggregateHavingCondition represents the condition (MAX or MIN) for the AggregateHaving clause.

HavingMax, HavingMin

const (
	HavingMax AggregateHavingCondition = iota
	HavingMin
)

AlterChangeStream

type AlterChangeStream struct {
	Name       ID
	Alteration ChangeStreamAlteration

	Position Position
}

AlterChangeStream represents a ALTER CHANGE STREAM statement.

func (*AlterChangeStream) Pos

func (acs *AlterChangeStream) Pos() Position

func (AlterChangeStream) SQL

func (acs AlterChangeStream) SQL() string

func (*AlterChangeStream) String

func (acs *AlterChangeStream) String() string

AlterChangeStreamOptions

type AlterChangeStreamOptions struct{ Options ChangeStreamOptions }

func (AlterChangeStreamOptions) SQL

AlterColumn

type AlterColumn struct {
	Name       ID
	Alteration ColumnAlteration
}

func (AlterColumn) SQL

func (ac AlterColumn) SQL() string

AlterDatabase

type AlterDatabase struct {
	Name       ID
	Alteration DatabaseAlteration

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

AlterDatabase represents an ALTER DATABASE statement. https://cloud.google.com/spanner/docs/data-definition-language#alter-database

func (*AlterDatabase) Pos

func (ad *AlterDatabase) Pos() Position

func (AlterDatabase) SQL

func (ad AlterDatabase) SQL() string

func (*AlterDatabase) String

func (ad *AlterDatabase) String() string

AlterIndex

type AlterIndex struct {
	Name       ID
	Alteration IndexAlteration

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

func (*AlterIndex) Pos

func (as *AlterIndex) Pos() Position

func (AlterIndex) SQL

func (ai AlterIndex) SQL() string

func (*AlterIndex) String

func (as *AlterIndex) String() string

AlterSequence

type AlterSequence struct {
	Name       ID
	Alteration SequenceAlteration

	Position Position
}

func (*AlterSequence) Pos

func (as *AlterSequence) Pos() Position

func (AlterSequence) SQL

func (as AlterSequence) SQL() string

func (*AlterSequence) String

func (as *AlterSequence) String() string

AlterStatistics

type AlterStatistics struct {
	Name       ID
	Alteration StatisticsAlteration

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

AlterStatistics represents an ALTER STATISTICS statement. https://cloud.google.com/spanner/docs/data-definition-language#alter-statistics

func (*AlterStatistics) Pos

func (as *AlterStatistics) Pos() Position

func (AlterStatistics) SQL

func (as AlterStatistics) SQL() string

func (*AlterStatistics) String

func (as *AlterStatistics) String() string

AlterTable

type AlterTable struct {
	Name       ID
	Alteration TableAlteration

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

func (*AlterTable) Pos

func (at *AlterTable) Pos() Position

func (AlterTable) SQL

func (at AlterTable) SQL() string

func (*AlterTable) String

func (at *AlterTable) String() string

AlterWatch

type AlterWatch struct {
	WatchAllTables bool
	Watch          []WatchDef
}

func (AlterWatch) SQL

func (scsw AlterWatch) SQL() string

ArithOp

type ArithOp struct {
	Op       ArithOperator
	LHS, RHS Expr // only RHS is set for Neg, Plus, BitNot
}

func (ArithOp) SQL

func (ao ArithOp) SQL() string

ArithOperator

type ArithOperator int

Neg, Plus, BitNot, Mul, Div, Concat, Add, Sub, BitShl, BitShr, BitAnd, BitXor, BitOr

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

Array

type Array []Expr

Array represents an array literal.

func (Array) SQL

func (a Array) SQL() string

AtTimeZoneExpr

type AtTimeZoneExpr struct {
	Expr Expr
	Type Type
	Zone string
}

func (AtTimeZoneExpr) SQL

func (aze AtTimeZoneExpr) SQL() string

BoolExpr

type BoolExpr interface {
	Expr
	// contains filtered or unexported methods
}

BoolLiteral

type BoolLiteral bool

func (BoolLiteral) SQL

func (b BoolLiteral) SQL() string

BytesLiteral

type BytesLiteral string

func (BytesLiteral) SQL

func (bl BytesLiteral) SQL() string

Case

type Case struct {
	Expr        Expr
	WhenClauses []WhenClause
	ElseResult  Expr
}

func (Case) SQL

func (c Case) SQL() string

ChangeStreamAlteration

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

ChangeStreamOptions

type ChangeStreamOptions struct {
	RetentionPeriod  *string
	ValueCaptureType *string
}

func (ChangeStreamOptions) SQL

func (cso ChangeStreamOptions) SQL() string

Check

type Check struct {
	Expr BoolExpr

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

Check represents a check constraint as part of a CREATE TABLE or ALTER TABLE statement.

func (Check) Pos

func (c Check) Pos() Position

func (Check) SQL

func (c Check) SQL() string

Coalesce

type Coalesce struct {
	ExprList []Expr
}

func (Coalesce) SQL

func (c Coalesce) SQL() string

ColumnAlteration

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

ColumnAlteration is satisfied by SetColumnType and SetColumnOptions.

ColumnDef

type ColumnDef struct {
	Name    ID
	Type    Type
	NotNull bool

	Default   Expr // set if this column has a default value
	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 (cd ColumnDef) Pos() Position

func (ColumnDef) SQL

func (cd ColumnDef) SQL() string

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

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

ComparisonOp

type ComparisonOp struct {
	Op       ComparisonOperator
	LHS, RHS Expr

	// RHS2 is the third operand for BETWEEN.
	// "

func (ComparisonOp) SQL

func (co ComparisonOp) SQL() string

ComparisonOperator

type ComparisonOperator int

Lt, Le, Gt, Ge, Eq, Ne, Like, NotLike, Between, NotBetween

const (
	Lt ComparisonOperator = iota
	Le
	Gt
	Ge
	Eq
	Ne // both "!=" and "<>"
	Like
	NotLike
	Between
	NotBetween
)

Constraint

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

CreateChangeStream

type CreateChangeStream struct {
	Name           ID
	Watch          []WatchDef
	WatchAllTables bool
	Options        ChangeStreamOptions

	Position Position
}

CreateChangeStream represents a CREATE CHANGE STREAM statement. https://cloud.google.com/spanner/docs/change-streams/manage

func (*CreateChangeStream) Pos

func (cs *CreateChangeStream) Pos() Position

func (CreateChangeStream) SQL

func (cs CreateChangeStream) SQL() string

func (*CreateChangeStream) String

func (cs *CreateChangeStream) String() string

CreateIndex

type CreateIndex struct {
	Name    ID
	Table   ID
	Columns []KeyPart

	Unique       bool
	NullFiltered bool
	IfNotExists  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

CreateRole

type CreateRole struct {
	Name ID

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

func (*CreateRole) Pos

func (cr *CreateRole) Pos() Position

func (CreateRole) SQL

func (cr CreateRole) SQL() string

func (*CreateRole) String

func (cr *CreateRole) String() string

CreateSequence

type CreateSequence struct {
	Name        ID
	IfNotExists bool
	Options     SequenceOptions

	Position Position
}

func (*CreateSequence) Pos

func (cs *CreateSequence) Pos() Position

func (CreateSequence) SQL

func (cs CreateSequence) SQL() string

func (*CreateSequence) String

func (cs *CreateSequence) String() string

CreateTable

type CreateTable struct {
	Name              ID
	IfNotExists       bool
	Columns           []ColumnDef
	Constraints       []TableConstraint
	PrimaryKey        []KeyPart
	Interleave        *Interleave
	RowDeletionPolicy *RowDeletionPolicy
	Synonym           ID // may be empty

	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

CreateView

type CreateView struct {
	Name         ID
	OrReplace    bool
	SecurityType SecurityType
	Query        Query

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

CreateView represents a CREATE [OR REPLACE] VIEW statement. https://cloud.google.com/spanner/docs/data-definition-language#view_statements

func (*CreateView) Pos

func (cv *CreateView) Pos() Position

func (CreateView) SQL

func (cv CreateView) SQL() string

func (*CreateView) String

func (cv *CreateView) String() string

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 (d *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 (d *DDL) LeadingComment(n Node) *Comment

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

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.

DML

type DML struct {
	List []DMLStmt

	Filename string // if known at parse time

	Comments []*Comment // all comments, sorted by position
}

DML represents a Data Manipulation Language (DML) file.

func ParseDML

func ParseDML(filename, s string) (*DML, error)

ParseDML parses a DML file.

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

func (*DML) InlineComment

func (d *DML) 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 (*DML) LeadingComment

func (d *DML) LeadingComment(n Node) *Comment

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

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.

DatabaseAlteration

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

DatabaseOptions

type DatabaseOptions struct {
	OptimizerVersion           *int
	OptimizerStatisticsPackage *string
	VersionRetentionPeriod     *string
	EnableKeyVisualizer        *bool
	DefaultLeader              *string
}

DatabaseOptions represents options on a database as part of a ALTER DATABASE statement.

func (DatabaseOptions) SQL

func (do DatabaseOptions) SQL() string

DateLiteral

type DateLiteral civil.Date

DateLiteral represents a date literal. https://cloud.google.com/spanner/docs/lexical#date_literals

func (DateLiteral) SQL

func (dl DateLiteral) SQL() string

Delete

type Delete struct {
	Table ID
	Where BoolExpr
}

func (*Delete) SQL

func (d *Delete) SQL() string

func (*Delete) String

func (d *Delete) String() string

DropChangeStream

type DropChangeStream struct {
	Name ID

	Position Position
}

DropChangeStream represents a DROP CHANGE STREAM statement.

func (*DropChangeStream) Pos

func (dc *DropChangeStream) Pos() Position

func (DropChangeStream) SQL

func (dc DropChangeStream) SQL() string

func (*DropChangeStream) String

func (dc *DropChangeStream) String() string

DropChangeStreamWatch

type DropChangeStreamWatch struct{}

func (DropChangeStreamWatch) SQL

func (dcsw DropChangeStreamWatch) SQL() string

DropColumn

type DropColumn struct{ Name ID }

func (DropColumn) SQL

func (dc DropColumn) SQL() string

DropConstraint

type DropConstraint struct{ Name ID }

func (DropConstraint) SQL

func (dc DropConstraint) SQL() string

DropDefault

type DropDefault struct{}

func (DropDefault) SQL

func (dp DropDefault) SQL() string

DropIndex

type DropIndex struct {
	Name     ID
	IfExists bool

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

func (*DropIndex) Pos

func (di *DropIndex) Pos() Position

func (DropIndex) SQL

func (di DropIndex) SQL() string

func (*DropIndex) String

func (di *DropIndex) String() string

DropRole

type DropRole struct {
	Name ID

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

func (*DropRole) Pos

func (dr *DropRole) Pos() Position

func (DropRole) SQL

func (dr DropRole) SQL() string

func (*DropRole) String

func (dr *DropRole) String() string

DropRowDeletionPolicy

type DropRowDeletionPolicy struct{}

func (DropRowDeletionPolicy) SQL

func (drdp DropRowDeletionPolicy) SQL() string

DropSequence

type DropSequence struct {
	Name     ID
	IfExists bool

	Position Position
}

func (*DropSequence) Pos

func (ds *DropSequence) Pos() Position

func (DropSequence) SQL

func (do DropSequence) SQL() string

func (*DropSequence) String

func (ds *DropSequence) String() string

DropStoredColumn

type DropStoredColumn struct{ Name ID }

func (DropStoredColumn) SQL

func (dsc DropStoredColumn) SQL() string

DropSynonym

type DropSynonym struct{ Name ID }

func (DropSynonym) SQL

func (ds DropSynonym) SQL() string

DropTable

type DropTable struct {
	Name     ID
	IfExists bool

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

func (*DropTable) Pos

func (dt *DropTable) Pos() Position

func (DropTable) SQL

func (dt DropTable) SQL() string

func (*DropTable) String

func (dt *DropTable) String() string

DropView

type DropView struct {
	Name ID

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

func (*DropView) Pos

func (dv *DropView) Pos() Position

func (DropView) SQL

func (dv DropView) SQL() string

func (*DropView) String

func (dv *DropView) String() string

Expr

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

ExtractExpr

type ExtractExpr struct {
	Part string
	Type Type
	Expr Expr
}

func (ExtractExpr) SQL

func (ee ExtractExpr) SQL() string

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

ForeignKey

type ForeignKey struct {
	Columns    []ID
	RefTable   ID
	RefColumns []ID
	OnDelete   OnDelete

	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

Func

type Func struct {
	Name string // not ID
	Args []Expr

	Distinct      bool
	NullsHandling NullsHandling
	Having        *AggregateHaving
}

Func represents a function call.

func (Func) SQL

func (f Func) SQL() string

GrantRole

type GrantRole struct {
	ToRoleNames       []ID
	GrantRoleNames    []ID
	Privileges        []Privilege
	TableNames        []ID
	TvfNames          []ID
	ViewNames         []ID
	ChangeStreamNames []ID

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

func (*GrantRole) Pos

func (gr *GrantRole) Pos() Position

func (GrantRole) SQL

func (gr GrantRole) SQL() string

func (*GrantRole) String

func (gr *GrantRole) String() string

ID

type ID string

func (ID) SQL

func (id ID) SQL() string

If

type If struct {
	Expr       Expr
	TrueResult Expr
	ElseResult Expr
}

func (If) SQL

func (i If) SQL() string

IfNull

type IfNull struct {
	Expr       Expr
	NullResult Expr
}

func (IfNull) SQL

func (in IfNull) SQL() string

InOp

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

func (InOp) SQL

func (io InOp) SQL() string

IndexAlteration

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

Insert

type Insert struct {
	Table   ID
	Columns []ID
	Input   ValuesOrSelect
}

func (*Insert) SQL

func (i *Insert) SQL() string

func (*Insert) String

func (i *Insert) String() string

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

Interleave

type Interleave struct {
	Parent   ID
	OnDelete OnDelete
}

Interleave represents an interleave clause of a CREATE TABLE statement.

IntervalExpr

type IntervalExpr struct {
	Expr     Expr
	DatePart string
}

func (IntervalExpr) SQL

func (ie IntervalExpr) SQL() string

IsExpr

type IsExpr interface {
	Expr
	// contains filtered or unexported methods
}

IsOp

type IsOp struct {
	LHS Expr
	Neg bool
	RHS IsExpr
}

func (IsOp) SQL

func (io IsOp) SQL() string

JSONLiteral

type JSONLiteral []byte

func (JSONLiteral) SQL

func (jl JSONLiteral) SQL() string

JoinType

type JoinType int

InnerJoin, CrossJoin, FullJoin, LeftJoin, RightJoin

const (
	InnerJoin JoinType = iota
	CrossJoin
	FullJoin
	LeftJoin
	RightJoin
)

KeyPart

type KeyPart struct {
	Column ID
	Desc   bool
}

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

func (KeyPart) SQL

func (kp KeyPart) SQL() string

LiteralOrParam

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

LiteralOrParam is implemented by integer literal and parameter values.

LogicalOp

type LogicalOp struct {
	Op       LogicalOperator
	LHS, RHS BoolExpr // only RHS is set for Not
}

func (LogicalOp) SQL

func (lo LogicalOp) SQL() string

LogicalOperator

type LogicalOperator int

And, Or, Not

const (
	And LogicalOperator = iota
	Or
	Not
)

Node

type Node interface {
	Pos() Position
}

Node is implemented by concrete types in this package that represent things appearing in a DDL file.

NullIf

type NullIf struct {
	Expr        Expr
	ExprToMatch Expr
}

func (NullIf) SQL

func (ni NullIf) SQL() string

NullLiteral

type NullLiteral int

func (NullLiteral) SQL

func (NullLiteral) SQL() string

NullsHandling

type NullsHandling int

NullsHandling represents the method of dealing with NULL values in aggregate functions.

NullsHandlingUnspecified, RespectNulls, IgnoreNulls

const (
	NullsHandlingUnspecified NullsHandling = iota
	RespectNulls
	IgnoreNulls
)

OnDelete

type OnDelete int

NoActionOnDelete, CascadeOnDelete

const (
	NoActionOnDelete OnDelete = iota
	CascadeOnDelete
)

func (OnDelete) SQL

func (od OnDelete) SQL() string

Order

type Order struct {
	Expr Expr
	Desc bool
}

func (Order) SQL

func (o Order) SQL() string

Param

type Param string

Param represents a query parameter.

func (Param) SQL

func (p Param) SQL() string

Paren

type Paren struct {
	Expr Expr
}

Paren represents a parenthesised expression.

func (Paren) SQL

func (p Paren) SQL() string

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

func (pe PathExp) SQL() string

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

Privilege

type Privilege struct {
	Type    PrivilegeType
	Columns []ID
}

Privilege represents privilege to grant or revoke.

PrivilegeType

type PrivilegeType int

PrivilegeTypeSelect, PrivilegeTypeInsert, PrivilegeTypeUpdate, PrivilegeTypeDelete

const (
	PrivilegeTypeSelect PrivilegeType = iota
	PrivilegeTypeInsert
	PrivilegeTypeUpdate
	PrivilegeTypeDelete
)

func (PrivilegeType) SQL

func (pt PrivilegeType) SQL() string

Query

type Query struct {
	Select Select
	Order  []Order

	Limit, Offset LiteralOrParam
}

func ParseQuery

func ParseQuery(s string) (Query, error)

ParseQuery parses a query string.

func (Query) SQL

func (q Query) SQL() string

RenameTable

type RenameTable struct {
	TableRenameOps []TableRenameOp

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

RenameTable represents a RENAME TABLE statement.

func (*RenameTable) Pos

func (rt *RenameTable) Pos() Position

func (RenameTable) SQL

func (rt RenameTable) SQL() string

func (*RenameTable) String

func (rt *RenameTable) String() string

RenameTo

type RenameTo struct {
	ToName  ID
	Synonym ID // may be empty
}

func (RenameTo) SQL

func (rt RenameTo) SQL() string

ReplaceRowDeletionPolicy

type ReplaceRowDeletionPolicy struct{ RowDeletionPolicy RowDeletionPolicy }

func (ReplaceRowDeletionPolicy) SQL

func (rrdp ReplaceRowDeletionPolicy) SQL() string

RevokeRole

type RevokeRole struct {
	FromRoleNames     []ID
	RevokeRoleNames   []ID
	Privileges        []Privilege
	TableNames        []ID
	TvfNames          []ID
	ViewNames         []ID
	ChangeStreamNames []ID
	Position          Position // position of the "REVOKE" token
}

func (*RevokeRole) Pos

func (rr *RevokeRole) Pos() Position

func (RevokeRole) SQL

func (rr RevokeRole) SQL() string

func (*RevokeRole) String

func (rr *RevokeRole) String() string

RowDeletionPolicy

type RowDeletionPolicy struct {
	Column  ID
	NumDays int64
}

RowDeletionPolicy represents an row deletion policy clause of a CREATE, ALTER TABLE statement.

func (RowDeletionPolicy) SQL

func (rdp RowDeletionPolicy) SQL() string

SecurityType

type SecurityType int

Invoker, Definer

const (
	Invoker SecurityType = iota
	Definer
)

func (SecurityType) SQL

func (st SecurityType) SQL() string

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
}

func (Select) SQL

func (sel Select) SQL() string

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

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

SelectFromTable

type SelectFromTable struct {
	Table ID
	Alias ID // empty if not aliased
	Hints map[string]string
}

SelectFromTable is a SelectFrom that specifies a table to read from.

func (SelectFromTable) SQL

func (sft SelectFromTable) SQL() string

SelectFromUnnest

type SelectFromUnnest struct {
	Expr  Expr
	Alias ID // empty if not aliased

}

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

SequenceAlteration

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

SequenceExpr

type SequenceExpr struct {
	Name ID
}

func (SequenceExpr) SQL

func (se SequenceExpr) SQL() string

SequenceOptions

type SequenceOptions struct {
	SequenceKind     *string
	SkipRangeMin     *int
	SkipRangeMax     *int
	StartWithCounter *int
}

SequenceOptions represents options on a sequence as part of a CREATE SEQUENCE and ALTER SEQUENCE statement.

func (SequenceOptions) SQL

func (so SequenceOptions) SQL() string

SetColumnOptions

type SetColumnOptions struct{ Options ColumnOptions }

func (SetColumnOptions) SQL

func (sco SetColumnOptions) SQL() string

SetColumnType

type SetColumnType struct {
	Type    Type
	NotNull bool
	Default Expr
}

func (SetColumnType) SQL

func (sct SetColumnType) SQL() string

SetDatabaseOptions

type SetDatabaseOptions struct{ Options DatabaseOptions }

func (SetDatabaseOptions) SQL

func (sdo SetDatabaseOptions) SQL() string

SetDefault

type SetDefault struct {
	Default Expr
}

func (SetDefault) SQL

func (sd SetDefault) SQL() string

SetOnDelete

type SetOnDelete struct{ Action OnDelete }

func (SetOnDelete) SQL

func (sod SetOnDelete) SQL() string

SetSequenceOptions

type SetSequenceOptions struct{ Options SequenceOptions }

func (SetSequenceOptions) SQL

func (sa SetSequenceOptions) SQL() string

SetStatisticsOptions

type SetStatisticsOptions struct{ Options StatisticsOptions }

func (SetStatisticsOptions) SQL

func (sso SetStatisticsOptions) SQL() string

StarExpr

type StarExpr int

func (StarExpr) SQL

func (StarExpr) SQL() string

StatisticsAlteration

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

StatisticsOptions

type StatisticsOptions struct {
	AllowGC *bool
}

StatisticsOptions represents options on a statistics as part of a ALTER STATISTICS statement.

func (StatisticsOptions) SQL

func (sa StatisticsOptions) SQL() string

StringLiteral

type StringLiteral string

func (StringLiteral) SQL

func (sl StringLiteral) SQL() string

TableAlteration

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

TableAlteration is satisfied by AddColumn, DropColumn, AddConstraint, DropConstraint, SetOnDelete, AlterColumn, AddRowDeletionPolicy, ReplaceRowDeletionPolicy, DropRowDeletionPolicy, RenameTo, AddSynonym, and DropSynonym.

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

TableRenameOp

type TableRenameOp struct {
	FromName ID
	ToName   ID
}

TableSample

type TableSample struct {
	Method   TableSampleMethod
	Size     Expr
	SizeType TableSampleSizeType
}

TableSampleMethod

type TableSampleMethod int

Bernoulli, Reservoir

const (
	Bernoulli TableSampleMethod = iota
	Reservoir
)

TableSampleSizeType

type TableSampleSizeType int

PercentTableSample, RowsTableSample

const (
	PercentTableSample TableSampleSizeType = iota
	RowsTableSample
)

TimestampLiteral

type TimestampLiteral time.Time

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

func (t Type) SQL() string

TypeBase

type TypeBase int

Bool, Int64, Float64, Numeric, String, Bytes, Date, Timestamp, JSON

const (
	Bool TypeBase = iota
	Int64
	Float64
	Numeric
	String
	Bytes
	Date
	Timestamp
	JSON
)

func (TypeBase) SQL

func (tb TypeBase) SQL() string

TypedExpr

type TypedExpr struct {
	Type Type
	Expr Expr
}

TypedExpr represents a typed expression in the form expr AS type_name, e.g. '17' AS INT64.

func (TypedExpr) SQL

func (te TypedExpr) SQL() string

Update

type Update struct {
	Table ID
	Items []UpdateItem
	Where BoolExpr
}

func (*Update) SQL

func (u *Update) SQL() string

func (*Update) String

func (u *Update) String() string

UpdateItem

type UpdateItem struct {
	Column ID
	Value  Expr // or nil for DEFAULT
}

Values

type Values [][]Expr

Values represents one or more lists of expressions passed to an INSERT statement.

func (Values) SQL

func (v Values) SQL() string

func (Values) String

func (v Values) String() string

ValuesOrSelect

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

WatchDef

type WatchDef struct {
	Table        ID
	Columns      []ID
	WatchAllCols bool

	Position Position
}

func (WatchDef) Pos

func (wd WatchDef) Pos() Position

func (WatchDef) SQL

func (w WatchDef) SQL() string

WhenClause

type WhenClause struct {
	Cond   Expr
	Result Expr
}