Documentation ¶
Index ¶
- Constants
- func Close() error
- func Execute(sql string, args ...interface{}) (middleware.Result, error)
- func InitGlobalPool(addr, dbName, dbUser, dbPass string, ...) error
- func InitGlobalPoolWithConfig(config Config, ...) error
- func InitGlobalPoolWithDefault(addr, dbName, dbUser, dbPass string) error
- func InitGlobalPoolWithPoolConfig(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
- func (conn *Conn) CheckInstanceStatus() bool
- func (conn *Conn) Execute(command string, args ...interface{}) (*Result, error)
- func (conn *Conn) ExecuteContext(ctx context.Context, command string, args ...interface{}) (*Result, error)
- func (conn *Conn) GetReplicationRole() (role ReplicationRole, err error)
- func (conn *Conn) GetReplicationSlaveList() (slaveList []string, err error)
- func (conn *Conn) GetReplicationSlavesStatus() (result *Result, err error)
- func (conn *Conn) GetVersion() (Version, error)
- func (conn *Conn) Prepare(command string) (*Statement, error)
- func (conn *Conn) PrepareContext(ctx context.Context, command string) (*Statement, error)
- type Pool
- type PoolConfig
- type PoolConn
- func (pc *PoolConn) Close() error
- func (pc *PoolConn) Disconnect() error
- func (pc *PoolConn) Execute(command string, args ...interface{}) (middleware.Result, error)
- func (pc *PoolConn) ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)
- func (pc *PoolConn) IsValid() bool
- func (pc *PoolConn) Prepare(command string) (middleware.Statement, error)
- func (pc *PoolConn) PrepareContext(ctx context.Context, command string) (middleware.Statement, error)
- type ReplicationRole
- type Result
- type Statement
- type Version
Constants ¶
const ( DefaultCharSet = "utf8mb4" HostString = "host" PortString = "port" SelectVersionSQL = "select @@version" ShowSlaveStatusSQL = "show slave status" ShowReplicaStatusSQL = "show replica status" ShowSlaveHostsSQL = "show slave hosts" // ReplicationSource represents mysql master, it's an alternative name ReplicationSource ReplicationRole = "source" // ReplicationReplica represents mysql slave, it's an alternative name ReplicationReplica ReplicationRole = "replica" // ReplicationRelay means this mysql instance has source and replica roles at the same time ReplicationRelay ReplicationRole = "relay" )
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 Execute ¶ added in v0.2.1
func Execute(sql string, args ...interface{}) (middleware.Result, error)
Execute execute given sql statement
func InitGlobalPool ¶ added in v0.3.0
func InitGlobalPool(addr, dbName, dbUser, dbPass string, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) error
InitGlobalPool returns a new *Pool and replaces it as global pool
func InitGlobalPoolWithConfig ¶ added in v0.3.0
func InitGlobalPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) error
InitGlobalPoolWithConfig returns a new *Pool with a Config object and replaces it as global pool
func InitGlobalPoolWithDefault ¶ added in v0.3.0
InitGlobalPoolWithDefault returns a new *Pool with default configuration and replaces it as global pool
func InitGlobalPoolWithPoolConfig ¶ added in v0.3.0
func InitGlobalPoolWithPoolConfig(config PoolConfig) error
InitGlobalPoolWithPoolConfig 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 NewConn ¶ added in v0.3.0
NewConn 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
CheckInstanceStatus checks mysql instance status
func (*Conn) Execute ¶ added in v0.2.23
Execute executes given sql and placeholders and returns a result
func (*Conn) ExecuteContext ¶ added in v0.3.0
func (conn *Conn) ExecuteContext(ctx context.Context, command string, args ...interface{}) (*Result, error)
ExecuteContext executes given sql and placeholders with context and returns a result
func (*Conn) GetReplicationRole ¶
func (conn *Conn) GetReplicationRole() (role ReplicationRole, err error)
GetReplicationRole returns replication role
func (*Conn) GetReplicationSlaveList ¶
GetReplicationSlaveList returns slave list of this server
func (*Conn) GetReplicationSlavesStatus ¶
GetReplicationSlavesStatus returns replication slave status, like sql: "show slave status;"
func (*Conn) GetVersion ¶ added in v0.2.32
GetVersion returns mysql version
type Pool ¶ added in v0.2.0
type Pool struct { sync.Mutex PoolConfig // contains filtered or unexported fields }
func NewPool ¶ added in v0.3.0
func NewPool(addr, dbName, dbUser, dbPass string, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) (*Pool, error)
NewPool returns a new *Pool
func NewPoolWithConfig ¶ added in v0.3.0
func NewPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) (*Pool, error)
NewPoolWithConfig returns a new *Pool with a Config object
func NewPoolWithDefault ¶ added in v0.3.0
NewPoolWithDefault returns a new *Pool with default configuration
func NewPoolWithPoolConfig ¶ added in v0.3.0
func NewPoolWithPoolConfig(config PoolConfig) (*Pool, error)
NewPoolWithPoolConfig returns a new *Pool with a PoolConfig object
func (*Pool) Get ¶ added in v0.2.0
func (p *Pool) Get() (middleware.PoolConn, error)
Get is an exported alias of get() function with routine safe
func (*Pool) Supply ¶ added in v0.2.0
Supply is an exported alias of supply() function with routine safe
func (*Pool) Transaction ¶ added in v0.2.22
func (p *Pool) Transaction() (middleware.Transaction, error)
Transaction simply returns *PoolConn, because it had implemented Transaction interface
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.24
Disconnect disconnects from mysql, normally when using connection pool, there is no need to disconnect manually, consider to use Close() instead.
func (*PoolConn) Execute ¶ added in v0.2.5
func (pc *PoolConn) Execute(command string, args ...interface{}) (middleware.Result, error)
Execute executes given sql and placeholders on the mysql server
func (*PoolConn) ExecuteContext ¶ added in v0.3.0
func (pc *PoolConn) ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)
ExecuteContext executes given sql and placeholders on the mysql server
func (*PoolConn) Prepare ¶ added in v0.3.0
func (pc *PoolConn) Prepare(command string) (middleware.Statement, error)
Prepare prepares a statement and returns a *Statement
func (*PoolConn) PrepareContext ¶ added in v0.3.0
func (pc *PoolConn) PrepareContext(ctx context.Context, command string) (middleware.Statement, error)
PrepareContext prepares a statement with context and returns a *Statement
type ReplicationRole ¶ added in v0.2.32
type ReplicationRole string
type Result ¶ added in v0.2.8
func (*Result) LastInsertID ¶ added in v0.2.23
LastInsertID returns the database's auto-generated ID after, for example, an INSERT into a table with primary key.
func (*Result) RowsAffected ¶ added in v0.2.23
RowsAffected returns the number of rows affected by the query.
type Statement ¶ added in v0.3.0
func NewStatement ¶ added in v0.3.0
NewStatement returns a new *Statement with given *client.Stmt
func (*Statement) Execute ¶ added in v0.3.0
func (stmt *Statement) Execute(args ...interface{}) (middleware.Result, error)
Execute executes given sql and placeholders and returns a result
func (*Statement) ExecuteContext ¶ added in v0.3.0
func (stmt *Statement) ExecuteContext(ctx context.Context, args ...interface{}) (middleware.Result, error)
ExecuteContext executes given sql and placeholders with context and returns a result
type Version ¶ added in v0.2.32
type Version interface { // GetMajor returns major GetMajor() int // GetMinor returns minor GetMinor() int // GetRelease returns release GetRelease() int // String returns string format of version String() string }
func NewVersion ¶ added in v0.2.32
NewVersion returns a new instance of Version