spansql

package
v1.73.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 10 Imported by: 82

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

View Source
const (
	True  = BoolLiteral(true)
	False = BoolLiteral(false)
)
View Source
const MaxLen = math.MaxInt64

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

View Source
const Null = NullLiteral(0)
View Source
const Star = StarExpr(0)

Star represents a "*" in an expression.

Variables

This section is empty.

Functions

func IsKeyword added in v1.2.1

func IsKeyword(id string) bool

IsKeyword reports whether the identifier is a reserved keyword.

Types

type AddColumn

type AddColumn struct {
	IfNotExists bool
	Def         ColumnDef
}

func (AddColumn) SQL

func (ac AddColumn) SQL() string

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 AddRowDeletionPolicy added in v1.24.0

type AddRowDeletionPolicy struct{ RowDeletionPolicy RowDeletionPolicy }

func (AddRowDeletionPolicy) SQL added in v1.24.0

func (ardp AddRowDeletionPolicy) SQL() string

type AddStoredColumn added in v1.44.0

type AddStoredColumn struct{ Name ID }

func (AddStoredColumn) SQL added in v1.44.0

func (asc AddStoredColumn) SQL() string

type AddSynonym added in v1.59.0

type AddSynonym struct{ Name ID }

func (AddSynonym) SQL added in v1.59.0

func (as AddSynonym) SQL() string

type AggregateHaving added in v1.50.0

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.

type AggregateHavingCondition added in v1.50.0

type AggregateHavingCondition int

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

const (
	HavingMax AggregateHavingCondition = iota
	HavingMin
)

type AlterChangeStream added in v1.39.0

type AlterChangeStream struct {
	Name       ID
	Alteration ChangeStreamAlteration

	Position Position
}

AlterChangeStream represents a ALTER CHANGE STREAM statement.

func (*AlterChangeStream) Pos added in v1.39.0

func (acs *AlterChangeStream) Pos() Position

func (AlterChangeStream) SQL added in v1.39.0

func (acs AlterChangeStream) SQL() string

func (*AlterChangeStream) String added in v1.39.0

func (acs *AlterChangeStream) String() string

type AlterChangeStreamOptions added in v1.39.0

type AlterChangeStreamOptions struct{ Options ChangeStreamOptions }

func (AlterChangeStreamOptions) SQL added in v1.39.0

type AlterColumn added in v1.3.0

type AlterColumn struct {
	Name       ID
	Alteration ColumnAlteration
}

func (AlterColumn) SQL added in v1.3.0

func (ac AlterColumn) SQL() string

type AlterDatabase added in v1.24.0

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 added in v1.24.0

func (ad *AlterDatabase) Pos() Position

func (AlterDatabase) SQL added in v1.24.0

func (ad AlterDatabase) SQL() string

func (*AlterDatabase) String added in v1.24.0

func (ad *AlterDatabase) String() string

type AlterIndex added in v1.44.0

type AlterIndex struct {
	Name       ID
	Alteration IndexAlteration

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

func (*AlterIndex) Pos added in v1.44.0

func (as *AlterIndex) Pos() Position

func (AlterIndex) SQL added in v1.44.0

func (ai AlterIndex) SQL() string

func (*AlterIndex) String added in v1.44.0

func (as *AlterIndex) String() string

type AlterProtoBundle added in v1.72.0

type AlterProtoBundle struct {
	AddTypes, UpdateTypes, DeleteTypes []string
	Position                           Position
}

AlterProtoBundle represents a ALTER PROTO BUNDLE statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#alter-proto-bundle

func (*AlterProtoBundle) Pos added in v1.72.0

func (ap *AlterProtoBundle) Pos() Position

func (AlterProtoBundle) SQL added in v1.72.0

func (ap AlterProtoBundle) SQL() string

func (*AlterProtoBundle) String added in v1.72.0

func (ap *AlterProtoBundle) String() string

type AlterSequence added in v1.50.0

type AlterSequence struct {
	Name       ID
	Alteration SequenceAlteration

	Position Position
}

AlterSequence represents an ALTER SEQUENCE statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#alter-sequence

func (*AlterSequence) Pos added in v1.50.0

func (as *AlterSequence) Pos() Position

func (AlterSequence) SQL added in v1.50.0

func (as AlterSequence) SQL() string

func (*AlterSequence) String added in v1.50.0

func (as *AlterSequence) String() string

type AlterStatistics added in v1.44.0

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 added in v1.44.0

func (as *AlterStatistics) Pos() Position

func (AlterStatistics) SQL added in v1.44.0

func (as AlterStatistics) SQL() string

func (*AlterStatistics) String added in v1.44.0

func (as *AlterStatistics) String() 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 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 AlterWatch added in v1.39.0

type AlterWatch struct {
	WatchAllTables bool
	Watch          []WatchDef
}

func (AlterWatch) SQL added in v1.45.0

func (scsw AlterWatch) SQL() string

type ArithOp added in v1.2.1

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

func (ArithOp) SQL added in v1.2.1

func (ao ArithOp) SQL() string

type ArithOperator added in v1.2.1

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

type Array added in v1.13.0

type Array []Expr

Array represents an array literal.

func (Array) SQL added in v1.13.0

func (a Array) SQL() string

type AtTimeZoneExpr added in v1.29.0

type AtTimeZoneExpr struct {
	Expr Expr
	Type Type
	Zone string
}

func (AtTimeZoneExpr) SQL added in v1.29.0

func (aze AtTimeZoneExpr) SQL() string

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 Case added in v1.31.0

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

func (Case) SQL added in v1.31.0

func (c Case) SQL() string

type ChangeStreamAlteration added in v1.39.0

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

type ChangeStreamOptions added in v1.39.0

type ChangeStreamOptions struct {
	RetentionPeriod  *string
	ValueCaptureType *string
}

func (ChangeStreamOptions) SQL added in v1.43.0

func (cso ChangeStreamOptions) SQL() string

type Check added in v1.11.0

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 added in v1.11.0

func (c Check) Pos() Position

func (Check) SQL added in v1.11.0

func (c Check) SQL() string

type Coalesce added in v1.38.0

type Coalesce struct {
	ExprList []Expr
}

func (Coalesce) SQL added in v1.38.0

func (c Coalesce) SQL() string

type ColumnAlteration added in v1.9.0

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

	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 added in v1.2.1

func (cd ColumnDef) Pos() Position

func (ColumnDef) SQL

func (cd ColumnDef) SQL() string

type ColumnOptions added in v1.9.0

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 added in v1.9.0

func (co ColumnOptions) SQL() string

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.

func (*Comment) Pos added in v1.2.1

func (c *Comment) Pos() Position

func (*Comment) String added in v1.2.1

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 Constraint added in v1.11.0

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

type CreateChangeStream added in v1.39.0

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 added in v1.39.0

func (cs *CreateChangeStream) Pos() Position

func (CreateChangeStream) SQL added in v1.39.0

func (cs CreateChangeStream) SQL() string

func (*CreateChangeStream) String added in v1.39.0

func (cs *CreateChangeStream) String() string

type 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 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 CreateProtoBundle added in v1.72.0

type CreateProtoBundle struct {
	Types    []string
	Position Position
}

CreateProtoBundle represents a CREATE PROTO BUNDLE statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#create-proto-bundle

func (*CreateProtoBundle) Pos added in v1.72.0

func (cp *CreateProtoBundle) Pos() Position

func (CreateProtoBundle) SQL added in v1.72.0

func (cp CreateProtoBundle) SQL() string

func (*CreateProtoBundle) String added in v1.72.0

func (cp *CreateProtoBundle) String() string

type CreateRole added in v1.45.0

type CreateRole struct {
	Name ID

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

CreateRole represents a CREATE Role statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#create_role

func (*CreateRole) Pos added in v1.45.0

func (cr *CreateRole) Pos() Position

func (CreateRole) SQL added in v1.45.0

func (cr CreateRole) SQL() string

func (*CreateRole) String added in v1.45.0

func (cr *CreateRole) String() string

type CreateSequence added in v1.50.0

type CreateSequence struct {
	Name        ID
	IfNotExists bool
	Options     SequenceOptions

	Position Position
}

CreateSequence represents an ALTER SEQUENCE statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#create-sequence

func (*CreateSequence) Pos added in v1.50.0

func (cs *CreateSequence) Pos() Position

func (CreateSequence) SQL added in v1.50.0

func (cs CreateSequence) SQL() string

func (*CreateSequence) String added in v1.50.0

func (cs *CreateSequence) String() string

type 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 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 CreateView added in v1.26.0

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 added in v1.26.0

func (cv *CreateView) Pos() Position

func (CreateView) SQL added in v1.26.0

func (cv CreateView) SQL() string

func (*CreateView) String added in v1.26.0

func (cv *CreateView) 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 added in v1.2.1

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 added in v1.2.1

func (d *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 DML added in v1.36.0

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 added in v1.36.0

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 added in v1.36.0

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 added in v1.36.0

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

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

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

func ParseDMLStmt(s string) (DMLStmt, error)

ParseDMLStmt parses a single DML statement.

type DatabaseAlteration added in v1.24.0

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

type DatabaseOptions added in v1.24.0

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 added in v1.24.0

func (do DatabaseOptions) SQL() string

type DateLiteral added in v1.13.0

type DateLiteral civil.Date

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

func (DateLiteral) SQL added in v1.13.0

func (dl DateLiteral) SQL() string

type Delete added in v1.2.1

type Delete struct {
	Table ID
	Where BoolExpr
}

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

func (*Delete) SQL added in v1.2.1

func (d *Delete) SQL() string

func (*Delete) String added in v1.2.1

func (d *Delete) String() string

type DropChangeStream added in v1.39.0

type DropChangeStream struct {
	Name ID

	Position Position
}

DropChangeStream represents a DROP CHANGE STREAM statement.

func (*DropChangeStream) Pos added in v1.39.0

func (dc *DropChangeStream) Pos() Position

func (DropChangeStream) SQL added in v1.39.0

func (dc DropChangeStream) SQL() string

func (*DropChangeStream) String added in v1.39.0

func (dc *DropChangeStream) String() string

type DropChangeStreamWatch added in v1.45.0

type DropChangeStreamWatch struct{}

func (DropChangeStreamWatch) SQL added in v1.45.0

func (dcsw DropChangeStreamWatch) SQL() string

type DropColumn

type DropColumn struct{ Name ID }

func (DropColumn) SQL

func (dc DropColumn) SQL() string

type DropConstraint added in v1.3.0

type DropConstraint struct{ Name ID }

func (DropConstraint) SQL added in v1.3.0

func (dc DropConstraint) SQL() string

type DropDefault added in v1.32.0

type DropDefault struct{}

func (DropDefault) SQL added in v1.32.0

func (dp DropDefault) SQL() string

type DropIndex

type DropIndex struct {
	Name     ID
	IfExists bool

	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 added in v1.2.1

func (di *DropIndex) Pos() Position

func (DropIndex) SQL

func (di DropIndex) SQL() string

func (*DropIndex) String added in v1.2.1

func (di *DropIndex) String() string

type DropProtoBundle added in v1.72.0

type DropProtoBundle struct {
	Position Position
}

DropProtoBundle represents a DROP PROTO BUNDLE statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#drop-proto-bundle

func (*DropProtoBundle) Pos added in v1.72.0

func (dp *DropProtoBundle) Pos() Position

func (DropProtoBundle) SQL added in v1.72.0

func (do DropProtoBundle) SQL() string

func (*DropProtoBundle) String added in v1.72.0

func (dp *DropProtoBundle) String() string

type DropRole added in v1.45.0

type DropRole struct {
	Name ID

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

DropRole represents a DROP ROLE statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#drop_role

func (*DropRole) Pos added in v1.45.0

func (dr *DropRole) Pos() Position

func (DropRole) SQL added in v1.45.0

func (dr DropRole) SQL() string

func (*DropRole) String added in v1.45.0

func (dr *DropRole) String() string

type DropRowDeletionPolicy added in v1.24.0

type DropRowDeletionPolicy struct{}

func (DropRowDeletionPolicy) SQL added in v1.24.0

func (drdp DropRowDeletionPolicy) SQL() string

type DropSequence added in v1.50.0

type DropSequence struct {
	Name     ID
	IfExists bool

	Position Position
}

DropSequence represents a DROP SEQUENCE statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#drop-sequence

func (*DropSequence) Pos added in v1.50.0

func (ds *DropSequence) Pos() Position

func (DropSequence) SQL added in v1.50.0

func (do DropSequence) SQL() string

func (*DropSequence) String added in v1.50.0

func (ds *DropSequence) String() string

type DropStoredColumn added in v1.44.0

type DropStoredColumn struct{ Name ID }

func (DropStoredColumn) SQL added in v1.44.0

func (dsc DropStoredColumn) SQL() string

type DropSynonym added in v1.59.0

type DropSynonym struct{ Name ID }

func (DropSynonym) SQL added in v1.59.0

func (ds DropSynonym) SQL() string

type DropTable

type DropTable struct {
	Name     ID
	IfExists bool

	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 added in v1.2.1

func (dt *DropTable) Pos() Position

func (DropTable) SQL

func (dt DropTable) SQL() string

func (*DropTable) String added in v1.2.1

func (dt *DropTable) String() string

type DropView added in v1.26.0

type DropView struct {
	Name ID

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

DropView represents a DROP VIEW statement. https://cloud.google.com/spanner/docs/data-definition-language#drop-view

func (*DropView) Pos added in v1.26.0

func (dv *DropView) Pos() Position

func (DropView) SQL added in v1.26.0

func (dv DropView) SQL() string

func (*DropView) String added in v1.26.0

func (dv *DropView) String() string

type Expr

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

type ExtractExpr added in v1.29.0

type ExtractExpr struct {
	Part string
	Type Type
	Expr Expr
}

func (ExtractExpr) SQL added in v1.29.0

func (ee ExtractExpr) SQL() string

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    []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 added in v1.3.0

func (fk ForeignKey) Pos() Position

func (ForeignKey) SQL added in v1.3.0

func (fk ForeignKey) SQL() string

type 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

type GrantRole added in v1.45.0

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

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

GrantRole represents a GRANT statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#grant_statement

func (*GrantRole) Pos added in v1.45.0

func (gr *GrantRole) Pos() Position

func (GrantRole) SQL added in v1.45.0

func (gr GrantRole) SQL() string

func (*GrantRole) String added in v1.45.0

func (gr *GrantRole) String() string

type ID

type ID string

ID represents an identifier. https://cloud.google.com/spanner/docs/lexical#identifiers

func (ID) SQL

func (id ID) SQL() string

type If added in v1.35.0

type If struct {
	Expr       Expr
	TrueResult Expr
	ElseResult Expr
}

func (If) SQL added in v1.35.0

func (i If) SQL() string

type IfNull added in v1.36.0

type IfNull struct {
	Expr       Expr
	NullResult Expr
}

func (IfNull) SQL added in v1.36.0

func (in IfNull) SQL() string

type InOp added in v1.3.0

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

func (InOp) SQL added in v1.3.0

func (io InOp) SQL() string

type IndexAlteration added in v1.44.0

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

type Insert added in v1.34.0

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

Insert represents an INSERT statement. https://cloud.google.com/spanner/docs/dml-syntax#insert-statement

func (*Insert) SQL added in v1.34.0

func (i *Insert) SQL() string

func (*Insert) String added in v1.34.0

func (i *Insert) String() 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   ID
	OnDelete OnDelete
}

Interleave represents an interleave clause of a CREATE TABLE statement.

type IntervalExpr added in v1.40.0

type IntervalExpr struct {
	Expr     Expr
	DatePart string
}

func (IntervalExpr) SQL added in v1.40.0

func (ie IntervalExpr) SQL() string

type IsExpr

type IsExpr interface {
	Expr
	// 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 JSONLiteral added in v1.32.0

type JSONLiteral []byte

JSONLiteral represents a JSON literal https://cloud.google.com/spanner/docs/reference/standard-sql/lexical#json_literals

func (JSONLiteral) SQL added in v1.32.0

func (jl JSONLiteral) SQL() string

type JoinType added in v1.11.0

type JoinType int
const (
	InnerJoin JoinType = iota
	CrossJoin
	FullJoin
	LeftJoin
	RightJoin
)

type 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

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

func (LogicalOp) SQL

func (lo LogicalOp) SQL() string

type LogicalOperator

type LogicalOperator int
const (
	And LogicalOperator = iota
	Or
	Not
)

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 NullIf added in v1.37.0

type NullIf struct {
	Expr        Expr
	ExprToMatch Expr
}

func (NullIf) SQL added in v1.37.0

func (ni NullIf) SQL() string

type NullLiteral

type NullLiteral int

func (NullLiteral) SQL

func (NullLiteral) SQL() string

type NullsHandling added in v1.50.0

type NullsHandling int

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

const (
	NullsHandlingUnspecified NullsHandling = iota
	RespectNulls
	IgnoreNulls
)

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 PathExp added in v1.11.0

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 added in v1.11.0

func (pe PathExp) SQL() string

type Position added in v1.2.1

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 added in v1.2.1

func (pos Position) IsValid() bool

func (Position) String added in v1.2.1

func (pos Position) String() string

type Privilege added in v1.45.0

type Privilege struct {
	Type    PrivilegeType
	Columns []ID
}

Privilege represents privilege to grant or revoke.

type PrivilegeType added in v1.45.0

type PrivilegeType int
const (
	PrivilegeTypeSelect PrivilegeType = iota
	PrivilegeTypeInsert
	PrivilegeTypeUpdate
	PrivilegeTypeDelete
)

func (PrivilegeType) SQL added in v1.45.0

func (pt PrivilegeType) SQL() 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 RenameTable added in v1.59.0

type RenameTable struct {
	TableRenameOps []TableRenameOp

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

RenameTable represents a RENAME TABLE statement.

func (*RenameTable) Pos added in v1.59.0

func (rt *RenameTable) Pos() Position

func (RenameTable) SQL added in v1.59.0

func (rt RenameTable) SQL() string

func (*RenameTable) String added in v1.59.0

func (rt *RenameTable) String() string

type RenameTo added in v1.59.0

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

func (RenameTo) SQL added in v1.59.0

func (rt RenameTo) SQL() string

type ReplaceRowDeletionPolicy added in v1.24.0

type ReplaceRowDeletionPolicy struct{ RowDeletionPolicy RowDeletionPolicy }

func (ReplaceRowDeletionPolicy) SQL added in v1.24.0

func (rrdp ReplaceRowDeletionPolicy) SQL() string

type RevokeRole added in v1.45.0

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

RevokeRole represents a REVOKE statement. https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language#revoke_statement

func (*RevokeRole) Pos added in v1.45.0

func (rr *RevokeRole) Pos() Position

func (RevokeRole) SQL added in v1.45.0

func (rr RevokeRole) SQL() string

func (*RevokeRole) String added in v1.45.0

func (rr *RevokeRole) String() string

type RowDeletionPolicy added in v1.24.0

type RowDeletionPolicy struct {
	Column  ID
	NumDays int64
}

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

func (RowDeletionPolicy) SQL added in v1.24.0

func (rdp RowDeletionPolicy) SQL() string

type SecurityType added in v1.56.0

type SecurityType int
const (
	Invoker SecurityType = iota
	Definer
)

func (SecurityType) SQL added in v1.56.0

func (st SecurityType) SQL() string

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

func (sel Select) SQL() string

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 added in v1.11.0

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 added in v1.11.0

func (sfj SelectFromJoin) SQL() string

type SelectFromTable added in v1.11.0

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 added in v1.11.0

func (sft SelectFromTable) SQL() string

type SelectFromUnnest added in v1.13.0

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 added in v1.13.0

func (sfu SelectFromUnnest) SQL() string

type SequenceAlteration added in v1.50.0

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

type SequenceExpr added in v1.50.0

type SequenceExpr struct {
	Name ID
}

func (SequenceExpr) SQL added in v1.50.0

func (se SequenceExpr) SQL() string

type SequenceOptions added in v1.50.0

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 added in v1.50.0

func (so SequenceOptions) SQL() string

type SetColumnOptions added in v1.9.0

type SetColumnOptions struct{ Options ColumnOptions }

func (SetColumnOptions) SQL added in v1.9.0

func (sco SetColumnOptions) SQL() string

type SetColumnType added in v1.9.0

type SetColumnType struct {
	Type    Type
	NotNull bool
	Default Expr
}

func (SetColumnType) SQL added in v1.9.0

func (sct SetColumnType) SQL() string

type SetDatabaseOptions added in v1.24.0

type SetDatabaseOptions struct{ Options DatabaseOptions }

func (SetDatabaseOptions) SQL added in v1.24.0

func (sdo SetDatabaseOptions) SQL() string

type SetDefault added in v1.32.0

type SetDefault struct {
	Default Expr
}

func (SetDefault) SQL added in v1.32.0

func (sd SetDefault) SQL() string

type SetOnDelete

type SetOnDelete struct{ Action OnDelete }

func (SetOnDelete) SQL

func (sod SetOnDelete) SQL() string

type SetSequenceOptions added in v1.50.0

type SetSequenceOptions struct{ Options SequenceOptions }

func (SetSequenceOptions) SQL added in v1.50.0

func (sa SetSequenceOptions) SQL() string

type SetStatisticsOptions added in v1.44.0

type SetStatisticsOptions struct{ Options StatisticsOptions }

func (SetStatisticsOptions) SQL added in v1.44.0

func (sso SetStatisticsOptions) SQL() string

type StarExpr

type StarExpr int

func (StarExpr) SQL

func (StarExpr) SQL() string

type StatisticsAlteration added in v1.44.0

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

type StatisticsOptions added in v1.44.0

type StatisticsOptions struct {
	AllowGC *bool
}

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

func (StatisticsOptions) SQL added in v1.44.0

func (sa StatisticsOptions) 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, AddConstraint, DropConstraint, SetOnDelete, AlterColumn, AddRowDeletionPolicy, ReplaceRowDeletionPolicy, DropRowDeletionPolicy, RenameTo, AddSynonym, and DropSynonym.

type TableConstraint added in v1.3.0

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 added in v1.3.0

func (tc TableConstraint) Pos() Position

func (TableConstraint) SQL added in v1.3.0

func (tc TableConstraint) SQL() string

type TableRenameOp added in v1.59.0

type TableRenameOp struct {
	FromName ID
	ToName   ID
}

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 added in v1.13.0

type TimestampLiteral time.Time

TimestampLiteral represents a timestamp literal. https://cloud.google.com/spanner/docs/lexical#timestamp_literals

func (TimestampLiteral) SQL added in v1.13.0

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
	// fully-qualified Protocol Buffer Message or Enum type-name (including
	// leading dot-separated namespace)
	// non-empty if Base is ProtoMessage or ProtoEnum
	ProtoRef string
}

Type represents a column type.

func (Type) SQL

func (t Type) SQL() string

type TypeBase

type TypeBase int
const (
	Bool TypeBase = iota
	Int64
	Float64
	Numeric
	String
	Bytes
	Date
	Timestamp
	JSON
	Proto
	Enum // Enum used in CAST expressions
)

func (TypeBase) SQL

func (tb TypeBase) SQL() string

type TypedExpr added in v1.28.0

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 added in v1.28.0

func (te TypedExpr) SQL() string

type Update added in v1.13.0

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 added in v1.13.0

func (u *Update) SQL() string

func (*Update) String added in v1.13.0

func (u *Update) String() string

type UpdateItem added in v1.13.0

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

type Values added in v1.34.0

type Values [][]Expr

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

func (Values) SQL added in v1.34.0

func (v Values) SQL() string

func (Values) String added in v1.34.0

func (v Values) String() string

type ValuesOrSelect added in v1.34.0

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

type WatchDef added in v1.39.0

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

	Position Position
}

func (WatchDef) Pos added in v1.39.0

func (wd WatchDef) Pos() Position

func (WatchDef) SQL added in v1.45.0

func (w WatchDef) SQL() string

type WhenClause added in v1.31.0

type WhenClause struct {
	Cond   Expr
	Result Expr
}

Jump to

Keyboard shortcuts

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