Documentation ¶
Index ¶
- Variables
- func RegistDriver(driverName string, driver Driver)
- type Column
- type Driver
- type DriverWithAutoInc
- type Loader
- func (loader *Loader) Close()
- func (loader *Loader) Conn() *sql.Conn
- func (loader *Loader) ConnPool() *sql.DB
- func (loader *Loader) DataSourceName() string
- func (loader *Loader) DataTypes() []string
- func (loader *Loader) DriverName() string
- func (loader *Loader) LoadAutoIncColumn(tableName string) (columnName string, err error)
- func (loader *Loader) LoadFK(tableName, fkName string) (columnNames []string, refTableName string, refColumnNames []string, err error)
- func (loader *Loader) LoadFKNames(tableName string) (fkNames []string, err error)
- func (loader *Loader) LoadIndex(tableName, indexName string) (columnNames []string, isPrimary bool, isUnique bool, err error)
- func (loader *Loader) LoadIndexNames(tableName string) (indexNames []string, err error)
- func (loader *Loader) LoadQueryResultColumns(query string, args ...interface{}) (columns []*Column, err error)
- func (loader *Loader) LoadTableColumns(tableName string) (columns []*TableColumn, err error)
- func (loader *Loader) LoadTableNames() (tableNames []string, err error)
- func (loader *Loader) Quote(identifier string) string
- type TableColumn
Constants ¶
This section is empty.
Variables ¶
var ( // ConnectTimeout is the database connection timeout. ConnectTimeout = time.Second * 5 )
Functions ¶
func RegistDriver ¶
RegistDriver regist a driver.
Types ¶
type Column ¶
type Column struct { // Name is name of the result column. Name string // ScanType is the go type suitable for scanning into. ScanType reflect.Type // DatabaseTypeName is the database system name of the column type. (e.g. "VARCHAR", "INT") DatabaseTypeName string // Nullable is valid only when HasNullable is true. HasNullable bool // Nullable is true if this column can have NULL value. Nullable bool // Length is valid only HasLength is true HasLength bool // Length returns the column type length for variable length column types. Length int64 // Precision and Scale is valid only when HasPrecisionScale is true. HasPrecisionScale bool // Column precision. Precision int64 // Column scale. Scale int64 // DataType is a 'translated' driver-specific type identifier (ignore nullable), such as: // - uint24 // - json // - time // It is used in scan type mapping only, thus can be any valid identifier, no need to be a real type name. DataType string }
Column represents a query result column.
type Driver ¶
type Driver interface { // LoadQueryResultColumns returns result columns of a query. LoadQueryResultColumns(conn *sql.Conn, query string, args ...interface{}) (columns []*Column, err error) // LoadTableNames returns all table names in current database. LoadTableNames(conn *sql.Conn) (tableNames []string, err error) // LoadTableColumns returns columns of a given table. LoadTableColumns(conn *sql.Conn, tableName string) (tableColumns []*TableColumn, err error) // LoadIndexNames returns all index name for a given table. LoadIndexNames(conn *sql.Conn, tableName string) (indexNames []string, err error) // LoadIndex returns information of a given index. LoadIndex(conn *sql.Conn, tableName, indexName string) (columnNames []string, isPrimary bool, isUnique bool, err error) // LoadFKNames returns all foreign key constraint names for a given table. LoadFKNames(conn *sql.Conn, tableName string) (fkNames []string, err error) // LoadFK returns information of a given foreign key constraint. LoadFK(conn *sql.Conn, tableName, fkName string) (columnNames []string, refTableName string, refColumnNames []string, err error) // DataTypes returns full list of driver-specific type identifiers used in Column.DataType. DataTypes() []string // Quote returns the quoted identifier. Quote(identifier string) string }
Driver is the low level interface of loader talking to different databases.
NOTE: Use sql.Conn instead of sql.DB to make sure only one database connection is using.
type DriverWithAutoInc ¶
type DriverWithAutoInc interface { Driver // LoadAutoIncColumn returns the 'auto increament' column's name for a given table or "" if not found. LoadAutoIncColumn(conn *sql.Conn, tableName string) (columnName string, err error) }
DriverWithAutoInc is Driver having single auto increment column support (e.g. MySQL)
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is used to load information from a database.
func (*Loader) DataSourceName ¶
DataSourceName returns the dsn.
func (*Loader) DataTypes ¶
DataTypes returns full list of driver-specific type identifiers used in Column.DataType.
func (*Loader) DriverName ¶
DriverName returns the driver's name.
func (*Loader) LoadAutoIncColumn ¶
LoadAutoIncColumn returns the 'auto increament' column's name for a given table or "" if not found.
func (*Loader) LoadFK ¶
func (loader *Loader) LoadFK(tableName, fkName string) (columnNames []string, refTableName string, refColumnNames []string, err error)
LoadFK returns information of a given foreign key constraint.
func (*Loader) LoadFKNames ¶
LoadFKNames returns all foreign key constraint names for a given table.
func (*Loader) LoadIndex ¶
func (loader *Loader) LoadIndex(tableName, indexName string) (columnNames []string, isPrimary bool, isUnique bool, err error)
LoadIndex returns information of a given index.
func (*Loader) LoadIndexNames ¶
LoadIndexNames returns all index name for a given table.
func (*Loader) LoadQueryResultColumns ¶
func (loader *Loader) LoadQueryResultColumns(query string, args ...interface{}) (columns []*Column, err error)
LoadQueryResultColumns returns result columns of a query.
func (*Loader) LoadTableColumns ¶
func (loader *Loader) LoadTableColumns(tableName string) (columns []*TableColumn, err error)
LoadTableColumns returns columns of a given table.
func (*Loader) LoadTableNames ¶
LoadTableNames returns all table names in current database.
type TableColumn ¶
type TableColumn struct { // Basic column information. Column // Pos is the position of the column in table. Pos int // DefaultValue is the default value of the table column. DefaultValue sql.NullString }
TableColumn represents a table column.