mysql

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: Apache-2.0 Imports: 9 Imported by: 7

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	DefaultMaxConnections     = 20
	DefaultInitConnections    = 5
	DefaultMaxIdleConnections = 10
	DefaultMaxIdleTime        = 600 // Seconds
	DefaultKeepAliveInterval  = 1   // Seconds
	DefaultKeepAliveChunkSize = 5
	DefaultSleepTime          = 1 // Seconds
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.2.0

type Config struct {
	Addr   string
	DBName string
	DBUser string
	DBPass string
}

func NewMySQLConfig added in v0.2.0

func NewMySQLConfig(addr string, dbName string, dbUser string, dbPass string) Config

type Conn

type Conn struct {
	Config
	client.Conn
}

func NewMySQLConn

func NewMySQLConn(addr string, dbName string, dbUser string, dbPass string) (*Conn, error)

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 *Conn) CheckInstanceStatus() bool

func (*Conn) GetReplicationRole

func (conn *Conn) GetReplicationRole() (role string, err error)

func (*Conn) GetReplicationSlaveList

func (conn *Conn) GetReplicationSlaveList() (slaveList []string, err error)

func (*Conn) GetReplicationSlavesStatus

func (conn *Conn) GetReplicationSlavesStatus() (result *mysql.Result, err error)

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

func NewMySQLPoolWithDefault(addr, dbName, dbUser, dbPass string) (*Pool, error)

NewMySQLPoolWithDefault returns a new *Pool with default configuration

func NewMySQLPoolWithPoolConfig added in v0.2.0

func NewMySQLPoolWithPoolConfig(config PoolConfig) (*Pool, error)

NewMySQLPoolWithDefault returns a new *Pool with a PoolConfig object

func (*Pool) Close added in v0.2.0

func (p *Pool) Close() error

Close releases each connection in the pool

func (*Pool) Get added in v0.2.0

func (p *Pool) Get() (*PoolConn, error)

Get is an exported alias of get() function with routine safe

func (*Pool) GetUsedConnections added in v0.2.0

func (p *Pool) GetUsedConnections() int

GetUsedConnections returns used connection number

func (*Pool) IsClosed added in v0.2.0

func (p *Pool) IsClosed() bool

IsClosed returns if pool had been closed

func (*Pool) MaintainFreeChan added in v0.2.0

func (p *Pool) MaintainFreeChan()

MaintainFreeChan maintains free connection channel, if there are insufficient connection in the free connection channel, it will add some connections, otherwise it will release some. for saving disk purpose, if there are errors when maintaining free channel, it will log with debug level

func (*Pool) Release added in v0.2.0

func (p *Pool) Release(num int) error

Release is an exported alias of release() function

func (*Pool) Supply added in v0.2.0

func (p *Pool) Supply(num int) error

Supply is an exported alias of supply() function with routine safe

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

type PoolConn struct {
	Conn
	Pool *Pool
}

func NewPoolConn added in v0.2.0

func NewPoolConn(addr, dbName, dbUser, dbPass string) (*PoolConn, error)

NewPoolConn returns a new *PoolConn

func NewPoolConnWithPool added in v0.2.0

func NewPoolConnWithPool(addr, dbName, dbUser, dbPass string, pool *Pool) (*PoolConn, error)

NewPoolConnWithPool returns a new *PoolConn

func (*PoolConn) Close added in v0.2.0

func (pc *PoolConn) Close() error

Close returns connection backup to the pool

func (*PoolConn) DisConnect added in v0.2.0

func (pc *PoolConn) DisConnect() error

DisConnect disconnects from mysql, normally when using connection pool, there is no need to disconnect manually, consider to use Close() instead.

func (*PoolConn) IsValid added in v0.2.0

func (pc *PoolConn) IsValid() bool

IsValid validates if connection is valid

Jump to

Keyboard shortcuts

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