Documentation ¶
Overview ¶
Package dbconnpool exposes a single DBConnection object with wrapped access to a single DB connection, and a ConnectionPool object to pool these DBConnections.
Index ¶
- type ConnectionPool
- type DBConnection
- func (dbc *DBConnection) ApplySetting(ctx context.Context, setting *smartconnpool.Setting) error
- func (dbc *DBConnection) ExecuteFetch(query string, maxrows int, wantfields bool) (*sqltypes.Result, error)
- func (dbc *DBConnection) ExecuteStreamFetch(query string, callback func(*sqltypes.Result) error, ...) error
- func (dbc *DBConnection) Reconnect(ctx context.Context) error
- func (dbc *DBConnection) ResetSetting(ctx context.Context) error
- func (dbc *DBConnection) Setting() *smartconnpool.Setting
- type PooledDBConnection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectionPool ¶
type ConnectionPool struct { *smartconnpool.ConnPool[*DBConnection] }
ConnectionPool re-exposes ResourcePool as a pool of PooledDBConnection objects.
func NewConnectionPool ¶
func NewConnectionPool(name string, stats *servenv.Exporter, capacity int, idleTimeout time.Duration, maxLifetime time.Duration, dnsResolutionFrequency time.Duration) *ConnectionPool
NewConnectionPool creates a new ConnectionPool. The name is used to publish stats only.
func (*ConnectionPool) Get ¶
func (cp *ConnectionPool) Get(ctx context.Context) (*PooledDBConnection, error)
func (*ConnectionPool) Open ¶
func (cp *ConnectionPool) Open(info dbconfigs.Connector)
Open must be called before starting to use the pool.
For instance: pool := dbconnpool.NewConnectionPool("name", 10, 30*time.Second) pool.Open(info) ... conn, err := pool.Get() ...
type DBConnection ¶
DBConnection re-exposes mysql.Conn with some wrapping to implement most of PoolConnection interface, except Recycle. That way it can be used by itself. (Recycle needs to know about the Pool).
func NewDBConnection ¶
NewDBConnection returns a new DBConnection based on the ConnParams and will use the provided stats to collect timing.
func (*DBConnection) ApplySetting ¶ added in v0.19.0
func (dbc *DBConnection) ApplySetting(ctx context.Context, setting *smartconnpool.Setting) error
func (*DBConnection) ExecuteFetch ¶
func (dbc *DBConnection) ExecuteFetch(query string, maxrows int, wantfields bool) (*sqltypes.Result, error)
ExecuteFetch overwrites mysql.Conn.ExecuteFetch.
func (*DBConnection) ExecuteStreamFetch ¶
func (dbc *DBConnection) ExecuteStreamFetch(query string, callback func(*sqltypes.Result) error, alloc func() *sqltypes.Result, streamBufferSize int) error
ExecuteStreamFetch overwrites mysql.Conn.ExecuteStreamFetch.
func (*DBConnection) Reconnect ¶ added in v0.19.0
func (dbc *DBConnection) Reconnect(ctx context.Context) error
Reconnect replaces the existing underlying connection with a new one, if possible. Recycle should still be called afterwards.
func (*DBConnection) ResetSetting ¶ added in v0.19.0
func (dbc *DBConnection) ResetSetting(ctx context.Context) error
func (*DBConnection) Setting ¶ added in v0.19.0
func (dbc *DBConnection) Setting() *smartconnpool.Setting
type PooledDBConnection ¶
type PooledDBConnection = smartconnpool.Pooled[*DBConnection]