Documentation ¶
Index ¶
- Variables
- type Client
- func (c *Client) AllTableNames(schema string) ([]*Table, error)
- func (c *Client) AllTables(schema string, opt Option) ([]*Table, error)
- func (c *Client) Connect()
- func (c *Client) Disconnect() error
- func (c *Client) SetProvider(p Provider)
- func (c *Client) Table(schema string, name string, opt Option) (*Table, error)
- func (c *Client) TableNames(schema string, name string) ([]*Table, error)
- type Column
- func (c Column) Comment() string
- func (c Column) DataType() string
- func (c Column) DefaultValue() string
- func (c Column) IsNullable() bool
- func (c Column) Name() string
- func (c Column) PrimaryKeyPosition() int64
- func (c Column) Schema() string
- func (c Column) Size() Size
- func (c Column) TableName() string
- type ColumnReference
- type Constraint
- type DataSource
- type ForeignKey
- type Index
- type Option
- type Provider
- type Size
- type Table
- func (t *Table) AddColumn(col *Column)
- func (t *Table) AddConstraint(c *Constraint)
- func (t *Table) AddForeignKey(fk *ForeignKey)
- func (t *Table) AddIndex(idx *Index)
- func (t *Table) AddReferencedKey(rk *ForeignKey)
- func (t Table) Columns() []*Column
- func (t Table) Comment() string
- func (t Table) Constraints() []*Constraint
- func (t *Table) FindColumn(name string) (*Column, bool)
- func (t *Table) FindConstraint(name string) (*Constraint, bool)
- func (t *Table) FindForeignKey(name string) (*ForeignKey, bool)
- func (t *Table) FindIndex(name string) (*Index, bool)
- func (t *Table) FindReferencedKey(name string) (*ForeignKey, bool)
- func (t Table) ForeignKeys() []*ForeignKey
- func (t Table) Indices() []*Index
- func (t Table) Name() string
- func (t Table) ReferencedKeys() []*ForeignKey
- func (t Table) Schema() string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSchemaEmpty is raised when schema is not given. ErrSchemaEmpty = errors.New("Schema is required") // ErrConnNotFound is raised when call function before connect to database. ErrConnNotFound = errors.New("Database connection is not found") // ErrInvalidDriver is raised when given driver is unknown. ErrInvalidDriver = errors.New("Invalid driver") // ErrTableNameEmpty is raised when table name is not given. ErrTableNameEmpty = errors.New("Table name is required.") )
var ( // RequireAll is loading option for loading all meta data. RequireAll = Option{ Indices: true, ForeignKeys: true, ReferencedKeys: true, Constraints: true, } // RequireNone is loading option for loading only columns. RequireNone = Option{ Indices: false, ForeignKeys: false, ReferencedKeys: false, Constraints: false, } )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is table meta data loding client.
func NewClient ¶
func NewClient(ds DataSource) *Client
NewClient returns new Client for connecting to given data source.
func (*Client) AllTableNames ¶
AllTableNames returns all table names in given schema. If schema is empty, raise ErrSchemaEmpty.
func (*Client) AllTables ¶
AllTables returns table meta data list that are contained in given schema. If schema is empty, raise ErrSchemaEmpty.
func (*Client) Disconnect ¶
Disconnect from datasource and close database connection.
func (*Client) SetProvider ¶
SetProvider sets custom provider. If use custom provider, call this before Connect.
func (*Client) Table ¶
Table returns table meta data. If schema is empty, raise ErrSchemaEmpty. If name is empaty, raise ErrTableNameEmpty.
func (*Client) TableNames ¶
TableNames returns table names in given schema. If schema is empty, raise ErrSchemaEmpty. If name is empaty, TableNames returns all table names orderd by table names. If name is given, TableNames returns table names that matches given name.
type Column ¶
type Column struct {
// contains filtered or unexported fields
}
Column is database column metadata.
func NewColumn ¶
func NewColumn(schema string, tableName string, name string, comment string, dataType string, size Size, nullable bool, defaultValue string, pkPosition int64) Column
NewColumn returns new Column initialized with arguments.
func (Column) DefaultValue ¶
DefaultValue returns column's default value
func (Column) IsNullable ¶
IsNullable returns true if column can accept NULL.
func (Column) PrimaryKeyPosition ¶
PrimaryKeyPosition returns this column's position in primary key columns. If this column is not primary key, returns 0.
type ColumnReference ¶
type ColumnReference struct {
// contains filtered or unexported fields
}
ColumnReference is reference to column from column.
func NewColumnReference ¶
func NewColumnReference(from *Column, to *Column) ColumnReference
NewColumnReference returns new ColumnRef initialized with arguments.
func (ColumnReference) From ¶
func (cr ColumnReference) From() *Column
From returns form column of this reference.
func (ColumnReference) To ¶
func (cr ColumnReference) To() *Column
To returns to column of this reference.
type Constraint ¶
type Constraint struct {
// contains filtered or unexported fields
}
Constraint is constraint's meta data. This struct using unique constraint and check constraint.
func NewConstraint ¶
func NewConstraint(schema string, tableName string, name string, kind string, content string) Constraint
NewConstraint returns new Constraint initialized with arguments.
func (Constraint) Content ¶
func (c Constraint) Content() string
Content returns constraint's content.
func (Constraint) Kind ¶
func (c Constraint) Kind() string
Kind returns constraint's kind. If Constraint is unique constraint, Kind returns 'UNIQUE'. If Constraint is check constraint, Kind returns 'CHECK'.
func (Constraint) TableName ¶
func (c Constraint) TableName() string
TableName returns table name that having this constraint.
type DataSource ¶
type DataSource struct { Driver string Version string Host string Port int User string Password string Database string Options map[string]string }
DataSource is database setting.
func InitDataSource ¶
func InitDataSource() DataSource
InitDataSource returns new DataSource that has initialized Options.
type ForeignKey ¶
type ForeignKey struct {
// contains filtered or unexported fields
}
ForeignKey is foreign key's meta data.
func NewForeignKey ¶
func NewForeignKey(schema string, tableName string, name string) ForeignKey
NewForeignKey returns new ForeignKey initialized with arguments.
func (*ForeignKey) AddColumnReference ¶
func (fk *ForeignKey) AddColumnReference(r *ColumnReference)
AddColumnReference appends column reference to ColumnReferences.
func (ForeignKey) ColumnReferences ¶
func (fk ForeignKey) ColumnReferences() []*ColumnReference
ColumnReferences returns foreign key's references from column to other column.
func (ForeignKey) Schema ¶
func (fk ForeignKey) Schema() string
Schema returns foreign key's schema.
func (ForeignKey) TableName ¶
func (fk ForeignKey) TableName() string
TableName returns table name that having this foreign key.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is database index metadata.
type Provider ¶
type Provider interface { // Connect open connection to DataSouce. Connect() (*sql.DB, error) // AllTableNamesSQL should return SQL for loading table names. // Parameters: // 1. schema // Return columns: // 1. schema // 2. table name // 3. table comment // Order: table name AllTableNamesSQL() string // TableNamesSQL should return SQL for loading table names using LIKE table_name. // Parameters: // 1. schema // 2. table name // Return columns: // same as AllTableNamesSQL // Order: table name TableNamesSQL() string // AllTableSQL should return SQL for loading all tables contains columns. // Parameters: // 1. schema // Return columns: // 1. schema // 2. table name // 3. table comment // 4. column name // 5. column comment // 6. data type // 7. length (using in text) // 8. precision (using in numeric or date) // 9. scale (using in numeric) // 10. nullable ("YES" or "NO") // 11. default value (as text) // 12. primary key position // Order: // 1. table name // 2. column position AllTablesSQL() string // TableSQL should return SQL for loading a table contains columns. // Parameters: // 1. schema // 2. table name // Return columns: // same as AllTableSQL // Order: // 1. column position TableSQL() string // AllIndicesSQL should return SQL for loading all indices. // Parameters: // 1. schema // Return columns: // 1. schema // 2. table name // 3. index name // 4. unique ("YES" or "NO") // 5. column name // Order: // 1. table name // 2. index name // 3. column position AllIndicesSQL() string // IndicesSQL should return SQL for loading indices in a table. // Parameters: // 1. schema // 2. table name // Return columns: // same as AllIndicesSQL // Order: // 1. index name // 2. column position IndicesSQL() string // AllForeignKeysSQL should return SQL for loading all foreign keys. // Parameters: // 1. schema // Return columns: // 1. foreign key name // 2. schema (from) // 3. table name (from) // 4. column name (from) // 5. schema (to) // 6. table name (to) // 7. column name (to) // Order: // 1. table name (from) // 2. foreign key name // 3. column position (from) AllForeignKeysSQL() string // ForeignKeysSQL should return SQL for loading foreign keys in a table. // Parameters: // 1. schema // 2. table name // Return columns: // same as AllForeignKeysSQL // Order: // 1. foreign key name // 2. column position (from) ForeignKeysSQL() string // AllReferencedKeysSQL should return SQL for loading all foreign keys. // Parameters: // 1. schema // Return columns: // 1. foreign key name // 2. schema (from) // 3. table name (from) // 4. column name (from) // 5. schema (to) // 6. table name (to) // 7. column name (to) // Order: // 1. table name (to) // 2. foreign key name // 3. column position (to) AllReferencedKeysSQL() string // ReferencedKeys should return SQL for loading referenced foreign keys in a table. // Parameters: // 1. schema // 2. table name // Return columns: // same as AllReferencedKeysSQL // Order: // 1. foreign key name // 2. column position (to) ReferencedKeysSQL() string // AllConstraintsSQL should return SQL for loading all constraints. // Parameters: // 1. schema // Return columns: // 1. schema // 2. table name // 3. constraint name // 4. kind (eg. "CHECK", "UNIQUE") // 5. content // Order: // 1. table name // 2. kind // 3. constraint name AllConstraintsSQL() string // ConstraintsSQL should return SQL for loading constraints in a table. // Parameters: // 1. schema // 2. table name // Return columns: // same as AllConstraintsSQL // Order: // 1. table name // 2. kind // 3. constraint name ConstraintsSQL() string }
Provider is interface to absorbe difference of each database.
type Size ¶
type Size struct {
// contains filtered or unexported fields
}
Size is column size
func (Size) IsValid ¶
IsValid returns has value. If length, precision and scale are NULL, IsValid returns false.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table stores table meta data.
func (*Table) AddConstraint ¶
func (t *Table) AddConstraint(c *Constraint)
AddConstraint appends foreign key to Constraints.
func (*Table) AddForeignKey ¶
func (t *Table) AddForeignKey(fk *ForeignKey)
AddForeignKey appends foreign key to ForeignKeys.
func (*Table) AddReferencedKey ¶
func (t *Table) AddReferencedKey(rk *ForeignKey)
AddReferencedKey appends other table's foreign key that reference this table's column to ReferencedKeys.
func (Table) Constraints ¶
func (t Table) Constraints() []*Constraint
Constraints returns having constraints.
func (*Table) FindColumn ¶
FindColumn returns column that has same name as argument. If column that has same name does not exist, return false as second value.
func (*Table) FindConstraint ¶
func (t *Table) FindConstraint(name string) (*Constraint, bool)
FindConstraint returns constraint that has same name as argument. If constraint that has same name does not exist, return false as second value.
func (*Table) FindForeignKey ¶
func (t *Table) FindForeignKey(name string) (*ForeignKey, bool)
FindForeignKey returns foreign key that has same name as argument. If foreign key that has same name does not exist, return false as second value.
func (*Table) FindIndex ¶
FindIndex returns index that has same name as argument. If index that has same name does not exist, return false as second value.
func (*Table) FindReferencedKey ¶
func (t *Table) FindReferencedKey(name string) (*ForeignKey, bool)
FindReferencedKey returns referenced key that has same name as argument. If referenced key that has same name does not exist, return false as second value.
func (Table) ForeignKeys ¶
func (t Table) ForeignKeys() []*ForeignKey
ForeignKeys returns having foreign keys.
func (Table) ReferencedKeys ¶
func (t Table) ReferencedKeys() []*ForeignKey
ReferencedKeys returns having referenced keys.