dbconnpool

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 12 Imported by: 11

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

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 (*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

type DBConnection struct {
	*mysql.Conn
	// contains filtered or unexported fields
}

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

func NewDBConnection(ctx context.Context, info dbconfigs.Connector) (*DBConnection, error)

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]

Jump to

Keyboard shortcuts

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