Documentation ¶
Index ¶
- Variables
- func MySQLBuildQueryString(user, pass, dbname, host string, port int, sslmode string) string
- func PostgresBuildQueryString(user, pass, dbname, host string, port int, sslmode string) string
- type MockDriver
- func (m *MockDriver) Close()
- func (m *MockDriver) Columns(schema, tableName string) ([]bdb.Column, error)
- func (m *MockDriver) ForeignKeyInfo(schema, tableName string) ([]bdb.ForeignKey, error)
- func (m *MockDriver) IndexPlaceholders() bool
- func (m *MockDriver) LeftQuote() byte
- func (m *MockDriver) Open() error
- func (m *MockDriver) PrimaryKeyInfo(schema, tableName string) (*bdb.PrimaryKey, error)
- func (m *MockDriver) RightQuote() byte
- func (m *MockDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error)
- func (m *MockDriver) TranslateColumnType(c bdb.Column) bdb.Column
- func (m *MockDriver) UseLastInsertID() bool
- type MySQLDriver
- func (m *MySQLDriver) Close()
- func (m *MySQLDriver) Columns(schema, tableName string) ([]bdb.Column, error)
- func (m *MySQLDriver) ForeignKeyInfo(schema, tableName string) ([]bdb.ForeignKey, error)
- func (m *MySQLDriver) IndexPlaceholders() bool
- func (m *MySQLDriver) LeftQuote() byte
- func (m *MySQLDriver) Open() error
- func (m *MySQLDriver) PrimaryKeyInfo(schema, tableName string) (*bdb.PrimaryKey, error)
- func (m *MySQLDriver) RightQuote() byte
- func (m *MySQLDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error)
- func (m *MySQLDriver) TranslateColumnType(c bdb.Column) bdb.Column
- func (m *MySQLDriver) UseLastInsertID() bool
- type PostgresDriver
- func (p *PostgresDriver) Close()
- func (p *PostgresDriver) Columns(schema, tableName string) ([]bdb.Column, error)
- func (p *PostgresDriver) ForeignKeyInfo(schema, tableName string) ([]bdb.ForeignKey, error)
- func (p *PostgresDriver) IndexPlaceholders() bool
- func (p *PostgresDriver) LeftQuote() byte
- func (p *PostgresDriver) Open() error
- func (p *PostgresDriver) PrimaryKeyInfo(schema, tableName string) (*bdb.PrimaryKey, error)
- func (p *PostgresDriver) RightQuote() byte
- func (p *PostgresDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error)
- func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column
- func (p *PostgresDriver) UseLastInsertID() bool
Constants ¶
This section is empty.
Variables ¶
var TinyintAsBool bool
TinyintAsBool is a global that is set from main.go if a user specifies this flag when generating. This flag only applies to MySQL so we're using a global instead, to avoid breaking the interface. If TinyintAsBool is true then tinyint(1) will be mapped in your generated structs to bool opposed to int8.
Functions ¶
func MySQLBuildQueryString ¶
MySQLBuildQueryString builds a query string for MySQL.
Types ¶
type MockDriver ¶
type MockDriver struct{}
MockDriver is a mock implementation of the bdb driver Interface
func (*MockDriver) Columns ¶
func (m *MockDriver) Columns(schema, tableName string) ([]bdb.Column, error)
Columns returns a list of mock columns
func (*MockDriver) ForeignKeyInfo ¶
func (m *MockDriver) ForeignKeyInfo(schema, tableName string) ([]bdb.ForeignKey, error)
ForeignKeyInfo returns a list of mock foreignkeys
func (*MockDriver) IndexPlaceholders ¶
func (m *MockDriver) IndexPlaceholders() bool
IndexPlaceholders returns true to indicate fake support of indexed placeholders
func (*MockDriver) LeftQuote ¶
func (m *MockDriver) LeftQuote() byte
LeftQuote is the quoting character for the left side of the identifier
func (*MockDriver) Open ¶
func (m *MockDriver) Open() error
Open mimics a database open call and returns nil for no error
func (*MockDriver) PrimaryKeyInfo ¶
func (m *MockDriver) PrimaryKeyInfo(schema, tableName string) (*bdb.PrimaryKey, error)
PrimaryKeyInfo returns mock primary key info for the passed in table name
func (*MockDriver) RightQuote ¶
func (m *MockDriver) RightQuote() byte
RightQuote is the quoting character for the right side of the identifier
func (*MockDriver) TableNames ¶
func (m *MockDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error)
TableNames returns a list of mock table names
func (*MockDriver) TranslateColumnType ¶
func (m *MockDriver) TranslateColumnType(c bdb.Column) bdb.Column
TranslateColumnType converts a column to its "null." form if it is nullable
func (*MockDriver) UseLastInsertID ¶
func (m *MockDriver) UseLastInsertID() bool
UseLastInsertID returns a database mock LastInsertID compatibility flag
type MySQLDriver ¶
type MySQLDriver struct {
// contains filtered or unexported fields
}
MySQLDriver holds the database connection string and a handle to the database connection.
func NewMySQLDriver ¶
func NewMySQLDriver(user, pass, dbname, host string, port int, sslmode string) *MySQLDriver
NewMySQLDriver takes the database connection details as parameters and returns a pointer to a MySQLDriver object. Note that it is required to call MySQLDriver.Open() and MySQLDriver.Close() to open and close the database connection once an object has been obtained.
func (*MySQLDriver) Columns ¶
func (m *MySQLDriver) Columns(schema, tableName string) ([]bdb.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) ([]bdb.ForeignKey, error)
ForeignKeyInfo retrieves the foreign keys for a given table name.
func (*MySQLDriver) IndexPlaceholders ¶
func (m *MySQLDriver) IndexPlaceholders() bool
IndexPlaceholders returns false to indicate MySQL doesnt support indexed placeholders
func (*MySQLDriver) LeftQuote ¶
func (m *MySQLDriver) LeftQuote() byte
LeftQuote is the quoting character for the left side of the identifier
func (*MySQLDriver) Open ¶
func (m *MySQLDriver) Open() error
Open opens the database connection using the connection string
func (*MySQLDriver) PrimaryKeyInfo ¶
func (m *MySQLDriver) PrimaryKeyInfo(schema, tableName string) (*bdb.PrimaryKey, error)
PrimaryKeyInfo looks up the primary key for a table.
func (*MySQLDriver) RightQuote ¶
func (m *MySQLDriver) RightQuote() byte
RightQuote is the quoting character for the right side of the identifier
func (*MySQLDriver) TableNames ¶
func (m *MySQLDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error)
TableNames connects to the postgres database and retrieves all table names from the information_schema where the table schema is public.
func (*MySQLDriver) TranslateColumnType ¶
func (m *MySQLDriver) TranslateColumnType(c bdb.Column) bdb.Column
TranslateColumnType converts postgres database types to Go types, for example "varchar" to "string" and "bigint" to "int64". It returns this parsed data as a Column object.
func (*MySQLDriver) UseLastInsertID ¶
func (m *MySQLDriver) UseLastInsertID() bool
UseLastInsertID returns false for postgres
type PostgresDriver ¶
type PostgresDriver struct {
// contains filtered or unexported fields
}
PostgresDriver holds the database connection string and a handle to the database connection.
func NewPostgresDriver ¶
func NewPostgresDriver(user, pass, dbname, host string, port int, sslmode string) *PostgresDriver
NewPostgresDriver takes the database connection details as parameters and returns a pointer to a PostgresDriver object. Note that it is required to call PostgresDriver.Open() and PostgresDriver.Close() to open and close the database connection once an object has been obtained.
func (*PostgresDriver) Close ¶
func (p *PostgresDriver) Close()
Close closes the database connection
func (*PostgresDriver) Columns ¶
func (p *PostgresDriver) Columns(schema, tableName string) ([]bdb.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 (*PostgresDriver) ForeignKeyInfo ¶
func (p *PostgresDriver) ForeignKeyInfo(schema, tableName string) ([]bdb.ForeignKey, error)
ForeignKeyInfo retrieves the foreign keys for a given table name.
func (*PostgresDriver) IndexPlaceholders ¶
func (p *PostgresDriver) IndexPlaceholders() bool
IndexPlaceholders returns true to indicate PSQL supports indexed placeholders
func (*PostgresDriver) LeftQuote ¶
func (p *PostgresDriver) LeftQuote() byte
LeftQuote is the quoting character for the left side of the identifier
func (*PostgresDriver) Open ¶
func (p *PostgresDriver) Open() error
Open opens the database connection using the connection string
func (*PostgresDriver) PrimaryKeyInfo ¶
func (p *PostgresDriver) PrimaryKeyInfo(schema, tableName string) (*bdb.PrimaryKey, error)
PrimaryKeyInfo looks up the primary key for a table.
func (*PostgresDriver) RightQuote ¶
func (p *PostgresDriver) RightQuote() byte
RightQuote is the quoting character for the right side of the identifier
func (*PostgresDriver) TableNames ¶
func (p *PostgresDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error)
TableNames connects to the postgres database and retrieves all table names from the information_schema where the table schema is schema. It uses a whitelist and blacklist.
func (*PostgresDriver) TranslateColumnType ¶
func (p *PostgresDriver) TranslateColumnType(c bdb.Column) bdb.Column
TranslateColumnType converts postgres database types to Go types, for example "varchar" to "string" and "bigint" to "int64". It returns this parsed data as a Column object.
func (*PostgresDriver) UseLastInsertID ¶
func (p *PostgresDriver) UseLastInsertID() bool
UseLastInsertID returns false for postgres