Documentation ¶
Index ¶
- func IsNotExistError(err error) bool
- type AddAttr
- type AddColumn
- type AddForeignKey
- type AddIndex
- type AddTable
- type Attr
- type BinaryType
- type BoolType
- type Change
- type ChangeKind
- type Charset
- type Collation
- type Column
- type ColumnType
- type Comment
- type DecimalType
- type Differ
- type DropAttr
- type DropColumn
- type DropForeignKey
- type DropIndex
- type DropTable
- type EnumType
- type ExecQuerier
- type Execer
- type Expr
- type FloatType
- type ForeignKey
- type Index
- type IndexPart
- type InspectOptions
- type InspectRealmOption
- type InspectTableOptions
- type Inspector
- type IntegerType
- type JSONType
- type Literal
- type ModifyAttr
- type ModifyColumn
- type ModifyForeignKey
- type ModifyIndex
- type ModifyTable
- type NotExistError
- type RawExpr
- type Realm
- type RealmInspector
- type ReferenceOption
- type Schema
- type SpatialType
- type StringType
- type Table
- type TableInspector
- type TimeType
- type Type
- type UnsupportedType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNotExistError ¶
IsNotExistError reports if an error is a NotExistError.
Types ¶
type AddForeignKey ¶
type AddForeignKey struct {
F *ForeignKey
}
AddForeignKey describes a foreign-key creation change.
type Attr ¶
type Attr interface {
// contains filtered or unexported methods
}
Attr represents the interface that all attributes implement.
type BinaryType ¶
BinaryType represents a type that stores a binary data.
type Change ¶
type Change interface {
// contains filtered or unexported methods
}
A Change represents a schema change. The types below implement this interface and can be used for describing schema changes.
The Change interface can also be implemented outside this package as follows:
type RenameType struct { schema.Change From, To string } var t schema.Change = &RenameType{From: "old", To: "new"}
type ChangeKind ¶
type ChangeKind uint
A ChangeKind describes a change kind that can be combined using a set of flags. The zero kind is no change.
const ( // NoChange holds the zero value of a change kind. NoChange ChangeKind = 0 // ChangeAttr describes attributes change of an element. // For example, a table CHECK was added or changed. ChangeAttr ChangeKind = 1 << (iota - 1) // ChangeCharset describes character-set change. ChangeCharset // ChangeCollation describes collation/encoding change. ChangeCollation // ChangeComment describes comment chang (of any element). ChangeComment // ChangeNull describe a change to the NULL constraint. ChangeNull // ChangeType describe a column type change. ChangeType // ChangeDefault describe a column default change. ChangeDefault // ChangeUnique describes a change to the uniqueness constraint. // For example, an index was changed from non-unique to unique. ChangeUnique // ChangeParts describes a change to one or more of the index parts. // For example, index keeps its previous name, but the columns order // was changed. ChangeParts // ChangeColumn describes a change to the foreign-key (child) columns. ChangeColumn // ChangeRefColumn describes a change to the foreign-key (parent) columns. ChangeRefColumn // ChangeRefTable describes a change to the foreign-key (parent) table. ChangeRefTable // ChangeUpdateAction describes a change to the foreign-key update action. ChangeUpdateAction // ChangeDeleteAction describes a change to the foreign-key delete action. ChangeDeleteAction )
func (ChangeKind) Is ¶
func (k ChangeKind) Is(c ChangeKind) bool
Is reports whether c is match the given change kind.
type Charset ¶
type Charset struct {
V string
}
Charset describes a column or a table character set setting.
type Collation ¶
type Collation struct {
V string
}
Collation describes a column or a table collation setting.
type Column ¶
type Column struct { Name string Type *ColumnType Default Expr Attrs []Attr Indexes []*Index ForeignKeys []*ForeignKey }
A Column represents a column definition.
type ColumnType ¶
ColumnType represents a column type that is implemented by the dialect.
type DecimalType ¶
DecimalType represents a fixed-point type that stores exact numeric values.
type Differ ¶
type Differ interface { // SchemaDiff returns a diff report for migrating a schema // from state "from" to state "to". An error is returned // if such step is not possible. SchemaDiff(from, to *Schema) ([]Change, error) // TableDiff returns a diff report for migrating a table // from state "from" to state "to". An error is returned // if such step is not possible. TableDiff(from, to *Table) ([]Change, error) }
Differ is the interface implemented by the different drivers for comparing and diffing schema top elements.
type DropColumn ¶
type DropColumn struct {
C *Column
}
DropColumn describes a column removal change.
type DropForeignKey ¶
type DropForeignKey struct {
F *ForeignKey
}
DropForeignKey describes a foreign-key removal change.
type ExecQuerier ¶
type ExecQuerier interface { QueryRow(query string, args ...interface{}) *sql.Row QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row Query(query string, args ...interface{}) (*sql.Rows, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) }
ExecQuerier wraps the standard sql.DB methods.
type Execer ¶
type Execer interface { // Exec responsible for executing the given changeset. // An error may return from Exec if the driver does not // know how to execute a change. Exec(ctx context.Context, changes []Change) error }
Execer is the interface implemented by the different drivers for executing schema changes.
type Expr ¶
type Expr interface {
// contains filtered or unexported methods
}
Expr defines an SQL expression in schema DDL.
type ForeignKey ¶
type ForeignKey struct { Symbol string Table *Table Columns []*Column RefTable *Table RefColumns []*Column OnUpdate ReferenceOption OnDelete ReferenceOption }
A ForeignKey represents an index definition.
type IndexPart ¶
An IndexPart represents an index part that can be either an expression or a column.
type InspectOptions ¶
type InspectOptions struct { // Tables to inspect. Empty means all tables in the schema. Tables []string }
InspectOptions describes options for Inspector.
type InspectRealmOption ¶
type InspectRealmOption struct { // Schemas to inspect. Empty means all tables in the schema. Schemas []string }
InspectRealmOption describes options for RealmInspector.
type InspectTableOptions ¶
type InspectTableOptions struct { // Schema defines an optional schema to inspect. Schema string }
InspectTableOptions describes options for TableInspector.
type Inspector ¶
type Inspector interface { // InspectSchema returns the schema description by its name. A NotExistError // error is returned if the schema does not exists in the database. InspectSchema(ctx context.Context, name string, opts *InspectOptions) (*Schema, error) }
Inspector is the interface implemented by the different database drivers for inspecting multiple tables.
type IntegerType ¶
IntegerType represents an int type.
type Literal ¶
type Literal struct {
V string
}
Literal represents a basic literal expression like "1".
type ModifyAttr ¶
type ModifyAttr struct {
From, To Attr
}
ModifyAttr describes a change that modifies an element attribute.
type ModifyColumn ¶
type ModifyColumn struct {
From, To *Column
Change ChangeKind
}
ModifyColumn describes a change that modifies a column.
type ModifyForeignKey ¶
type ModifyForeignKey struct {
From, To *ForeignKey
Change ChangeKind
}
ModifyForeignKey describes a change that modifies a foreign-key.
type ModifyIndex ¶
type ModifyIndex struct {
From, To *Index
Change ChangeKind
}
ModifyIndex describes an index modification.
type ModifyTable ¶
ModifyTable describes a table modification change.
type NotExistError ¶
type NotExistError struct {
Err error
}
A NotExistError wraps another error to retain its original text but makes it possible to the migrator to catch it.
func (NotExistError) Error ¶
func (e NotExistError) Error() string
type Realm ¶
A Realm or a database describes a domain of schema resources that are logically connected and can be accessed and queried in the same connection (e.g. a physical database instance).
type RealmInspector ¶
type RealmInspector interface {
InspectRealm(ctx context.Context, opts *InspectRealmOption) (*Realm, error)
}
RealmInspector is the interface implemented by the different database drivers for inspecting multiple schemas (realm).
type ReferenceOption ¶
type ReferenceOption string
ReferenceOption for constraint actions.
const ( NoAction ReferenceOption = "NO ACTION" Restrict ReferenceOption = "RESTRICT" Cascade ReferenceOption = "CASCADE" SetNull ReferenceOption = "SET NULL" SetDefault ReferenceOption = "SET DEFAULT" )
Reference options (actions) specified by ON UPDATE and ON DELETE subclauses of the FOREIGN KEY clause.
type Schema ¶
type Schema struct { Name string Realm *Realm Tables []*Table Attrs []Attr // Attributes and options. }
A Schema describes a database schema (i.e. named database).
type SpatialType ¶
type SpatialType struct {
T string
}
SpatialType represents a spatial/geometric type.
type Table ¶
type Table struct { Name string Schema *Schema Columns []*Column Indexes []*Index PrimaryKey *Index ForeignKeys []*ForeignKey Attrs []Attr // Attributes, constraints and options. }
A Table represents a table definition.
func (*Table) ForeignKey ¶
func (t *Table) ForeignKey(symbol string) (*ForeignKey, bool)
ForeignKey returns the first foreign-key that matched the given symbol (constraint name).
type TableInspector ¶
type TableInspector interface { // InspectTable returns the table description by its name. A NotExistError // error is returned if the table does not exists in the database. InspectTable(ctx context.Context, name string, opts *InspectTableOptions) (*Table, error) }
TableInspector is the interface implemented by the different database drivers for inspecting their schema tables.
type Type ¶
type Type interface {
// contains filtered or unexported methods
}
A Type represents a database type. The types below implements this interface and can be used for describing schemas.
The Type interface can also be implemented outside this package as follows:
type SpatialType struct { schema.Type T string } var t schema.Type = &SpatialType{T: "point"}
type UnsupportedType ¶
type UnsupportedType struct {
T string
}
UnsupportedType represents a type that is not supported by the drivers.