go: cloud.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

Package Files

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

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.

func IsKeyword Uses

func IsKeyword(id string) bool

IsKeyword reports whether the identifier is a reserved keyword.

type AddColumn Uses

type AddColumn struct{ Def ColumnDef }

func (AddColumn) SQL Uses

func (ac AddColumn) SQL() string

type AddConstraint Uses

type AddConstraint struct{ Constraint TableConstraint }

func (AddConstraint) SQL Uses

func (ac AddConstraint) SQL() string

type AlterColumn Uses

type AlterColumn struct {
    Name       ID
    Alteration ColumnAlteration
}

func (AlterColumn) SQL Uses

func (ac AlterColumn) SQL() string

type AlterTable Uses

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 Uses

func (at *AlterTable) Pos() Position

func (AlterTable) SQL Uses

func (at AlterTable) SQL() string

func (*AlterTable) String Uses

func (at *AlterTable) String() string

type ArithOp Uses

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

func (ArithOp) SQL Uses

func (ao ArithOp) SQL() string

type ArithOperator Uses

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

type Array Uses

type Array []Expr

Array represents an array literal.

func (Array) SQL Uses

func (a Array) SQL() string

type BoolExpr Uses

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

type BoolLiteral Uses

type BoolLiteral bool

func (BoolLiteral) SQL Uses

func (b BoolLiteral) SQL() string

type BytesLiteral Uses

type BytesLiteral string

BytesLiteral represents a bytes literal. https://cloud.google.com/spanner/docs/lexical#string-and-bytes-literals

func (BytesLiteral) SQL Uses

func (bl BytesLiteral) SQL() string

type Check Uses

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 Uses

func (c Check) Pos() Position

func (Check) SQL Uses

func (c Check) SQL() string

type ColumnAlteration Uses

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

ColumnAlteration is satisfied by SetColumnType and SetColumnOptions.

type ColumnDef Uses

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 Uses

func (cd ColumnDef) Pos() Position

func (ColumnDef) SQL Uses

func (cd ColumnDef) SQL() string

type ColumnOptions Uses

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 Uses

func (co ColumnOptions) SQL() string

type Comment Uses

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 Uses

func (c *Comment) Pos() Position

func (*Comment) String Uses

func (c *Comment) String() string

type ComparisonOp Uses

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 Uses

func (co ComparisonOp) SQL() string

type ComparisonOperator Uses

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

type Constraint Uses

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

type CreateIndex Uses

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 Uses

func (ci *CreateIndex) Pos() Position

func (CreateIndex) SQL Uses

func (ci CreateIndex) SQL() string

func (*CreateIndex) String Uses

func (ci *CreateIndex) String() string

type CreateTable Uses

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 Uses

func (ct *CreateTable) Pos() Position

func (CreateTable) SQL Uses

func (ct CreateTable) SQL() string

func (*CreateTable) String Uses

func (ct *CreateTable) String() string

type DDL Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func ParseDDLStmt(s string) (DDLStmt, error)

ParseDDLStmt parses a single DDL statement.

type DMLStmt Uses

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

DMLStmt is satisfied by a type that is a DML statement.

func ParseDMLStmt Uses

func ParseDMLStmt(s string) (DMLStmt, error)

ParseDMLStmt parses a single DML statement.

type DateLiteral Uses

type DateLiteral civil.Date

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

func (DateLiteral) SQL Uses

func (dl DateLiteral) SQL() string

type Delete Uses

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 Uses

func (d *Delete) SQL() string

func (*Delete) String Uses

func (d *Delete) String() string

type DropColumn Uses

type DropColumn struct{ Name ID }

func (DropColumn) SQL Uses

func (dc DropColumn) SQL() string

type DropConstraint Uses

type DropConstraint struct{ Name ID }

func (DropConstraint) SQL Uses

func (dc DropConstraint) SQL() string

type DropIndex Uses

type DropIndex struct {
    Name ID

    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 Uses

func (di *DropIndex) Pos() Position

func (DropIndex) SQL Uses

func (di DropIndex) SQL() string

func (*DropIndex) String Uses

func (di *DropIndex) String() string

type DropTable Uses

type DropTable struct {
    Name ID

    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 Uses

func (dt *DropTable) Pos() Position

func (DropTable) SQL Uses

func (dt DropTable) SQL() string

func (*DropTable) String Uses

func (dt *DropTable) String() string

type Expr Uses

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

type FloatLiteral Uses

type FloatLiteral float64

FloatLiteral represents a floating point literal. https://cloud.google.com/spanner/docs/lexical#floating-point-literals

func (FloatLiteral) SQL Uses

func (fl FloatLiteral) SQL() string

type ForeignKey Uses

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 Uses

func (fk ForeignKey) Pos() Position

func (ForeignKey) SQL Uses

func (fk ForeignKey) SQL() string

type Func Uses

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

Func represents a function call.

func (Func) SQL Uses

func (f Func) SQL() string

type ID Uses

type ID string

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

func (ID) SQL Uses

func (id ID) SQL() string

type InOp Uses

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

func (InOp) SQL Uses

func (io InOp) SQL() string

type IntegerLiteral Uses

type IntegerLiteral int64

IntegerLiteral represents an integer literal. https://cloud.google.com/spanner/docs/lexical#integer-literals

func (IntegerLiteral) SQL Uses

func (il IntegerLiteral) SQL() string

type Interleave Uses

type Interleave struct {
    Parent   ID
    OnDelete OnDelete
}

Interleave represents an interleave clause of a CREATE TABLE statement.

type IsExpr Uses

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

type IsOp Uses

type IsOp struct {
    LHS Expr
    Neg bool
    RHS IsExpr
}

func (IsOp) SQL Uses

func (io IsOp) SQL() string

type JoinType Uses

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

type KeyPart Uses

type KeyPart struct {
    Column ID
    Desc   bool
}

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

func (KeyPart) SQL Uses

func (kp KeyPart) SQL() string

type LiteralOrParam Uses

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

LiteralOrParam is implemented by integer literal and parameter values.

type LogicalOp Uses

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

func (LogicalOp) SQL Uses

func (lo LogicalOp) SQL() string

type LogicalOperator Uses

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

type Node Uses

type Node interface {
    Pos() Position
}

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

type NullLiteral Uses

type NullLiteral int

func (NullLiteral) SQL Uses

func (NullLiteral) SQL() string

type OnDelete Uses

type OnDelete int
const (
    NoActionOnDelete OnDelete = iota
    CascadeOnDelete
)

func (OnDelete) SQL Uses

func (od OnDelete) SQL() string

type Order Uses

type Order struct {
    Expr Expr
    Desc bool
}

func (Order) SQL Uses

func (o Order) SQL() string

type Param Uses

type Param string

Param represents a query parameter.

func (Param) SQL Uses

func (p Param) SQL() string

type Paren Uses

type Paren struct {
    Expr Expr
}

Paren represents a parenthesised expression.

func (Paren) SQL Uses

func (p Paren) SQL() string

type PathExp Uses

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 Uses

func (pe PathExp) SQL() string

type Position Uses

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 Uses

func (pos Position) IsValid() bool

func (Position) String Uses

func (pos Position) String() string

type Query Uses

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 Uses

func ParseQuery(s string) (Query, error)

ParseQuery parses a query string.

func (Query) SQL Uses

func (q Query) SQL() string

type Select Uses

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 Uses

func (sel Select) SQL() string

type SelectFrom Uses

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 Uses

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 Uses

func (sfj SelectFromJoin) SQL() string

type SelectFromTable Uses

type SelectFromTable struct {
    Table ID
    Alias ID  // empty if not aliased
}

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

func (SelectFromTable) SQL Uses

func (sft SelectFromTable) SQL() string

type SelectFromUnnest Uses

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 Uses

func (sfu SelectFromUnnest) SQL() string

type SetColumnOptions Uses

type SetColumnOptions struct{ Options ColumnOptions }

func (SetColumnOptions) SQL Uses

func (sco SetColumnOptions) SQL() string

type SetColumnType Uses

type SetColumnType struct {
    Type    Type
    NotNull bool
}

func (SetColumnType) SQL Uses

func (sct SetColumnType) SQL() string

type SetOnDelete Uses

type SetOnDelete struct{ Action OnDelete }

func (SetOnDelete) SQL Uses

func (sod SetOnDelete) SQL() string

type StarExpr Uses

type StarExpr int

func (StarExpr) SQL Uses

func (StarExpr) SQL() string

type StringLiteral Uses

type StringLiteral string

StringLiteral represents a string literal. https://cloud.google.com/spanner/docs/lexical#string-and-bytes-literals

func (StringLiteral) SQL Uses

func (sl StringLiteral) SQL() string

type TableAlteration Uses

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

TableAlteration is satisfied by AddColumn, DropColumn, AddConstraint, DropConstraint, SetOnDelete and AlterColumn.

type TableConstraint Uses

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 Uses

func (tc TableConstraint) Pos() Position

func (TableConstraint) SQL Uses

func (tc TableConstraint) SQL() string

type TableSample Uses

type TableSample struct {
    Method   TableSampleMethod
    Size     Expr
    SizeType TableSampleSizeType
}

type TableSampleMethod Uses

type TableSampleMethod int
const (
    Bernoulli TableSampleMethod = iota
    Reservoir
)

type TableSampleSizeType Uses

type TableSampleSizeType int
const (
    PercentTableSample TableSampleSizeType = iota
    RowsTableSample
)

type TimestampLiteral Uses

type TimestampLiteral time.Time

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

func (TimestampLiteral) SQL Uses

func (tl TimestampLiteral) SQL() string

type Type Uses

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 Uses

func (t Type) SQL() string

type TypeBase Uses

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

func (TypeBase) SQL Uses

func (tb TypeBase) SQL() string

type Update Uses

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 Uses

func (u *Update) SQL() string

func (*Update) String Uses

func (u *Update) String() string

type UpdateItem Uses

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

Package spansql imports 9 packages (graph) and is imported by 7 packages. Updated 2021-01-20. Refresh now. Tools for package owners.