Documentation ¶
Index ¶
- Constants
- Variables
- func Close() error
- func Execute(command string, args ...interface{}) (middleware.Result, error)
- func ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)
- func InitGlobalPool(addr string, rt http.RoundTripper, ...) error
- func InitGlobalPoolWithConfig(config Config, ...) error
- func InitGlobalPoolWithDefault(addr 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
- 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 RawData
- type Result
Constants ¶
const ( DefaultMaxConnections = 20 DefaultInitConnections = 5 DefaultMaxIdleConnections = 10 DefaultMaxIdleTime = 1800 // seconds DefaultKeepAliveInterval = 300 // seconds DefaultKeepAliveChunkSize = 5 DefaultSleepTime = 1 // seconds )
Variables ¶
var DefaultRoundTripper http.RoundTripper = &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: (&net.Dialer{Timeout: 30 * time.Second, KeepAlive: 30 * time.Second}).DialContext, TLSHandshakeTimeout: 10 * time.Second, }
DefaultRoundTripper is used if no RoundTripper is set in Config,
Functions ¶
func Execute ¶
func Execute(command string, args ...interface{}) (middleware.Result, error)
Execute execute given sql statement
func ExecuteContext ¶
func ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)
ExecuteContext executes given command with context
func InitGlobalPool ¶
func InitGlobalPool(addr string, rt http.RoundTripper, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) error
InitGlobalPool returns a new *Pool and replaces it as global pool
func InitGlobalPoolWithConfig ¶
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 ¶
InitGlobalPoolWithDefault returns a new *Pool with default configuration and replaces it as global pool
func InitGlobalPoolWithPoolConfig ¶
func InitGlobalPoolWithPoolConfig(config PoolConfig) error
InitGlobalPoolWithPoolConfig returns a new *Pool with a PoolConfig object and replaces it as global pool
func Release ¶
Release releases given number of connections of global pool, each connection will disconnect with database
func ReplaceGlobalPool ¶
ReplaceGlobalPool replaces given pool as global pool
Types ¶
type Config ¶
func NewConfig ¶
func NewConfig(addr string, rt http.RoundTripper) Config
NewConfig returns a new client.Config with given address and round tripper
func NewConfigWithBasicAuth ¶
NewConfigWithBasicAuth returns a new client.Config with given address, user and password
func NewConfigWithDefaultRoundTripper ¶
NewConfigWithDefaultRoundTripper returns a new client.Config with given address and default round tripper
type Conn ¶
func NewConn ¶
func NewConn(addr string, rt http.RoundTripper) (*Conn, error)
NewConn returns a new *Conn with given address and round tripper
func NewConnWithConfig ¶
NewConnWithConfig returns a new *Conn with given config
func (*Conn) CheckInstanceStatus ¶
func (*Conn) Execute ¶
Execute executes given command with arguments and return a result, note that args should must be either time.Time or apiv1.Range of prometheus golang client package
func (*Conn) ExecuteContext ¶
func (conn *Conn) ExecuteContext(ctx context.Context, command string, args ...interface{}) (*Result, error)
ExecuteContext executes given command with arguments and return a result, note that args should must be either time.Time or apiv1.Range of prometheus golang client package
type Pool ¶
type Pool struct { sync.Mutex PoolConfig // contains filtered or unexported fields }
func NewPool ¶
func NewPool(addr string, rt http.RoundTripper, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) (*Pool, error)
NewPool returns a new *Pool
func NewPoolWithConfig ¶
func NewPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) (*Pool, error)
NewPoolWithConfig returns a new *Pool with a Config object
func NewPoolWithDefault ¶
NewPoolWithDefault returns a new *Pool with default configuration
func NewPoolWithPoolConfig ¶
func NewPoolWithPoolConfig(config PoolConfig) (*Pool, error)
NewPoolWithPoolConfig returns a new *Pool with a PoolConfig object
func (*Pool) Get ¶
func (p *Pool) Get() (middleware.PoolConn, error)
Get is an exported alias of get() function with routine safe
func (*Pool) Transaction ¶
func (p *Pool) Transaction() (middleware.Transaction, error)
Transaction simply returns *PoolConn, because it had implemented Transaction interface
func (*Pool) UsedConnections ¶
UsedConnections returns used connection number
type PoolConfig ¶
type PoolConfig struct { Config MaxConnections int InitConnections int MaxIdleConnections int MaxIdleTime int KeepAliveInterval int }
func NewPoolConfig ¶
func NewPoolConfig(addr string, rt http.RoundTripper, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) PoolConfig
NewPoolConfig returns a new PoolConfig
func NewPoolConfigWithConfig ¶
func NewPoolConfigWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, keepAliveInterval int) PoolConfig
NewPoolConfigWithConfig returns a new PoolConfig
func (*PoolConfig) Validate ¶
func (cfg *PoolConfig) Validate() (bool, error)
Validate validates pool config
type PoolConn ¶
func Get ¶
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 ¶
func NewPoolConn(addr string, rt http.RoundTripper) (*PoolConn, error)
NewPoolConn returns a new *PoolConn
func NewPoolConnWithPool ¶
NewPoolConnWithPool returns a new *PoolConn
func (*PoolConn) Disconnect ¶
Disconnect disconnects from mysql, normally when using connection pool, there is no need to disconnect manually, consider to use Close() instead.
func (*PoolConn) Execute ¶
func (pc *PoolConn) Execute(command string, args ...interface{}) (middleware.Result, error)
Execute executes given sql and placeholders on the mysql server
func (*PoolConn) ExecuteContext ¶
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 ¶
func (pc *PoolConn) Prepare(command string) (middleware.Statement, error)
Prepare prepares a statement and returns a *Statement
func (*PoolConn) PrepareContext ¶
func (pc *PoolConn) PrepareContext(ctx context.Context, command string) (middleware.Statement, error)
PrepareContext prepares a statement with context and returns a *Statement