Documentation ¶
Overview ¶
Package mysql provides MySQL helpers for golembic.
The DSN `Config` helper struct from `github.com/go-sql-driver/mysql` has been vendored into this package (license headers intact) in the files prefixed with `vendor_`. This was done to avoid invoking `init()` in that package and registering a driver that would not be used.
Index ¶
- type Config
- type Option
- func OptConfig(cfg *Config) Option
- func OptDBName(database string) Option
- func OptHostPort(host string, port int) Option
- func OptIdleConnections(count int) Option
- func OptMaxConnections(count int) Option
- func OptMaxLifetime(d time.Duration) Option
- func OptNet(net string) Option
- func OptPassword(password string) Option
- func OptUser(user string) Option
- type SQLProvider
- func (*SQLProvider) NewCreateTableParameters() golembic.CreateTableParameters
- func (sp *SQLProvider) Open() (*sql.DB, error)
- func (*SQLProvider) QueryParameter(_ int) string
- func (*SQLProvider) QuoteIdentifier(name string) string
- func (*SQLProvider) QuoteLiteral(literal string) string
- func (sp *SQLProvider) TableExistsSQL() string
- func (*SQLProvider) TimestampColumn() golembic.TimestampColumn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { User string // Username Passwd string // Password (requires User) Net string // Network type Addr string // Network address (requires Net) DBName string // Database name Params map[string]string // Connection parameters Collation string // Connection collation Loc *time.Location // Location for time.Time values MaxAllowedPacket int // Max packet size allowed ServerPubKey string // Server public key name TLSConfig string // TLS configuration name Timeout time.Duration // Dial timeout ReadTimeout time.Duration // I/O read timeout WriteTimeout time.Duration // I/O write timeout AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE AllowCleartextPasswords bool // Allows the cleartext client side plugin AllowNativePasswords bool // Allows the native password authentication method AllowOldPasswords bool // Allows the old insecure password method CheckConnLiveness bool // Check connections for liveness before using them ClientFoundRows bool // Return number of matching rows instead of rows changed ColumnsWithAlias bool // Prepend table alias to column names InterpolateParams bool // Interpolate placeholders into query string MultiStatements bool // Allow multiple statements in one query ParseTime bool // Parse time values to time.Time RejectReadOnly bool // Reject read-only connections // contains filtered or unexported fields }
Config is a configuration parsed from a DSN string. If a new Config is created instead of being parsed from a DSN string, the NewConfig function should be used, which sets default values.
type Option ¶
type Option = func(*SQLProvider) error
Option describes options used to create a new config for a SQL provider.
func OptHostPort ¶
OptHostPort sets the `Addr` on a `Config`.
func OptIdleConnections ¶
OptIdleConnections sets the `IdleConnections` on a `SQLProvider`.
func OptMaxConnections ¶
OptMaxConnections sets the `MaxConnections` on a `SQLProvider`.
func OptMaxLifetime ¶
OptMaxLifetime sets the `MaxLifetime` on a `SQLProvider`.
func OptPassword ¶
OptPassword sets the `Passwd` on a `Config`.
type SQLProvider ¶
type SQLProvider struct { Config *Config // IdleConnections is the number of idle connections. IdleConnections int // MaxConnections is the maximum number of connections. MaxConnections int // MaxLifetime is the maximum time a connection can be open. MaxLifetime time.Duration }
SQLProvider is a MySQL-specific database engine provider.
func New ¶
func New(opts ...Option) (*SQLProvider, error)
New creates a MySQL-specific database engine provider from some options.
func (*SQLProvider) NewCreateTableParameters ¶
func (*SQLProvider) NewCreateTableParameters() golembic.CreateTableParameters
NewCreateTableParameters produces the SQL expressions used in the the `CREATE TABLE` statement used to create the migrations table.
func (*SQLProvider) Open ¶
func (sp *SQLProvider) Open() (*sql.DB, error)
Open creates a database connection pool to a MySQL instance.
func (*SQLProvider) QueryParameter ¶
func (*SQLProvider) QueryParameter(_ int) string
QueryParameter produces the placeholder `?` for a numbered parameter in a MySQL query.
func (*SQLProvider) QuoteIdentifier ¶
func (*SQLProvider) QuoteIdentifier(name string) string
QuoteIdentifier quotes an identifier, such as a table name, for usage in a query.
func (*SQLProvider) QuoteLiteral ¶
func (*SQLProvider) QuoteLiteral(literal string) string
QuoteLiteral quotes a literal, such as `2023-01-05 15:00:00Z`, for usage in a query.
func (*SQLProvider) TableExistsSQL ¶
func (sp *SQLProvider) TableExistsSQL() string
TableExistsSQL returns a SQL query that can be used to determine if a table exists.
func (*SQLProvider) TimestampColumn ¶
func (*SQLProvider) TimestampColumn() golembic.TimestampColumn
TimestampColumn produces a value that can be used for reading / writing a `TIMESTAMP` column to a `time.Time` in MySQL.