Documentation
¶
Index ¶
- Constants
- func SQLCombine(sqls []string) string
- type Column
- type Constraint
- type Diff
- type DiffStruct
- type Differ
- type ForeignKeyConstraint
- type Index
- type PrimaryKeyConstraint
- type Schema
- func (s *Schema) DiffSchema(old *Schema) *Schema
- func (s *Schema) DropIndexConstraintSQL() []string
- func (s *Schema) IndexConstraintSQL() []string
- func (s *Schema) PrintDelta(out io.Writer)
- func (s *Schema) SQL() []string
- func (s *Schema) SQLNoIndexesConstraints() []string
- func (s *Schema) SQLSel(sel Select) []string
- func (s *Schema) Sort() *Schema
- func (s *Schema) Table(name string) *Table
- func (s *Schema) Write(sel Select, writer io.Writer) (int, error)
- func (s *Schema) WriteFile(sel Select, filename string) (int, error)
- type Select
- type Table
- func (t *Table) Column(name string) *Column
- func (t *Table) CreateColumnClauses() []string
- func (t *Table) CreateForceIndexSQL() []string
- func (t *Table) CreateIndexConstraintSQLs() []string
- func (t *Table) CreateTableSQL() string
- func (t *Table) DependsOn(other *Table) bool
- func (t *Table) DiffConstraints(old *Table) []Constraint
- func (t *Table) DiffSchema(old *Table) *Table
- func (t *Table) DropIndexConstraintSQL() []string
- func (t *Table) DropSQL() []string
- func (t *Table) Index(name string) *Index
- func (t *Table) IndexConstraintSQL() []string
- func (t *Table) PrintDelta(out io.Writer)
- func (t *Table) SQL() []string
- func (t *Table) SQLNoIndexesConstraints() []string
Constants ¶
const UnknownColumn = "§"
UnknownColumn is the character that represents a column that cannot be introspected from the database.
Variables ¶
This section is empty.
Functions ¶
func SQLCombine ¶
SQLCombine combines multiple SQL statements into one string, separating SQL statements with the ";" separator.
Types ¶
type Column ¶
type Column struct { Name string SQLType string Default string Alias string DiffStruct }
A Column represents a single column in a table
func (*Column) DiffSchema ¶
DiffSchema compares c and old and returns a diff column.
func (*Column) PrintDelta ¶
PrintDelta writes the column delta to out.
type Constraint ¶
A Constraint is a table constraint such as a unique column or foreign-key.
type DiffStruct ¶
type DiffStruct struct {
Diff Diff
}
A DiffStruct represents a diff.
func (*DiffStruct) DiffMode ¶
func (d *DiffStruct) DiffMode() Diff
DiffMode returns the current diff mode.
func (*DiffStruct) SetDiffMode ¶
func (d *DiffStruct) SetDiffMode(diff Diff)
SetDiffMode sets the diff mode to diff.
type ForeignKeyConstraint ¶
type ForeignKeyConstraint struct { ConstraintName string SourceTableField string TargetTable string TargetTableField string *DiffStruct }
A ForeignKeyConstraint links a foreign key column in a table to a (primary) key in a target table.
func (ForeignKeyConstraint) DependsOnTable ¶
func (f ForeignKeyConstraint) DependsOnTable() string
DependsOnTable gets the name of the table this constraint depends on.
func (ForeignKeyConstraint) Name ¶
func (f ForeignKeyConstraint) Name() string
Name gets the name of the foreign key constraint f
func (ForeignKeyConstraint) SQL ¶
func (f ForeignKeyConstraint) SQL() string
SQL gets the SQL clause for the constraint f.
type Index ¶
type Index struct { Name string TableName string Columns []string Unique bool Force bool // Always created, even if other indexes are omitted DiffStruct }
An Index represents a table index.
func (*Index) PrintDelta ¶
PrintDelta writes the index delta to out.
type PrimaryKeyConstraint ¶
type PrimaryKeyConstraint struct { ConstraintName string Column string *DiffStruct }
A PrimaryKeyConstraint represents the primary key constraint for a table.
func (PrimaryKeyConstraint) DependsOnTable ¶
func (c PrimaryKeyConstraint) DependsOnTable() string
DependsOnTable returns "" always (primary-key constraints can have no dependencies on other tables).
func (PrimaryKeyConstraint) Name ¶
func (c PrimaryKeyConstraint) Name() string
Name returns the constraint name for c.
func (PrimaryKeyConstraint) SQL ¶
func (c PrimaryKeyConstraint) SQL() string
SQL returns the SQL for c.
type Schema ¶
type Schema struct {
Tables []*Table
}
A Schema is a set of tables
func (*Schema) DiffSchema ¶
DiffSchema compares s to old and returns a diff schema.
func (*Schema) DropIndexConstraintSQL ¶
DropIndexConstraintSQL returns the DDL to drop indexes and constraints, usually to prepare for a bulk load.
func (*Schema) IndexConstraintSQL ¶
IndexConstraintSQL returns the DDL for table indexes and constraints.
func (*Schema) PrintDelta ¶
PrintDelta writes the schema delta to out.
func (*Schema) SQLNoIndexesConstraints ¶
SQLNoIndexesConstraints returns the schema SQL without index and constraints.
type Select ¶
type Select int
Select specifies what database DDL statements are selected.
const ( // SelTables requests only table created statements SelTables Select = iota // SelIndexesConstraints requests indexes and constraints on tables SelIndexesConstraints // SelTablesIndexesConstraints requests tables, indexes and constraints SelTablesIndexesConstraints // SelDropIndexesConstraints requests drop statements for indexes and // constraints. This is usually used to drop indexes and constraints for a // bulk data load. SelDropIndexesConstraints )
type Table ¶
type Table struct { Name string Columns []*Column Indexes []*Index Constraints []Constraint *DiffStruct // contains filtered or unexported fields }
A Table represents a single table's columns, indexes, constaints and dependencies.
func (*Table) CreateColumnClauses ¶
CreateColumnClauses returns the list of column SQL expressions.
func (*Table) CreateForceIndexSQL ¶
CreateForceIndexSQL returns SQL statements for force-created indexes. Forced indexes are necessary for fast bulk-loads (usually indexes on lookup tables), and must be returned even when if the caller requested no regular indexes.
func (*Table) CreateIndexConstraintSQLs ¶
CreateIndexConstraintSQLs returns the DDL statements to create the table's indexes and constraints.
func (*Table) CreateTableSQL ¶
CreateTableSQL returns the DDL SQL to create this table.
func (*Table) DependsOn ¶
DependsOn checks if t depends on other (viz. has a foreign key into other).
func (*Table) DiffConstraints ¶
func (t *Table) DiffConstraints(old *Table) []Constraint
DiffConstraints compares the constraints on t and old and returns the list of constraint diffs.
func (*Table) DiffSchema ¶
DiffSchema compares t to old and returns a diff table.
func (*Table) DropIndexConstraintSQL ¶
DropIndexConstraintSQL returns the DDL to drop this table's indexes and constraints.
func (*Table) IndexConstraintSQL ¶
IndexConstraintSQL returns SQL statements to create indexes and constraints
func (*Table) PrintDelta ¶
PrintDelta writes the table delta to out.
func (*Table) SQLNoIndexesConstraints ¶
SQLNoIndexesConstraints returns the table's DDL SQL, ignoring indexes and constraints.