spanner

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Dialect       = "spanner"
	DriverName    = "spanner"
	Indent        = "    "
	CommentPrefix = "-- "
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string
const (
	ActionAdd    Action = "ADD"
	ActionDrop   Action = "DROP"
	ActionAlter  Action = "ALTER"
	ActionRename Action = "RENAME"
)

type AddColumn

type AddColumn struct {
	Column *Column
}

AddColumn represents ALTER TABLE table_name ADD COLUMN.

func (*AddColumn) GoString

func (s *AddColumn) GoString() string

type AddConstraint

type AddConstraint struct {
	Constraint Constraint
	NotValid   bool
}

AddConstraint represents ALTER TABLE table_name ADD CONSTRAINT.

func (*AddConstraint) GoString

func (s *AddConstraint) GoString() string

type AddRowDeletionPolicy added in v0.0.16

type AddRowDeletionPolicy struct {
	RowDeletionPolicy *Option
}

AddRowDeletionPolicy represents ALTER TABLE table_name ADD ROW DELETION POLICY.

func (*AddRowDeletionPolicy) GoString added in v0.0.16

func (s *AddRowDeletionPolicy) GoString() string

type AlterColumnDataType

type AlterColumnDataType struct {
	Name     *Ident
	DataType *DataType
	NotNull  bool
}

AlterColumnDataType represents ALTER TABLE table_name ALTER COLUMN column_name data_type NOT NULL.

func (*AlterColumnDataType) GoString

func (s *AlterColumnDataType) GoString() string

type AlterColumnDropDefault

type AlterColumnDropDefault struct {
	Name *Ident
}

AlterColumnDropDefault represents ALTER TABLE table_name ALTER COLUMN column_name DROP DEFAULT.

func (*AlterColumnDropDefault) GoString

func (s *AlterColumnDropDefault) GoString() string

type AlterColumnDropOptions

type AlterColumnDropOptions struct {
	Name *Ident
}

AlterColumnDropOptions represents ALTER TABLE table_name ALTER COLUMN column_name DROP OPTIONS.

func (*AlterColumnDropOptions) GoString

func (s *AlterColumnDropOptions) GoString() string

type AlterColumnSetDefault

type AlterColumnSetDefault struct {
	Name    *Ident
	Default *Default
}

AlterColumnSetDefault represents ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT.

func (*AlterColumnSetDefault) GoString

func (s *AlterColumnSetDefault) GoString() string

type AlterColumnSetOptions

type AlterColumnSetOptions struct {
	Name    *Ident
	Options *Expr
}

AlterColumnSetOptions represents ALTER TABLE table_name ALTER COLUMN column_name SET OPTIONS.

func (*AlterColumnSetOptions) GoString

func (s *AlterColumnSetOptions) GoString() string

type AlterConstraint

type AlterConstraint struct {
	Name              *Ident
	Deferrable        bool
	InitiallyDeferred bool
}

AlterConstraint represents ALTER TABLE table_name ALTER CONSTRAINT.

func (*AlterConstraint) GoString

func (s *AlterConstraint) GoString() string

type AlterTableAction

type AlterTableAction interface {
	GoString() string
	// contains filtered or unexported methods
}

type AlterTableStmt

type AlterTableStmt struct {
	Comment string
	Indent  string
	Name    *ObjectName
	Action  AlterTableAction
}

func (*AlterTableStmt) GetNameForDiff

func (s *AlterTableStmt) GetNameForDiff() string

func (*AlterTableStmt) GoString

func (s *AlterTableStmt) GoString() string

func (*AlterTableStmt) String

func (s *AlterTableStmt) String() string

type CheckConstraint

type CheckConstraint struct {
	Name *Ident
	Expr *Expr
}

CheckConstraint represents a CHECK constraint.

func (*CheckConstraint) GetName

func (c *CheckConstraint) GetName() *Ident

func (*CheckConstraint) GoString

func (c *CheckConstraint) GoString() string

func (*CheckConstraint) String

func (c *CheckConstraint) String() string

func (*CheckConstraint) StringForDiff

func (c *CheckConstraint) StringForDiff() string

type Column

type Column struct {
	Name     *Ident
	DataType *DataType
	Default  *Default
	NotNull  bool
	Options  *Expr
}

func (*Column) GoString

func (c *Column) GoString() string

func (*Column) String

func (c *Column) String() string

type ColumnIdent

type ColumnIdent struct {
	Ident *Ident
	Order *Order //diff:ignore-line-postgres-cockroach
}

func (*ColumnIdent) GoString

func (i *ColumnIdent) GoString() string

func (*ColumnIdent) String

func (i *ColumnIdent) String() string

func (*ColumnIdent) StringForDiff

func (i *ColumnIdent) StringForDiff() string

type Constraint

type Constraint interface {
	GetName() *Ident
	GoString() string
	String() string
	StringForDiff() string
	// contains filtered or unexported methods
}

type Constraints

type Constraints []Constraint

func (Constraints) Append

func (constraints Constraints) Append(constraint Constraint) Constraints

type CreateIndexStmt

type CreateIndexStmt struct {
	Comment     string
	Unique      bool
	IfNotExists bool
	Name        *ObjectName
	TableName   *ObjectName
	Using       []*Ident
	Columns     []*ColumnIdent
}

func (*CreateIndexStmt) GetNameForDiff

func (s *CreateIndexStmt) GetNameForDiff() string

func (*CreateIndexStmt) GoString

func (s *CreateIndexStmt) GoString() string

func (*CreateIndexStmt) String

func (s *CreateIndexStmt) String() string

func (*CreateIndexStmt) StringForDiff

func (s *CreateIndexStmt) StringForDiff() string

type CreateTableStmt

type CreateTableStmt struct {
	Comment           string
	Indent            string
	IfNotExists       bool
	Name              *ObjectName
	Columns           []*Column
	Constraints       Constraints
	Options           Options
	RowDeletionPolicy *Option
}

func (*CreateTableStmt) GetNameForDiff

func (s *CreateTableStmt) GetNameForDiff() string

func (*CreateTableStmt) GoString

func (s *CreateTableStmt) GoString() string

func (*CreateTableStmt) String

func (s *CreateTableStmt) String() string

type DDL

type DDL struct {
	Stmts []Stmt
}

func Diff

func Diff(before, after *DDL) (*DDL, error)

func DiffCreateTable

func DiffCreateTable(before, after *CreateTableStmt, opts ...DiffCreateTableOption) (*DDL, error)

func (*DDL) String

func (d *DDL) String() string

type DataType

type DataType struct {
	Name string
	Type TokenType
	Expr *Expr
}

func (*DataType) String

func (s *DataType) String() string

func (*DataType) StringForDiff

func (s *DataType) StringForDiff() string

type Default

type Default struct {
	Value *Expr
}

func (*Default) GoString

func (d *Default) GoString() string

func (*Default) String

func (d *Default) String() string

func (*Default) StringForDiff

func (d *Default) StringForDiff() string

type DiffCreateTableConfig

type DiffCreateTableConfig struct {
	UseAlterTableAddConstraintNotValid bool
}

type DiffCreateTableOption

type DiffCreateTableOption interface {
	// contains filtered or unexported methods
}

func DiffCreateTableUseAlterTableAddConstraintNotValid

func DiffCreateTableUseAlterTableAddConstraintNotValid(notValid bool) DiffCreateTableOption

type DropColumn

type DropColumn struct {
	Name *Ident
}

DropColumn represents ALTER TABLE table_name DROP COLUMN.

func (*DropColumn) GoString

func (s *DropColumn) GoString() string

type DropConstraint

type DropConstraint struct {
	Name *Ident
}

DropConstraint represents ALTER TABLE table_name DROP CONSTRAINT.

func (*DropConstraint) GoString

func (s *DropConstraint) GoString() string

type DropIndexStmt

type DropIndexStmt struct {
	Comment  string
	IfExists bool
	Name     *ObjectName
}

func (*DropIndexStmt) GetNameForDiff

func (s *DropIndexStmt) GetNameForDiff() string

func (*DropIndexStmt) GoString

func (s *DropIndexStmt) GoString() string

func (*DropIndexStmt) String

func (s *DropIndexStmt) String() string

type DropRowDeletionPolicy added in v0.0.16

type DropRowDeletionPolicy struct{}

DropRowDeletionPolicy represents ALTER TABLE table_name DROP ROW DELETION POLICY.

func (*DropRowDeletionPolicy) GoString added in v0.0.16

func (s *DropRowDeletionPolicy) GoString() string

type DropTableStmt

type DropTableStmt struct {
	Comment  string
	IfExists bool
	Name     *ObjectName
}

func (*DropTableStmt) GetNameForDiff

func (s *DropTableStmt) GetNameForDiff() string

func (*DropTableStmt) GoString

func (s *DropTableStmt) GoString() string

func (*DropTableStmt) String

func (s *DropTableStmt) String() string

type Expr

type Expr struct {
	Idents []*Ident
}

func (*Expr) Append

func (d *Expr) Append(idents ...*Ident) *Expr

func (*Expr) GoString

func (d *Expr) GoString() string

func (*Expr) String

func (d *Expr) String() string

func (*Expr) StringForDiff

func (d *Expr) StringForDiff() string

type ForeignKeyConstraint

type ForeignKeyConstraint struct {
	Name       *Ident
	Columns    []*ColumnIdent
	Ref        *Ident
	RefColumns []*ColumnIdent
}

ForeignKeyConstraint represents a FOREIGN KEY constraint.

func (*ForeignKeyConstraint) GetName

func (c *ForeignKeyConstraint) GetName() *Ident

func (*ForeignKeyConstraint) GoString

func (c *ForeignKeyConstraint) GoString() string

func (*ForeignKeyConstraint) String

func (c *ForeignKeyConstraint) String() string

func (*ForeignKeyConstraint) StringForDiff

func (c *ForeignKeyConstraint) StringForDiff() string

type Ident

type Ident struct {
	Name          string
	QuotationMark string
	Raw           string
}

func NewIdent

func NewIdent(name, quotationMark, raw string) *Ident

func NewRawIdent

func NewRawIdent(raw string) *Ident

func (*Ident) GoString

func (i *Ident) GoString() string

func (*Ident) String

func (i *Ident) String() string

func (*Ident) StringForDiff

func (i *Ident) StringForDiff() string

type IndexConstraint

type IndexConstraint struct {
	Name    *Ident
	Unique  bool //diff:ignore-line-postgres-cockroach
	Columns []*ColumnIdent
}

IndexConstraint represents a UNIQUE constraint. //diff:ignore-line-postgres-cockroach.

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer はSQL文をトークンに分割するレキサーです。

func NewLexer

func NewLexer(input string) *Lexer

NewLexer は新しいLexerを生成します。

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

NextToken は次のトークンを返します。

type Literal

type Literal struct {
	Str string
}

func (*Literal) String

func (l *Literal) String() string

func (*Literal) StringForDiff

func (l *Literal) StringForDiff() string

type Object

type Object string
const (
	ObjectTable Object = "TABLE"
	ObjectIndex Object = "INDEX"
	ObjectView  Object = "VIEW"
)

type ObjectName

type ObjectName struct {
	Schema *Ident
	Name   *Ident
}

func NewObjectName

func NewObjectName(name string) *ObjectName

func (*ObjectName) String

func (t *ObjectName) String() string

func (*ObjectName) StringForDiff

func (t *ObjectName) StringForDiff() string

type Option

type Option struct {
	Name  string
	Value *Expr
}

func (*Option) GoString

func (o *Option) GoString() string

func (*Option) String

func (o *Option) String() string

func (*Option) StringForDiff

func (o *Option) StringForDiff() string

type Options

type Options []*Option

func (Options) String

func (o Options) String() string

func (Options) StringForDiff

func (o Options) StringForDiff() string

type Order

type Order struct{ Desc bool } //diff:ignore-line-postgres-cockroach

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser はSQL文を解析するパーサーです。

func NewParser

func NewParser(l *Lexer) *Parser

NewParser は新しいParserを生成します。

func (*Parser) Parse

func (p *Parser) Parse() (*DDL, error)

Parse はSQL文を解析します。

type RenameColumn

type RenameColumn struct {
	Name    *Ident
	NewName *Ident
}

RenameColumn represents ALTER TABLE table_name RENAME COLUMN.

func (*RenameColumn) GoString

func (s *RenameColumn) GoString() string

type RenameConstraint

type RenameConstraint struct {
	Name    *Ident
	NewName *Ident
}

RenameConstraint represents ALTER TABLE table_name RENAME COLUMN.

func (*RenameConstraint) GoString

func (s *RenameConstraint) GoString() string

type RenameTable

type RenameTable struct {
	NewName *ObjectName
}

RenameTable represents ALTER TABLE table_name RENAME TO new_table_name.

func (*RenameTable) GoString

func (s *RenameTable) GoString() string

type ReplaceRowDeletionPolicy added in v0.0.16

type ReplaceRowDeletionPolicy struct {
	RowDeletionPolicy *Option
}

ReplaceRowDeletionPolicy represents ALTER TABLE table_name REPLACE ROW DELETION POLICY.

func (*ReplaceRowDeletionPolicy) GoString added in v0.0.16

func (s *ReplaceRowDeletionPolicy) GoString() string

type Stmt

type Stmt interface {
	GetNameForDiff() string
	String() string
	// contains filtered or unexported methods
}

type Token

type Token struct {
	Type    TokenType
	Literal Literal
}

Token はSQL文のトークンを表す型です。

type TokenType

type TokenType string
const (
	// SPECIAL TOKENS.
	TOKEN_ILLEGAL TokenType = "ILLEGAL"
	TOKEN_EOF     TokenType = "EOF"

	// SPECIAL CHARACTERS.
	TOKEN_OPEN_PAREN      TokenType = "OPEN_PAREN"      // (
	TOKEN_CLOSE_PAREN     TokenType = "CLOSE_PAREN"     // )
	TOKEN_COMMA           TokenType = "COMMA"           // ,
	TOKEN_SEMICOLON       TokenType = "SEMICOLON"       // ;
	TOKEN_EQUAL           TokenType = "EQUAL"           // =
	TOKEN_GREATER         TokenType = "GREATER"         // >
	TOKEN_LESS            TokenType = "LESS"            // <
	TOKEN_PLUS            TokenType = "PLUS"            // +
	TOKEN_MINUS           TokenType = "MINUS"           // -
	TOKEN_ASTERISK        TokenType = "ASTERISK"        // *
	TOKEN_SLASH           TokenType = "SLASH"           // /
	TOKEN_STRING_CONCAT   TokenType = "STRING_CONCAT"   //nolint:gosec // ||
	TOKEN_TYPECAST        TokenType = "TYPECAST"        // ::
	TOKEN_TYPE_ANNOTATION TokenType = "TYPE_ANNOTATION" // ::: //diff:ignore-line-postgres-cockroach

	// VERB.
	TOKEN_CREATE   TokenType = "CREATE"
	TOKEN_ALTER    TokenType = "ALTER"
	TOKEN_DROP     TokenType = "DROP"
	TOKEN_RENAME   TokenType = "RENAME"
	TOKEN_TRUNCATE TokenType = "TRUNCATE"
	TOKEN_DELETE   TokenType = "DELETE"
	TOKEN_UPDATE   TokenType = "UPDATE"

	// OBJECT.
	TOKEN_TABLE TokenType = "TABLE"
	TOKEN_INDEX TokenType = "INDEX"
	TOKEN_VIEW  TokenType = "VIEW"

	// OTHER.
	TOKEN_IF     TokenType = "IF"
	TOKEN_EXISTS TokenType = "EXISTS"
	TOKEN_USING  TokenType = "USING"
	TOKEN_ON     TokenType = "ON"
	TOKEN_TO     TokenType = "TO"
	TOKEN_WITH   TokenType = "WITH"

	// DATA TYPE.
	TOKEN_BOOL      TokenType = "BOOL"  //diff:ignore-line-postgres-cockroach
	TOKEN_INT64     TokenType = "INT64" //diff:ignore-line-postgres-cockroach
	TOKEN_FLOAT64   TokenType = "FLOAT64"
	TOKEN_NUMERIC   TokenType = "NUMERIC"
	TOKEN_JSON      TokenType = "JSON"
	TOKEN_STRING    TokenType = "STRING" //diff:ignore-line-postgres-cockroach
	TOKEN_BYTES     TokenType = "BYTES"
	TOKEN_TIMESTAMP TokenType = "TIMESTAMP"
	TOKEN_DATE      TokenType = "DATE"
	TOKEN_ARRAY     TokenType = "ARRAY"
	TOKEN_STRUCT    TokenType = "STRUCT"

	// COLUMN.
	TOKEN_DEFAULT    TokenType = "DEFAULT"
	TOKEN_NOT        TokenType = "NOT"
	TOKEN_ASC        TokenType = "ASC"
	TOKEN_DESC       TokenType = "DESC"
	TOKEN_OPTIONS    TokenType = "OPTIONS"
	TOKEN_INTERLEAVE TokenType = "INTERLEAVE"
	TOKEN_IN         TokenType = "IN"
	TOKEN_PARENT     TokenType = "PARENT"
	TOKEN_CASCADE    TokenType = "CASCADE"
	TOKEN_NO         TokenType = "NO"
	TOKEN_ACTION     TokenType = "ACTION"

	// CONSTRAINT.
	TOKEN_CONSTRAINT TokenType = "CONSTRAINT"
	TOKEN_PRIMARY    TokenType = "PRIMARY"
	TOKEN_KEY        TokenType = "KEY"
	TOKEN_FOREIGN    TokenType = "FOREIGN"
	TOKEN_REFERENCES TokenType = "REFERENCES"
	TOKEN_UNIQUE     TokenType = "UNIQUE"
	TOKEN_CHECK      TokenType = "CHECK"

	// FUNCTION.
	TOKEN_NULLIF TokenType = "NULLIF"

	// VALUE.
	TOKEN_NULL  TokenType = "NULL"
	TOKEN_TRUE  TokenType = "TRUE"
	TOKEN_FALSE TokenType = "FALSE"

	// OPTION
	TOKEN_ROW        TokenType = "ROW"
	TOKEN_DELETION   TokenType = "DELETION"
	TOKEN_POLICY     TokenType = "POLICY"
	TOKEN_OLDER_THAN TokenType = "OLDER_THAN"
	TOKEN_INTERVAL   TokenType = "INTERVAL"
	TOKEN_DAY        TokenType = "DAY"

	// IDENTIFIER.
	TOKEN_IDENT TokenType = "IDENT"
)

func (TokenType) String

func (t TokenType) String() string

type Verb

type Verb string
const (
	VerbCreate   Verb = "CREATE"
	VerbAlter    Verb = "ALTER"
	VerbDrop     Verb = "DROP"
	VerbRename   Verb = "RENAME"
	VerbTruncate Verb = "TRUNCATE"
)

Jump to

Keyboard shortcuts

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