Documentation
¶
Index ¶
- Constants
- Variables
- func GetMysqlDsn(connection *MysqlConnectionOptions, multiStatements bool) string
- func IsTx(executor boil.ContextExecutor) bool
- func Migrate(conn *MysqlConnectionOptions, config *MigrationConfig) error
- func MustCommit(tx *sql.Tx)
- func MustRollbackTx(tx *sql.Tx)
- type BalancingMode
- type ClusterConfig
- type ConnectionConfig
- type MigrationConfig
- type MysqlConnection
- type MysqlConnectionOptions
- type MysqlConnectionPool
- func (m *MysqlConnectionPool) BeginTx() (*sql.Tx, error)
- func (m *MysqlConnectionPool) Close()
- func (m *MysqlConnectionPool) GetActiveConfig() (*MysqlConnectionOptions, error)
- func (m *MysqlConnectionPool) GetConnection() (*sql.DB, error)
- func (m *MysqlConnectionPool) MustBeginTx() *sql.Tx
- func (m *MysqlConnectionPool) MustGetConnection() *sql.DB
Constants ¶
View Source
const SUBSYTEM = "database"
Variables ¶
View Source
var ( ErrNoHealthyConn = errors.New("no healthy mysql connection available") ErrUnsupportedBalancingMode = errors.New("unsupported balancing mode") )
Functions ¶
func GetMysqlDsn ¶
func GetMysqlDsn(connection *MysqlConnectionOptions, multiStatements bool) string
func IsTx ¶
func IsTx(executor boil.ContextExecutor) bool
IsTx checks whether the given executor is a transaction
func Migrate ¶
func Migrate(conn *MysqlConnectionOptions, config *MigrationConfig) error
func MustCommit ¶
MustCommit commits the given transaction or panics if an error occurs
func MustRollbackTx ¶
MustRollbackTx rolls back the given transaction or panics if an error occurs
Types ¶
type BalancingMode ¶
type BalancingMode string
const ( Random BalancingMode = "random" // the connection pool will return a random database node each time Ordered BalancingMode = "ordered" // the connection pool will always return the first available database node )
type ClusterConfig ¶
type ClusterConfig struct {
IsGaleraCluster *bool `yaml:"is_galera_cluster" json:"is_galera_cluster" mapstructure:"is_galera_cluster" validate:"required"`
BalancingMode BalancingMode `yaml:"balancing_mode" json:"balancing_mode" mapstructure:"balancing_mode" validate:"required,oneof=random ordered"`
User string `yaml:"user" json:"user" mapstructure:"user" validate:"required"`
Password string `yaml:"password" json:"password" mapstructure:"password" validate:"required"`
Database string `yaml:"database" json:"database" mapstructure:"database" validate:"required"`
Connections []*ConnectionConfig `yaml:"connections" json:"connections" mapstructure:"connections" validate:"gte=1,dive,required"`
}
type ConnectionConfig ¶
type MigrationConfig ¶
type MigrationConfig struct {
MigrationDir string `yaml:"migration_dir" json:"migration_dir" mapstructure:"migration_dir" validate:"required"` // Directory for SQL migration files
}
type MysqlConnection ¶
type MysqlConnectionOptions ¶
type MysqlConnectionPool ¶
type MysqlConnectionPool struct {
Connections []*MysqlConnection
Mutex *sync.Mutex
PingsTicker *time.Ticker
PingsDone chan bool
Config *ClusterConfig
}
func NewMysqlConnectionPool ¶
func NewMysqlConnectionPool(config *ClusterConfig) (*MysqlConnectionPool, error)
func (*MysqlConnectionPool) BeginTx ¶
func (m *MysqlConnectionPool) BeginTx() (*sql.Tx, error)
BeginTx starts a database transaction
func (*MysqlConnectionPool) Close ¶
func (m *MysqlConnectionPool) Close()
Close closes all database connections from the pool
func (*MysqlConnectionPool) GetActiveConfig ¶
func (m *MysqlConnectionPool) GetActiveConfig() (*MysqlConnectionOptions, error)
func (*MysqlConnectionPool) GetConnection ¶
func (m *MysqlConnectionPool) GetConnection() (*sql.DB, error)
GetConnection returns an active connection or ErrNoHealthyConn if none of the connections from the pool is healthy
func (*MysqlConnectionPool) MustBeginTx ¶
func (m *MysqlConnectionPool) MustBeginTx() *sql.Tx
MustBeginTx starts a database transaction or panics if an error occurs
func (*MysqlConnectionPool) MustGetConnection ¶
func (m *MysqlConnectionPool) MustGetConnection() *sql.DB
MustGetConnection returns an active connection of panics if none of the connections from the pool is healthy
Click to show internal directories.
Click to hide internal directories.