Documentation ¶
Index ¶
- Constants
- func Close() error
- func Execute(sql string, args ...interface{}) (*mysql.Result, error)
- func InitMySQLGlobalPool(addr, dbName, dbUser, dbPass string, ...) error
- func InitMySQLGlobalPoolWithConfig(config Config, ...) error
- func InitMySQLGlobalPoolWithDefault(addr, dbName, dbUser, dbPass string) error
- func InitMySQLGlobalPoolWithPoolConfig(config PoolConfig) error
- func IsClosed() bool
- func Release(num int) error
- func ReplaceGlobalPool(pool *Pool) error
- func Supply(num int) error
- type Config
- type Conn
- type Pool
- type PoolConfig
- type PoolConn
Constants ¶
const ( DefaultCharSet = "utf8mb4" ReplicationMaster = "master" ReplicationSlave = "slave" ReplicationRelay = "relay" // it has master and slave roles at the same time HostString = "host" PortString = "port" ShowSlaveStatusSQL = "show slave status" )
const ( DefaultMaxConnections = 20 DefaultInitConnections = 5 DefaultMaxIdleConnections = 10 DefaultMaxIdleTime = 1800 // Seconds DefaultKeepAliveInterval = 300 // Seconds DefaultKeepAliveChunkSize = 5 DefaultSleepTime = 1 // Seconds )
Variables ¶
This section is empty.
Functions ¶
func Close ¶ added in v0.2.1
func Close() error
Close closes global pool, it sets global pool to nil pointer
func InitMySQLGlobalPool ¶ added in v0.2.1
func InitMySQLGlobalPool(addr, dbName, dbUser, dbPass string, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) error
InitMySQLGlobalPool returns a new *Pool and replaces it as global pool
func InitMySQLGlobalPoolWithConfig ¶ added in v0.2.1
func InitMySQLGlobalPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) error
InitMySQLGlobalPoolWithConfig returns a new *Pool with a Config object and replaces it as global pool
func InitMySQLGlobalPoolWithDefault ¶ added in v0.2.1
InitMySQLGlobalPoolWithDefault returns a new *Pool with default configuration and replaces it as global pool
func InitMySQLGlobalPoolWithPoolConfig ¶ added in v0.2.1
func InitMySQLGlobalPoolWithPoolConfig(config PoolConfig) error
InitMySQLGlobalPoolWithPoolConfig returns a new *Pool with a PoolConfig object and replaces it as global pool
func IsClosed ¶ added in v0.2.1
func IsClosed() bool
IsClosed returns if global pool had been closed
func Release ¶ added in v0.2.1
Release releases given number of connections of global pool, each connection will disconnect with database
func ReplaceGlobalPool ¶ added in v0.2.1
ReplaceGlobalPool replaces given pool as global pool
Types ¶
type Conn ¶
func NewMySQLConn ¶
NewMySQLConn returns connection to mysql database, be aware that addr is host:port style, default charset is utf8mb4
func (*Conn) CheckInstanceStatus ¶ added in v0.2.0
func (*Conn) GetReplicationRole ¶
func (*Conn) GetReplicationSlaveList ¶
type Pool ¶ added in v0.2.0
type Pool struct { sync.Mutex PoolConfig // contains filtered or unexported fields }
func NewMySQLPool ¶ added in v0.2.0
func NewMySQLPool(addr, dbName, dbUser, dbPass string, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) (*Pool, error)
NewMySQLPool returns a new *Pool
func NewMySQLPoolWithConfig ¶ added in v0.2.0
func NewMySQLPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) (*Pool, error)
NewMySQLPoolWithConfig returns a new *Pool with a Config object
func NewMySQLPoolWithDefault ¶ added in v0.2.0
NewMySQLPoolWithDefault returns a new *Pool with default configuration
func NewMySQLPoolWithPoolConfig ¶ added in v0.2.0
func NewMySQLPoolWithPoolConfig(config PoolConfig) (*Pool, error)
NewMySQLPoolWithPoolConfig returns a new *Pool with a PoolConfig object
func (*Pool) Supply ¶ added in v0.2.0
Supply is an exported alias of supply() function with routine safe
func (*Pool) UsedConnections ¶ added in v0.2.1
UsedConnections returns used connection number
type PoolConfig ¶ added in v0.2.0
type PoolConfig struct { Config MaxConnections int InitConnections int MaxIdleConnections int MaxIdleTime int KeepAliveInterval int }
func NewPoolConfig ¶ added in v0.2.0
func NewPoolConfig(addr, dbName, dbUser, dbPass string, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) PoolConfig
NewPoolConfig returns a new PoolConfig
func NewPoolConfigWithConfig ¶ added in v0.2.0
func NewPoolConfigWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) PoolConfig
NewPoolConfigWithConfig returns a new PoolConfig
func (*PoolConfig) Validate ¶ added in v0.2.0
func (cfg *PoolConfig) Validate() (bool, error)
Validate validates pool config
type PoolConn ¶ added in v0.2.0
func Get ¶ added in v0.2.1
Get get gets a connection from pool and validate it, if there is no valid connection in the pool, it will create a new connection
func NewPoolConn ¶ added in v0.2.0
NewPoolConn returns a new *PoolConn
func NewPoolConnWithPool ¶ added in v0.2.0
NewPoolConnWithPool returns a new *PoolConn
func (*PoolConn) DisConnect ¶ added in v0.2.0
DisConnect disconnects from mysql, normally when using connection pool, there is no need to disconnect manually, consider to use Close() instead.