2016-02-23 18:27:32 +10:00
|
|
|
package dbdrivers
|
|
|
|
|
2016-02-24 19:17:58 +10:00
|
|
|
// DBDriver is an interface that handles the operation uniqueness of each
|
|
|
|
// type of database connection. For example, queries to obtain schema data
|
|
|
|
// will vary depending on what type of database software is in use.
|
|
|
|
// The goal of the DBDriver is to retrieve all table names in a database
|
2016-03-01 20:05:25 -08:00
|
|
|
// using GetAllTables() if no table names are provided via flags,
|
2016-02-24 19:17:58 +10:00
|
|
|
// to handle the database connection using Open() and Close(), and to
|
|
|
|
// build the table information using GetTableInfo() and ParseTableInfo()
|
2016-02-23 18:27:32 +10:00
|
|
|
type DBDriver interface {
|
2016-03-01 20:05:25 -08:00
|
|
|
// GetAllTables connects to the database and retrieves all "public" table names
|
|
|
|
GetAllTables() ([]string, error)
|
2016-02-24 19:17:58 +10:00
|
|
|
|
2016-03-01 07:53:56 -08:00
|
|
|
// GetTableInfo retrieves column information about the table.
|
|
|
|
GetTableInfo(tableName string) ([]DBColumn, error)
|
2016-02-24 19:17:58 +10:00
|
|
|
|
2016-03-01 07:53:56 -08:00
|
|
|
// ParseTableInfo builds a DBColumn out of a column name and column type.
|
2016-02-24 19:17:58 +10:00
|
|
|
// Its main responsibility is to convert database types to Go types, for example
|
|
|
|
// "varchar" to "string".
|
2016-03-01 07:53:56 -08:00
|
|
|
ParseTableInfo(name, colType string, isNullable bool) DBColumn
|
2016-02-24 19:17:58 +10:00
|
|
|
|
2016-02-23 18:27:32 +10:00
|
|
|
// Open the database connection
|
|
|
|
Open() error
|
2016-02-24 19:17:58 +10:00
|
|
|
|
2016-02-23 18:27:32 +10:00
|
|
|
// Close the database connection
|
|
|
|
Close()
|
|
|
|
}
|
|
|
|
|
2016-03-01 07:53:56 -08:00
|
|
|
// DBColumn holds information about a database column name.
|
|
|
|
// Column types are Go types, converted by ParseTableInfo.
|
|
|
|
type DBColumn struct {
|
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
IsNullable bool
|
2016-02-23 18:27:32 +10:00
|
|
|
}
|