Documentation ¶
Index ¶
- func Assemble(config DBConfig) (dbinfo *structs.DBInfo, err error)
- func ColumnsFromList(list []string, tablename string) []string
- func MySQLBuildQueryString(user, pass, dbname, host string, port int, sslmode string) string
- func TablesFromList(list []string) []string
- type Config
- func (c Config) DefaultInt(key string, def int) int
- func (c Config) DefaultString(key, def string) string
- func (c Config) Int(key string) (int, bool)
- func (c Config) MustString(key string) string
- func (c Config) String(key string) (string, bool)
- func (c Config) StringSlice(key string) ([]string, bool)
- type DBConfig
- type MySQLDriver
- func (m *MySQLDriver) Assemble(c DBConfig) (dbinfo *structs.DBInfo, err error)
- func (m *MySQLDriver) Columns(schema string, table *structs.Table, tableName string, ...) ([]structs.Column, error)
- func (m *MySQLDriver) ForeignKeyInfo(schema, tableName string) ([]structs.ForeignKey, error)
- func (m *MySQLDriver) PrimaryKeyInfo(schema, tableName string) (*structs.PrimaryKey, error)
- func (m *MySQLDriver) SetIndexAndKey(tables []*structs.Table) (err error)
- func (m *MySQLDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error)
- func (m *MySQLDriver) TranslateColumnType(c structs.Column) structs.Column
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assemble ¶
Assemble is more useful for calling into the library so you don't have to instantiate an empty type.
func ColumnsFromList ¶
ColumnsFromList takes a whitelist or blacklist and returns the columns for a given table.
func MySQLBuildQueryString ¶
MySQLBuildQueryString builds a query string for MySQL.
func TablesFromList ¶
TablesFromList takes a whitelist or blacklist and returns the table names.
Types ¶
type Config ¶
Config define config value needed
func (Config) DefaultInt ¶
DefaultInt retrieves a non-zero int or the default value provided.
func (Config) DefaultString ¶
DefaultString retrieves a non-empty string or the default value provided.
func (Config) Int ¶
Int retrieves an int, the bool says if it exists, is of the appropriate type, and is non-zero. Coerces float64 to int because JSON and Javascript kinda suck.
func (Config) MustString ¶
MustString retrieves a string that must exist and must be a string, it must also not be the empty string
type DBConfig ¶
type DBConfig struct {
// contains filtered or unexported fields
}
DBConfig define db config value needed
func NewDBConfig ¶
NewDBConfig convert Config obj(read via viper) to DBConfig
type MySQLDriver ¶
type MySQLDriver struct {
// contains filtered or unexported fields
}
MySQLDriver holds the database connection string and a handle to the database connection.
func (*MySQLDriver) Assemble ¶
func (m *MySQLDriver) Assemble(c DBConfig) (dbinfo *structs.DBInfo, err error)
Assemble all the information we need to provide back to the driver
func (*MySQLDriver) Columns ¶
func (m *MySQLDriver) Columns(schema string, table *structs.Table, tableName string, whitelist, blacklist []string) ([]structs.Column, error)
Columns takes a table name and attempts to retrieve the table information from the database information_schema.columns. It retrieves the column names and column types and returns those as a []Column after TranslateColumnType() converts the SQL types to Go types, for example: "varchar" to "string"
func (*MySQLDriver) ForeignKeyInfo ¶
func (m *MySQLDriver) ForeignKeyInfo(schema, tableName string) ([]structs.ForeignKey, error)
ForeignKeyInfo retrieves the foreign keys for a given table name.
func (*MySQLDriver) PrimaryKeyInfo ¶
func (m *MySQLDriver) PrimaryKeyInfo(schema, tableName string) (*structs.PrimaryKey, error)
PrimaryKeyInfo looks up the primary key for a table.
func (*MySQLDriver) SetIndexAndKey ¶
func (m *MySQLDriver) SetIndexAndKey(tables []*structs.Table) (err error)
SetIndexAndKey sets indexes & key information to given tables
func (*MySQLDriver) TableNames ¶
func (m *MySQLDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error)
TableNames connects to the mysql database and retrieves all table names from the information_schema where the table schema is public.
func (*MySQLDriver) TranslateColumnType ¶
func (m *MySQLDriver) TranslateColumnType(c structs.Column) structs.Column
TranslateColumnType converts mysql database types to Go types, for example "varchar" to "string" and "bigint" to "int64". It returns this parsed data as a Column object.