postgres

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       = "postgres" //diff:ignore-line-postgres-cockroach
	DriverName    = "postgres" //diff:ignore-line-postgres-cockroach
	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 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 AlterColumnDropNotNull

type AlterColumnDropNotNull struct {
	Name *Ident
}

AlterColumnDropNotNull represents ALTER TABLE table_name ALTER COLUMN column_name DROP NOT NULL.

func (*AlterColumnDropNotNull) GoString

func (s *AlterColumnDropNotNull) GoString() string

type AlterColumnSetDataType

type AlterColumnSetDataType struct {
	Name     *Ident
	DataType *DataType
}

AlterColumnSetDataType represents ALTER TABLE table_name ALTER COLUMN column_name SET DATA TYPE.

func (*AlterColumnSetDataType) GoString

func (s *AlterColumnSetDataType) 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 AlterColumnSetNotNull

type AlterColumnSetNotNull struct {
	Name *Ident
}

AlterColumnSetNotNull represents ALTER TABLE table_name ALTER COLUMN column_name SET NOT NULL.

func (*AlterColumnSetNotNull) GoString

func (s *AlterColumnSetNotNull) 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
}

func (*Column) GoString

func (c *Column) GoString() string

func (*Column) String

func (c *Column) String() string

type ColumnIdent

type ColumnIdent struct {
	Ident *Ident
}

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        *Ident
	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     []*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     *Ident
}

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

func (d *Expr) String() string

type ForeignKeyConstraint

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

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 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 *Ident
}

func (*Option) GoString

func (o *Option) GoString() string

func (*Option) String

func (o *Option) String() string

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 PrimaryKeyConstraint

type PrimaryKeyConstraint struct {
	Name    *Ident
	Columns []*ColumnIdent
}

PrimaryKeyConstraint represents a PRIMARY KEY constraint.

func (*PrimaryKeyConstraint) GetName

func (c *PrimaryKeyConstraint) GetName() *Ident

func (*PrimaryKeyConstraint) GoString

func (c *PrimaryKeyConstraint) GoString() string

func (*PrimaryKeyConstraint) String

func (c *PrimaryKeyConstraint) String() string

func (*PrimaryKeyConstraint) StringForDiff

func (c *PrimaryKeyConstraint) StringForDiff() string

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 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"      // ::

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

	// DATA TYPE.
	TOKEN_BOOLEAN                  TokenType = "BOOLEAN"  //diff:ignore-line-postgres-cockroach
	TOKEN_SMALLINT                 TokenType = "SMALLINT" //diff:ignore-line-postgres-cockroach
	TOKEN_INTEGER                  TokenType = "INTEGER"  //diff:ignore-line-postgres-cockroach
	TOKEN_BIGINT                   TokenType = "BIGINT"   //diff:ignore-line-postgres-cockroach
	TOKEN_DECIMAL                  TokenType = "DECIMAL"
	TOKEN_NUMERIC                  TokenType = "NUMERIC"
	TOKEN_REAL                     TokenType = "REAL"
	TOKEN_DOUBLE                   TokenType = "DOUBLE"
	TOKEN_PRECISION                TokenType = "PRECISION"
	TOKEN_DOUBLE_PRECISION         TokenType = "DOUBLE PRECISION"
	TOKEN_SMALLSERIAL              TokenType = "SMALLSERIAL"
	TOKEN_SERIAL                   TokenType = "SERIAL"
	TOKEN_BIGSERIAL                TokenType = "BIGSERIAL"
	TOKEN_UUID                     TokenType = "UUID"
	TOKEN_JSONB                    TokenType = "JSONB"
	TOKEN_CHARACTER_VARYING        TokenType = "CHARACTER VARYING"
	TOKEN_CHARACTER                TokenType = "CHARACTER"
	TOKEN_VARYING                  TokenType = "VARYING"
	TOKEN_TEXT                     TokenType = "TEXT" //diff:ignore-line-postgres-cockroach
	TOKEN_TIMESTAMPTZ              TokenType = "TIMESTAMPTZ"
	TOKEN_TIMESTAMP_WITH_TIME_ZONE TokenType = "TIMESTAMP WITH TIME ZONE" //diff:ignore-line-postgres-cockroach
	TOKEN_TIMESTAMP                TokenType = "TIMESTAMP"
	TOKEN_WITH                     TokenType = "WITH"
	TOKEN_TIME                     TokenType = "TIME"
	TOKEN_ZONE                     TokenType = "ZONE"

	// COLUMN.
	TOKEN_DEFAULT TokenType = "DEFAULT"
	TOKEN_NOT     TokenType = "NOT"
	TOKEN_ASC     TokenType = "ASC"
	TOKEN_DESC    TokenType = "DESC"
	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"

	// IDENTIFIER.
	TOKEN_IDENT TokenType = "IDENT"
)

func (TokenType) String

func (t TokenType) String() string

type UniqueConstraint

type UniqueConstraint struct {
	Name    *Ident
	Columns []*ColumnIdent
}

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

func (*UniqueConstraint) GetName

func (c *UniqueConstraint) GetName() *Ident

func (*UniqueConstraint) GoString

func (c *UniqueConstraint) GoString() string

func (*UniqueConstraint) String

func (c *UniqueConstraint) String() string

func (*UniqueConstraint) StringForDiff

func (c *UniqueConstraint) StringForDiff() 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