mysql

package
v0.0.0-...-0a47f3e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

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

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.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config and sets default values.

func ParseDSN

func ParseDSN(dsn string) (cfg *Config, err error)

ParseDSN parses the DSN string to a Config

func (*Config) Clone

func (cfg *Config) Clone() *Config

func (*Config) FormatDSN

func (cfg *Config) FormatDSN() string

FormatDSN formats the given Config into a DSN string which can be passed to the driver.

type Option

type Option = func(*SQLProvider) error

Option describes options used to create a new config for a SQL provider.

func OptConfig

func OptConfig(cfg *Config) Option

OptConfig sets the `Config` on a `SQLProvider`.

func OptDBName

func OptDBName(database string) Option

OptDBName sets the `DBName` on a `Config`.

func OptHostPort

func OptHostPort(host string, port int) Option

OptHostPort sets the `Addr` on a `Config`.

func OptIdleConnections

func OptIdleConnections(count int) Option

OptIdleConnections sets the `IdleConnections` on a `SQLProvider`.

func OptMaxConnections

func OptMaxConnections(count int) Option

OptMaxConnections sets the `MaxConnections` on a `SQLProvider`.

func OptMaxLifetime

func OptMaxLifetime(d time.Duration) Option

OptMaxLifetime sets the `MaxLifetime` on a `SQLProvider`.

func OptNet

func OptNet(net string) Option

OptNet sets the `Net` on a `Config`.

func OptPassword

func OptPassword(password string) Option

OptPassword sets the `Passwd` on a `Config`.

func OptUser

func OptUser(user string) Option

OptUser sets the `User` 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL