Documentation ¶
Index ¶
- type Config
- type Connection
- func (c *Connection) BeginTX(ctx context.Context, options *alphasql.TXOptions) (alphasql.TX, error)
- func (c *Connection) Exec(ctx context.Context, query string, args ...any) (alphasql.Result, error)
- func (c *Connection) Ping(ctx context.Context) error
- func (c *Connection) Prepare(ctx context.Context, query string) (alphasql.Statement, error)
- func (c *Connection) Query(ctx context.Context, query string, args ...any) (alphasql.Rows, error)
- func (c *Connection) QueryRow(ctx context.Context, query string, args ...any) alphasql.Row
- type Pool
- func (p *Pool) Acquire(ctx context.Context) (*Connection, error)
- func (p *Pool) BeginTX(ctx context.Context, options *alphasql.TXOptions) (alphasql.TX, error)
- func (p *Pool) Close(ctx context.Context)
- func (p *Pool) Exec(ctx context.Context, query string, args ...any) (alphasql.Result, error)
- func (p *Pool) Ping(ctx context.Context) error
- func (p *Pool) Prepare(ctx context.Context, query string) (alphasql.Statement, error)
- func (p *Pool) Query(ctx context.Context, query string, args ...any) (alphasql.Rows, error)
- func (p *Pool) QueryRow(ctx context.Context, query string, args ...any) alphasql.Row
- func (p *Pool) Release(ctx context.Context, c *Connection)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { ConnectionConfig *alphasql.ConnectionConfig // BeforeConnect is called before a new Connection is made. It is passed a copy of the underlying // alphasql.ConnectionConfig and will not impact any existing open connections. BeforeConnect func(context.Context, *alphasql.ConnectionConfig) error // AfterConnect is called after a Connection is established, but before it is added to the pool. AfterConnect func(context.Context, *alphasql.Connection) error // BeforeAcquire is called before a Connection is acquired from the pool. It must return true to allow the // acquisition or false to indicate that the Connection should be destroyed and a different Connection should be // acquired. BeforeAcquire func(context.Context, *Connection) bool // AfterRelease is called after a Connection is released, but before it is returned to the pool. It must return true to // return the Connection to the pool or false to destroy the Connection. AfterRelease func(context.Context, *Connection) bool // BeforeClose is called right before a Connection is closed and removed from the pool. BeforeClose func(context.Context, *alphasql.Connection) // MaxConnectionLifetime is the duration since creation after which a Connection will be automatically closed. MaxConnectionLifetime time.Duration // MaxConnectionLifetimeJitter is the duration after MaxConnectionLifetime to randomly decide to close a Connection. // This helps prevent all connections from being closed at the exact same time, starving the pool. MaxConnectionLifetimeJitter time.Duration // MaxConnectionIdleTime is the duration after which an idle Connection will be automatically closed by the health check. MaxConnectionIdleTime time.Duration // MaxConnections is the maximum size of the pool. The default is the greatest of 4 or runtime.NumCPU(). MaxConnections int32 // MinConnections is the minimum size of the pool. After Connection closes, the pool might dip below MinConnections. // A low number of MinConnections might mean the pool is empty after MaxConnectionLifetime until the health check // has a chance to create new connections. MinConnections int32 // HealthCheckPeriod is the duration between checks of the health of idle connections. HealthCheckPeriod time.Duration }
Config is the configuration required for creating a pool.
func (*Config) ValidateAndDefault ¶
ValidateAndDefault is used to validate and set the defaults for the mandatory parameters not passed.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is used for managing the instance of a Connection in the pool.
func (*Connection) BeginTX ¶
BeginTX starts a transaction.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the `alphasql` package will roll back the transaction. [TX.Commit] will return an error if the context provided to BeginTX is canceled.
The provided [TXOptions] is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*Connection) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Connection) Ping ¶
func (c *Connection) Ping(ctx context.Context) error
Ping verifies a Connection to the database is still alive, establishing a Connection if necessary.
func (*Connection) Prepare ¶
Prepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's alphasql.Statement.Close method when the statement is no longer needed.
func (*Connection) Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Connection) QueryRow ¶
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until alphasql.Row's Scan method is called. If the query selects no rows, the alphasql.Row.Scan will return alphasql.ErrNoRows. Otherwise, alphasql.Row.Scan scans the first selected row and discards the rest.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is used to manage the set of connections, also being able to reuse it.
func (*Pool) Acquire ¶
func (p *Pool) Acquire(ctx context.Context) (*Connection, error)
Acquire is used to get a (*Connection) from the pool.
func (*Pool) BeginTX ¶
BeginTX starts a transaction.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the `alphasql` package will roll back the transaction. alphasql.TX.Commit will return an error if the context provided to BeginTX is canceled.
The provided alphasql.TXOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*Pool) Close ¶
Close closes all connections in the pool and rejects future Acquire calls. Blocks until all connections are returned.
func (*Pool) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Pool) Ping ¶
Ping verifies a Connection to the database is still alive, establishing a Connection if necessary.
func (*Pool) Prepare ¶
Prepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's alphasql.Statement.Close method when the statement is no longer needed.
func (*Pool) Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Pool) QueryRow ¶
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until alphasql.Row's Scan method is called. If the query selects no rows, the alphasql.Row.Scan will return alphasql.ErrNoRows. Otherwise, alphasql.Row.Scan scans the first selected row and discards the rest.