Documentation ¶
Index ¶
- Constants
- Variables
- func Funcs() map[string]interface{}
- type Column
- type Constraint
- type Index
- type PatchColumn
- type PatchConstraint
- type PatchIndex
- type PatchRelation
- type PatchSchema
- type PatchTable
- type PlantUML
- type Relation
- type Schema
- func (s *Schema) FindRelation(tblName string, cs, pcs []*Column) (*Relation, error)
- func (s *Schema) FindTableByName(name string) (*Table, error)
- func (s *Schema) LoadYaml(r io.Reader) error
- func (s *Schema) MarshalYAML() ([]byte, error)
- func (s *Schema) NormalizeTableName(name string) string
- func (s *Schema) NormalizeTableNames(names []string) []string
- func (s *Schema) Repair() error
- func (s *Schema) SavePlantUml(wr io.Writer, distance int) error
- func (s *Schema) SaveYaml(wr io.Writer) error
- func (s *Schema) Sort()
- func (s *Schema) UnmarshalYAML(data []byte) error
- func (s *Schema) Validate() error
- type Table
- func (t *Table) CollectTablesAndRelations(distance int, root bool) ([]*Table, []*Relation, error)
- func (t *Table) FindColumnByName(name string) (*Column, error)
- func (t *Table) FindConstrainsByColumnName(name string) []*Constraint
- func (t *Table) FindConstraintByName(name string) (*Constraint, error)
- func (t *Table) FindIndexByName(name string) (*Index, error)
- func (t *Table) Validate() error
- type YamlColumn
- type YamlConstraint
- type YamlIndex
- type YamlRelation
- type YamlSchema
- type YamlTable
Constants ¶
View Source
const ( TypeFK = "FOREIGN KEY" TypePK = "PRIMARY KEY" TypeUQ = "UNIQUE" )
Variables ¶
View Source
var PatchDropDisable bool = false
Functions ¶
Types ¶
type Column ¶
type Column struct { Name string `json:"name"` Type string `json:"type"` Nullable bool `json:"nullable"` PrimaryKey bool `json:"pk"` Default sql.NullString `json:"default"` Comment string `json:"comment"` ParentRelations []*Relation `json:"-"` ChildRelations []*Relation `json:"-"` }
Column is the struct for table column
type Constraint ¶
type Constraint struct { Name string `json:"name"` Type string `json:"type"` Def string `json:"def"` Check string `json:"check"` OnDelete string `json:"onDelete"` Table *string `json:"table"` ReferenceTable *string `json:"reference_table" yaml:"referenceTable"` Columns []string `json:"columns"` ReferenceColumns []string `json:"reference_columns" yaml:"referenceColumns"` Comment string `json:"comment"` }
Constraint is the struct for database constraint
func (*Constraint) Validate ¶ added in v1.1.0
func (c *Constraint) Validate() error
type Index ¶
type Index struct { Name string `json:"name"` IsPrimary bool IsUnique bool IsClustered bool MethodName string Def string `json:"def"` Table *string `json:"table"` Columns []string `json:"columns"` Concurrently bool `json:"concurrently,omitempty"` ColDef string `json:"coldef,omitempty"` With string `json:"with,omitempty"` Tablespace string `json:"tablespace,omitempty"` Where string `json:"where,omitempty"` Comment string `json:"comment"` }
Index is the struct for database index
type PatchColumn ¶
type PatchColumn struct {
// contains filtered or unexported fields
}
func (*PatchColumn) GenerateSQL ¶
func (c *PatchColumn) GenerateSQL() []string
type PatchConstraint ¶
type PatchConstraint struct {
// contains filtered or unexported fields
}
func (*PatchConstraint) GenerateSQL ¶
func (c *PatchConstraint) GenerateSQL() []string
type PatchIndex ¶
type PatchIndex struct {
// contains filtered or unexported fields
}
func (*PatchIndex) GenerateSQL ¶
func (i *PatchIndex) GenerateSQL() []string
type PatchRelation ¶
type PatchRelation struct {
// contains filtered or unexported fields
}
func (*PatchRelation) GenerateSQL ¶
func (r *PatchRelation) GenerateSQL() []string
type PatchSchema ¶
type PatchSchema struct { CurrentSchema string // contains filtered or unexported fields }
func (*PatchSchema) Build ¶
func (s *PatchSchema) Build(from, to *Schema) error
func (*PatchSchema) GenerateSQL ¶
func (t *PatchSchema) GenerateSQL() (ret []string)
type PatchTable ¶
type PatchTable struct {
// contains filtered or unexported fields
}
func (*PatchTable) GenerateSQL ¶
func (t *PatchTable) GenerateSQL() []string
type Relation ¶
type Relation struct { Name string `json:"name"` Table *Table `json:"table"` Columns []*Column `json:"columns"` ParentTable *Table `json:"parent_table" yaml:"parentTable"` ParentColumns []*Column `json:"parent_columns" yaml:"parentColumns"` OnDelete string `json:"onDelete"` Def string `json:"def"` }
Relation is the struct for table relation
type Schema ¶
type Schema struct { Name string `json:"name"` Desc string `json:"desc"` Tables []*Table `json:"tables"` Relations []*Relation `json:"relations"` CurrentSchema string `json:"currentSchema"` SearchPaths []string `json:"searchPaths,omitempty"` }
Schema is the struct for database schema
func (*Schema) FindRelation ¶
FindRelation ...
func (*Schema) FindTableByName ¶
FindTableByName find table by table name
func (*Schema) MarshalYAML ¶
func (*Schema) NormalizeTableName ¶
func (*Schema) NormalizeTableNames ¶
func (*Schema) Sort ¶
func (s *Schema) Sort()
Sort schema tables, columns, relations, and constrains
func (*Schema) UnmarshalYAML ¶
type Table ¶
type Table struct { Name string `json:"name"` Type string `json:"type"` Comment string `json:"comment"` Columns []*Column `json:"columns"` Indexes []*Index `json:"indexes"` Constraints []*Constraint `json:"constraints"` Def string `json:"def"` }
Table is the struct for database table
func (*Table) CollectTablesAndRelations ¶
func (*Table) FindColumnByName ¶
FindColumnByName find column by column name
func (*Table) FindConstrainsByColumnName ¶
func (t *Table) FindConstrainsByColumnName(name string) []*Constraint
FindConstrainsByColumnName find constraint by column name
func (*Table) FindConstraintByName ¶
func (t *Table) FindConstraintByName(name string) (*Constraint, error)
FindConstraintByName find constraint by constraint name
func (*Table) FindIndexByName ¶
FindIndexByName find index by index name
type YamlColumn ¶
type YamlConstraint ¶
type YamlConstraint struct { Type string `yaml:"type,omitempty"` Check string `json:"check,omitempty"` OnDelete string `json:"onDelete,omitempty"` ReferenceTable string `yaml:"referenceTable,omitempty"` Columns []string `yaml:"columns,flow"` ReferenceColumns []string `yaml:"referenceColumns,flow,omitempty"` }
type YamlIndex ¶
type YamlIndex struct { IsPrimary bool `yaml:"isPrimary,omitempty"` IsUnique bool `yaml:"isUnique,omitempty"` IsClustered bool `yaml:"isClustered,omitempty"` Concurrently bool `yaml:"concurrently,omitempty"` MethodName string `yaml:"method,omitempty"` Columns []string `yaml:"columns,flow"` ColDef string `yaml:"coldef,omitempty"` With string `yaml:"with,omitempty"` Tablespace string `yaml:"tablespace,omitempty"` Where string `yaml:"where,omitempty"` }
type YamlRelation ¶
type YamlSchema ¶
type YamlTable ¶
type YamlTable struct { Type string `yaml:"type,omitempty"` Columns map[string]*YamlColumn `yaml:"columns"` Indexes map[string]*YamlIndex `yaml:"indexes,omitempty"` Constraints map[string]*YamlConstraint `yaml:"constraints,omitempty"` Relations map[string]*YamlRelation `yaml:"relations,omitempty"` // key = parent table Def string `yaml:"def,omitempty"` }
Click to show internal directories.
Click to hide internal directories.