Documentation ¶
Index ¶
- Constants
- func InitLogger() (*zap.SugaredLogger, error)
- func ParseReferencedTables(src string) []string
- type Column
- type Constraint
- type DB
- func (db *DB) CheckSchema() error
- func (db *DB) CheckVersion() error
- func (db *DB) Close() error
- func (db *DB) Columns(tableName string) ([]*Column, error)
- func (db *DB) Constraints(tableName string) ([]*Constraint, error)
- func (db *DB) FindTableDDL(tableName string, tableType TableType) (string, error)
- func (db *DB) Indexes(tableName string) ([]*Index, error)
- func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryRowx(query string, args ...interface{}) (*sqlx.Row, error)
- func (db *DB) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
- func (db *DB) ReferencedTables(tb *Table) error
- func (db *DB) Relation(tb *Table, c *Constraint) (*Relation, error)
- func (db *DB) Table(name string) (*Table, error)
- func (db *DB) TableRelations(tb *Table) ([]*Relation, error)
- func (db *DB) Tables(pattern string) ([]*TableInfo, error)
- func (db *DB) Triggers(tableName string) ([]*Trigger, error)
- type Datasource
- type Index
- type Relation
- type Schema
- 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) FindTriggerByName(name string) (*Trigger, error)
- func (t *Table) HasColumnWithExtraDef() bool
- type TableInfo
- type TableType
- type Trigger
Constants ¶
const ( MinMysqlVersion = "5.7.6" DriverName = "mysql" )
const CurrentDB = "tidb_5_2"
const TypeFK = "FOREIGN KEY"
Variables ¶
This section is empty.
Functions ¶
func InitLogger ¶
func InitLogger() (*zap.SugaredLogger, error)
func ParseReferencedTables ¶
ParseReferencedTables parse DDL of view table and list tables referenced by view table.
Types ¶
type Column ¶
type Column struct { Name string `json:"name"` Type string `json:"type"` Nullable bool `json:"nullable"` Default *string `json:"default"` Comment *string `json:"comment"` ExtraDef *string `json:"extra_def,omitempty" yaml:"extraDef,omitempty"` 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"` Table *string `json:"table"` ReferencedTable *string `json:"referenced_table" yaml:"referencedTable"` Columns []string `json:"columns"` ReferencedColumns []string `json:"referenced_columns" yaml:"referencedColumns"` Comment string `json:"comment"` }
Constraint is the struct for database constraint
type DB ¶
type DB struct { // Name for database driver, such as mysql Name string `json:"name"` Version string `json:"version"` URL string `json:"url"` Schema *Schema `json:"schema"` // contains filtered or unexported fields }
DB stands for a connection to database, including current schema The returned DB is safe for concurrent use by multiple goroutines and maintains its own pool of idle connections. Thus, the Open function should be called just once. It is rarely necessary to close a DB.
func Open ¶
func Open(ds *Datasource) (*DB, error)
Open takes a dataSourceName like "root:mypass@tcp(127.0.0.1:33308)/testdb?parseTime=true"
func (*DB) CheckVersion ¶
CheckVersion set version and supportGeneratedColumn
func (*DB) Constraints ¶
func (db *DB) Constraints(tableName string) ([]*Constraint, error)
func (*DB) FindTableDDL ¶
func (*DB) ReferencedTables ¶
ReferencedTables get referenced tables for view
func (*DB) Relation ¶
func (db *DB) Relation(tb *Table, c *Constraint) (*Relation, error)
Relation get one relation from one constraint
func (*DB) TableRelations ¶
TableRelations get table's relations from its constraints
type Datasource ¶
type Datasource struct { UserName string Passwd string Host string Port int DBName string Comment string }
func PredefinedDatasource ¶
func PredefinedDatasource(comment string) (*Datasource, error)
func (*Datasource) ConnectString ¶
func (ds *Datasource) ConnectString() string
ConnectString returns a connection string based on the parameters it's given This would normally also contain the password, however we're not using one
type Index ¶
type Index struct { Name string `json:"name"` Def string `json:"def"` Table *string `json:"table"` Columns []string `json:"columns"` Comment string `json:"comment"` }
Index is the struct for database index
type Relation ¶
type Relation struct { Table *Table `json:"table"` Columns []*Column `json:"columns"` ParentTable *Table `json:"parent_table" yaml:"parentTable"` ParentColumns []*Column `json:"parent_columns" yaml:"parentColumns"` Def string `json:"def"` Virtual bool `json:"virtual"` }
Relation is the struct for table relation
type Schema ¶
type Schema struct {
Name string `json:"name"`
}
Schema is a named collection of tables. A schema can also contain views, indexes, sequences, data types, operators, and functions. Schemas are analogous to directories at the operating system level, except schemas cannot be nested. For mysql, schema is equal to database. For postgres, a database could have multi schemas.
type Table ¶
type Table struct { TableInfo Columns []*Column `json:"columns"` Indexes []*Index `json:"indexes"` Constraints []*Constraint `json:"constraints"` Triggers []*Trigger `json:"triggers"` // only used for view ReferencedTables []*Table `json:"referenced_tables,omitempty" yaml:"referencedTables,omitempty"` }
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
func (*Table) FindTriggerByName ¶
FindTriggerByName find trigger by trigger name