Documentation
¶
Index ¶
- Constants
- func SetLSNCookie(w http.ResponseWriter, lsn LSN, cookieName string, maxAge time.Duration, ...)
- func WithLSNContext(ctx context.Context, lsnCtx *LSNContext) context.Context
- type CausalConsistencyConfig
- type CausalConsistencyLevel
- type CausalRouter
- type Conn
- type DB
- func (db *DB) Begin() (Tx, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
- func (db *DB) Close() error
- func (db *DB) Conn(ctx context.Context) (Conn, error)
- func (db *DB) DbSelector(ctx context.Context, queryType QueryType) *sql.DB
- func (db *DB) Driver() driver.Driver
- func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (db *DB) IsCausalConsistencyEnabled() bool
- func (db *DB) LoadBalancer() LoadBalancer[*sql.DB]
- func (db *DB) Ping() error
- func (db *DB) PingContext(ctx context.Context) error
- func (db *DB) Prepare(query string) (_stmt Stmt, err error)
- func (db *DB) PrepareContext(ctx context.Context, query string) (_stmt Stmt, err error)
- func (db *DB) PrimaryDBs() []*sql.DB
- func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (rows *sql.Rows, err error)
- func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (db *DB) ReadOnly() *sql.DB
- func (db *DB) ReadWrite() *sql.DB
- func (db *DB) ReplicaDBs() []*sql.DB
- func (db *DB) SetConnMaxIdleTime(d time.Duration)
- func (db *DB) SetConnMaxLifetime(d time.Duration)
- func (db *DB) SetMaxIdleConns(n int)
- func (db *DB) SetMaxOpenConns(n int)
- func (db *DB) Stats() sql.DBStats
- type DBConnection
- type DBLoadBalancer
- type DBProvider
- type DefaultQueryTypeChecker
- type HTTPMiddleware
- type LSN
- func (lsn LSN) Add(bytes uint64) LSN
- func (lsn LSN) Compare(other LSN) int
- func (lsn LSN) Equals(other LSN) bool
- func (lsn LSN) GreaterThan(other LSN) bool
- func (lsn LSN) GreaterThanOrEqual(other LSN) bool
- func (lsn LSN) IsZero() bool
- func (lsn LSN) LessThan(other LSN) bool
- func (lsn LSN) LessThanOrEqual(other LSN) bool
- func (lsn LSN) String() string
- func (lsn LSN) Subtract(other LSN) uint64
- func (lsn LSN) ToUint64() uint64
- type LSNContext
- type LoadBalancer
- type LoadBalancerPolicy
- type Option
- type OptionFunc
- func WithCausalConsistency(router QueryRouter) OptionFunc
- func WithCausalConsistencyConfig(config *CausalConsistencyConfig) OptionFunc
- func WithCausalConsistencyLevel(level CausalConsistencyLevel) OptionFunc
- func WithLSNQueryTimeout(timeout time.Duration) OptionFunc
- func WithLoadBalancer(lb LoadBalancerPolicy) OptionFunc
- func WithMasterFallback(fallback bool) OptionFunc
- func WithPrimaryDBs(primaryDBs ...*sql.DB) OptionFunc
- func WithQueryTypeChecker(checker QueryTypeChecker) OptionFunc
- func WithReplicaDBs(replicaDBs ...*sql.DB) OptionFunc
- type PGLSNChecker
- func (c *PGLSNChecker) GetCurrentWALLSN(ctx context.Context) (LSN, error)
- func (c *PGLSNChecker) GetLastReplayLSN(ctx context.Context) (LSN, error)
- func (c *PGLSNChecker) GetReplicationLag(ctx context.Context, masterLSN LSN) (uint64, error)
- func (c *PGLSNChecker) GetWALLagBytes(ctx context.Context, fromLSN, toLSN LSN) (uint64, error)
- func (c *PGLSNChecker) IsReplicaHealthy(ctx context.Context, masterLSN LSN, maxLagBytes uint64) (bool, error)
- func (c *PGLSNChecker) TestConnection(ctx context.Context) error
- type PGLSNCheckerOption
- type PGLSNCheckerRegistry
- type QueryRouter
- type QueryType
- type QueryTypeChecker
- type RandomLoadBalancer
- type RandomRouter
- type ReplicaStatus
- type RoundRobinLoadBalancer
- type RoundRobinRouter
- type SimpleRouter
- type Stmt
- type StmtLoadBalancer
- type Tx
Constants ¶
const ( // PostgreSQL function to get current WAL LSN from master PGCurrentWALLSN = "pg_current_wal_lsn()" // PostgreSQL function to get last replay LSN from replica PGLastWalReplayLSN = "pg_last_wal_replay_lsn()" // PostgreSQL function to get WAL flush LSN PGWalFlushLSN = "pg_wal_lsn_diff(%s, %s)" )
Constants for common PostgreSQL LSN functions
Variables ¶
This section is empty.
Functions ¶
func SetLSNCookie ¶
func SetLSNCookie(w http.ResponseWriter, lsn LSN, cookieName string, maxAge time.Duration, secure bool)
SetLSNCookie is a helper function to set LSN cookie after write operations Call this explicitly after write operations instead of relying on response wrapping
func WithLSNContext ¶
func WithLSNContext(ctx context.Context, lsnCtx *LSNContext) context.Context
WithLSNContext adds LSN requirements to the context
Types ¶
type CausalConsistencyConfig ¶
type CausalConsistencyConfig struct {
Enabled bool // Enable LSN-based routing
Level CausalConsistencyLevel // Consistency level required
RequireCookie bool // Require LSN cookie for read-your-writes
CookieName string // HTTP cookie name for LSN tracking
CookieMaxAge time.Duration // Maximum age for LSN cookie
FallbackToMaster bool // Fallback to master when LSN requirements can't be met
Timeout time.Duration // Timeout for LSN queries
}
CausalConsistencyConfig defines configuration for LSN-based causal consistency
func DefaultCausalConsistencyConfig ¶
func DefaultCausalConsistencyConfig() *CausalConsistencyConfig
DefaultCausalConsistencyConfig returns default configuration for causal consistency
type CausalConsistencyLevel ¶
type CausalConsistencyLevel int
CausalConsistencyLevel defines the level of causal consistency required
const ( // NoneCausalConsistency - No causal consistency requirements (default behavior) NoneCausalConsistency CausalConsistencyLevel = iota // ReadYourWrites - Ensure reads see your own writes ReadYourWrites // StrongConsistency - Ensure all reads see the latest committed writes StrongConsistency )
type CausalRouter ¶
type CausalRouter struct {
// contains filtered or unexported fields
}
CausalRouter provides LSN-aware database routing
func NewCausalRouter ¶
func NewCausalRouter(dbProvider DBProvider, config *CausalConsistencyConfig) *CausalRouter
NewCausalRouter creates a new LSN-aware router
func (*CausalRouter) RouteQuery ¶
RouteQuery routes a query to the appropriate database based on LSN requirements Optimized version: Cookie-first approach with simplified logic
func (*CausalRouter) UpdateLSNAfterWrite ¶
func (r *CausalRouter) UpdateLSNAfterWrite(ctx context.Context) (LSN, error)
UpdateLSNAfterWrite updates the LSN context after a write operation using the specific DB Optimized version: Event-driven, queries the specific DB that performed the write
type Conn ¶
type Conn interface {
Close() error
BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error)
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
PingContext(ctx context.Context) error
PrepareContext(ctx context.Context, query string) (Stmt, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
Raw(f func(driverConn interface{}) error) (err error)
}
Conn is a *sql.Conn wrapper. Its main purpose is to be able to return the internal Tx and Stmt interfaces.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func New ¶
func New(opts ...OptionFunc) *DB
New will resolve all the passed connection with configurable parameters
func (*DB) Begin ¶
Begin starts a transaction on the RW-db. The isolation level is dependent on the driver.
func (*DB) BeginTx ¶
BeginTx starts a transaction with the provided context on the RW-db.
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 (*DB) Conn ¶
Conn returns a single connection by either opening a new connection or returning an existing connection from the connection pool of the first primary db.
func (*DB) DbSelector ¶
DbSelector returns a readonly database considering query router requirements
func (*DB) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query. Exec uses the RW-database as the underlying db connection
func (*DB) ExecContext ¶
func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query. Exec uses the RW-database as the underlying db connection Optimized version: Uses single responsibility function for LSN tracking
func (*DB) IsCausalConsistencyEnabled ¶
IsCausalConsistencyEnabled returns true if causal consistency (LSN tracking) is enabled
func (*DB) LoadBalancer ¶
func (db *DB) LoadBalancer() LoadBalancer[*sql.DB]
LoadBalancer returns the database load balancer
func (*DB) Ping ¶
Ping verifies if a connection to each physical database is still alive, establishing a connection if necessary.
func (*DB) PingContext ¶
PingContext verifies if a connection to each physical database is still alive, establishing a connection if necessary.
func (*DB) Prepare ¶
Prepare creates a prepared statement for later queries or executions on each physical database, concurrently.
func (*DB) PrepareContext ¶
PrepareContext creates a prepared statement for later queries or executions on each physical database, concurrently.
The provided context is used for the preparation of the statement, not for the execution of the statement.
func (*DB) PrimaryDBs ¶
PrimaryDBs return all the active primary DB
func (*DB) Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryContext ¶
func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (rows *sql.Rows, err error)
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryRow ¶
QueryRow executes a query that is expected to return at most one row. QueryRow always return a non-nil value. Errors are deferred until Row's Scan method is called.
func (*DB) QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always return a non-nil value. Errors are deferred until Row's Scan method is called.
func (*DB) ReplicaDBs ¶
ReplicaDBs return all the active replica DB
func (*DB) SetConnMaxIdleTime ¶
SetConnMaxIdleTime sets the maximum amount of time a connection may be idle. Expired connections may be closed lazily before reuse. If d <= 0, connections are not closed due to a connection's idle time.
func (*DB) SetConnMaxLifetime ¶
SetConnMaxLifetime sets the maximum amount of time a connection may be reused. Expired connections may be closed lazily before reuse. If d <= 0, connections are reused forever.
func (*DB) SetMaxIdleConns ¶
SetMaxIdleConns sets the maximum number of connections in the idle connection pool for each underlying db connection If MaxOpenConns is greater than 0 but less than the new MaxIdleConns then the new MaxIdleConns will be reduced to match the MaxOpenConns limit If n <= 0, no idle connections are retained.
func (*DB) SetMaxOpenConns ¶
SetMaxOpenConns sets the maximum number of open connections to each physical db. If MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit. If n <= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).
type DBConnection ¶
DBConnection is the generic type for DB and Stmt operation
type DBLoadBalancer ¶
type DBLoadBalancer LoadBalancer[*sql.DB]
DBLoadBalancer is loadbalancer for physical DBs
type DBProvider ¶
type DBProvider interface {
PrimaryDBs() []*sql.DB
ReplicaDBs() []*sql.DB
LoadBalancer() LoadBalancer[*sql.DB]
}
DBProvider interface provides access to primary and replica databases
type DefaultQueryTypeChecker ¶
type DefaultQueryTypeChecker struct {
// contains filtered or unexported fields
}
DefaultQueryTypeChecker uses regex patterns to detect write queries by identifying SQL DML statements.
func NewDefaultQueryTypeChecker ¶
func NewDefaultQueryTypeChecker() *DefaultQueryTypeChecker
NewDefaultQueryTypeChecker creates a new DefaultQueryTypeChecker with compiled regex
func (*DefaultQueryTypeChecker) Check ¶
func (c *DefaultQueryTypeChecker) Check(query string) QueryType
type HTTPMiddleware ¶
type HTTPMiddleware struct {
// contains filtered or unexported fields
}
HTTPMiddleware provides HTTP middleware for LSN-aware database routing Optimized version with automatic cookie setting via response wrapper
func NewHTTPMiddleware ¶
func NewHTTPMiddleware(router QueryRouter, cookieName string, maxAge time.Duration, useSecureCookie bool) *HTTPMiddleware
NewHTTPMiddleware creates new HTTP middleware for LSN tracking maxAge determine your threshold of avg time sync between master and replica
func (*HTTPMiddleware) Middleware ¶
func (m *HTTPMiddleware) Middleware(next http.Handler) http.Handler
Middleware returns an HTTP middleware function Enhanced version with automatic cookie setting via response wrapper
type LSN ¶
type LSN struct {
Upper uint32 // Higher 32 bits (log file ID)
Lower uint32 // Lower 32 bits (byte offset)
}
LSN represents a PostgreSQL Log Sequence Number in the format X/Y where X is the log file ID and Y is the byte offset within the file
func GetLSNFromCookie ¶
GetLSNFromCookie extracts LSN from HTTP request cookies
func LSNFromUint64 ¶
LSNFromUint64 creates an LSN from a 64-bit integer representation
func ParseLSN ¶
ParseLSN parses a PostgreSQL LSN string in the format "X/Y" For example: "0/3000060", "1/A0B1C2"
func (LSN) Compare ¶
Compare compares this LSN with another LSN Returns:
-1 if this LSN < other LSN 0 if this LSN == other LSN 1 if this LSN > other LSN
func (LSN) GreaterThan ¶
GreaterThan returns true if this LSN is greater than the other LSN
func (LSN) GreaterThanOrEqual ¶
GreaterThanOrEqual returns true if this LSN is greater than or equal to the other LSN
func (LSN) LessThanOrEqual ¶
LessThanOrEqual returns true if this LSN is less than or equal to the other LSN
type LSNContext ¶
type LSNContext struct {
RequiredLSN LSN
Level CausalConsistencyLevel
ForceMaster bool
HasWriteOperation bool // Track if this request performed a write operation
// contains filtered or unexported fields
}
LSNContext holds LSN-related context information
func GetLSNContext ¶
func GetLSNContext(ctx context.Context) *LSNContext
GetLSNContext retrieves LSN context from the request context
type LoadBalancer ¶
type LoadBalancer[T DBConnection] interface { Resolve([]T) T Name() LoadBalancerPolicy // contains filtered or unexported methods }
LoadBalancer define the load balancer contract
type LoadBalancerPolicy ¶
type LoadBalancerPolicy string
LoadBalancerPolicy define the loadbalancer policy data type
const ( RoundRobinLB LoadBalancerPolicy = "ROUND_ROBIN" RandomLB LoadBalancerPolicy = "RANDOM" )
Supported Loadbalancer policy
type Option ¶
type Option struct {
PrimaryDBs []*sql.DB
ReplicaDBs []*sql.DB
StmtLB StmtLoadBalancer
DBLB DBLoadBalancer
QueryTypeChecker QueryTypeChecker
QueryRouter QueryRouter
CCConfig *CausalConsistencyConfig
}
Option define the option property
type OptionFunc ¶
type OptionFunc func(opt *Option)
OptionFunc used for option chaining
func WithCausalConsistency ¶
func WithCausalConsistency(router QueryRouter) OptionFunc
WithCausalConsistency enables and configures LSN-based causal consistency
func WithCausalConsistencyConfig ¶
func WithCausalConsistencyConfig(config *CausalConsistencyConfig) OptionFunc
WithCausalConsistencyConfig sets the complete causal consistency configuration
func WithCausalConsistencyLevel ¶
func WithCausalConsistencyLevel(level CausalConsistencyLevel) OptionFunc
WithCausalConsistencyLevel sets a specific causal consistency level
func WithLSNQueryTimeout ¶
func WithLSNQueryTimeout(timeout time.Duration) OptionFunc
WithLSNQueryTimeout sets the timeout for LSN queries
func WithLoadBalancer ¶
func WithLoadBalancer(lb LoadBalancerPolicy) OptionFunc
WithLoadBalancer configure the loadbalancer for the resolver
func WithMasterFallback ¶
func WithMasterFallback(fallback bool) OptionFunc
WithMasterFallback configures whether to fallback to master when LSN requirements can't be met
func WithPrimaryDBs ¶
func WithPrimaryDBs(primaryDBs ...*sql.DB) OptionFunc
WithPrimaryDBs add primaryDBs to the resolver
func WithQueryTypeChecker ¶
func WithQueryTypeChecker(checker QueryTypeChecker) OptionFunc
WithQueryTypeChecker sets the query type checker instance.
func WithReplicaDBs ¶
func WithReplicaDBs(replicaDBs ...*sql.DB) OptionFunc
WithReplicaDBs add replica DBs to the resolver
type PGLSNChecker ¶
type PGLSNChecker struct {
// contains filtered or unexported fields
}
PGLSNChecker handles PostgreSQL-specific LSN queries and operations
func (*PGLSNChecker) GetCurrentWALLSN ¶
func (c *PGLSNChecker) GetCurrentWALLSN(ctx context.Context) (LSN, error)
GetCurrentWALLSN queries the current WAL LSN from the master database
func (*PGLSNChecker) GetLastReplayLSN ¶
func (c *PGLSNChecker) GetLastReplayLSN(ctx context.Context) (LSN, error)
GetLastReplayLSN queries the last replay LSN from a replica database
func (*PGLSNChecker) GetReplicationLag ¶
GetReplicationLag calculates the replication lag in bytes between master and replica
func (*PGLSNChecker) GetWALLagBytes ¶
GetWALLagBytes queries the WAL lag in bytes between two LSNs using pg_wal_lsn_diff
func (*PGLSNChecker) IsReplicaHealthy ¶
func (c *PGLSNChecker) IsReplicaHealthy(ctx context.Context, masterLSN LSN, maxLagBytes uint64) (bool, error)
IsReplicaHealthy checks if a replica is healthy and within acceptable lag
func (*PGLSNChecker) TestConnection ¶
func (c *PGLSNChecker) TestConnection(ctx context.Context) error
TestConnection performs a basic connection test
type PGLSNCheckerOption ¶
type PGLSNCheckerOption func(*PGLSNChecker)
PGLSNCheckerOption configures the PGLSNChecker
func WithQueryTimeout ¶
func WithQueryTimeout(timeout time.Duration) PGLSNCheckerOption
WithQueryTimeout sets the timeout for LSN queries
type PGLSNCheckerRegistry ¶
type PGLSNCheckerRegistry struct {
// contains filtered or unexported fields
}
PGLSNCheckerRegistry manages singleton instances per DB connection
type QueryRouter ¶
type QueryRouter interface {
// RouteQuery routes a query to the appropriate database based on query type and context
RouteQuery(ctx context.Context, queryType QueryType) (*sql.DB, error)
// UpdateLSNAfterWrite updates LSN tracking after a write operation (optional)
// Implementations can return zero LSN and nil error if LSN tracking is not supported
UpdateLSNAfterWrite(ctx context.Context) (LSN, error)
}
QueryRouter interface defines the contract for query routing strategies This follows the Open-Closed Principle, allowing different routing implementations
type QueryTypeChecker ¶
QueryTypeChecker is used to try to detect the query type, like for detecting RETURNING clauses in INSERT/UPDATE clauses.
type RandomLoadBalancer ¶
type RandomLoadBalancer[T DBConnection] struct { // contains filtered or unexported fields }
RandomLoadBalancer represent for Random LB policy
func (RandomLoadBalancer[T]) Name ¶
func (lb RandomLoadBalancer[T]) Name() LoadBalancerPolicy
RandomLoadBalancer return the LB policy name
func (RandomLoadBalancer[T]) Resolve ¶
func (lb RandomLoadBalancer[T]) Resolve(dbs []T) T
Resolve return the resolved option for Random LB. Marked with go:nosplit to prevent preemption.
type RandomRouter ¶
type RandomRouter struct {
// contains filtered or unexported fields
}
RandomRouter implements QueryRouter with random database selection This demonstrates how the QueryRouter interface enables the Open-Closed Principle: We can add new routing strategies without modifying existing code.
func NewRandomRouter ¶
func NewRandomRouter(dbProvider DBProvider) *RandomRouter
NewRandomRouter creates a new router that randomly selects databases
func (*RandomRouter) RouteQuery ¶
RouteQuery routes queries to randomly selected databases
func (*RandomRouter) UpdateLSNAfterWrite ¶
func (r *RandomRouter) UpdateLSNAfterWrite(_ context.Context) (LSN, error)
UpdateLSNAfterWrite is a no-op for RandomRouter since it doesn't track LSN
type ReplicaStatus ¶
type ReplicaStatus struct {
IsHealthy bool
LastCheck time.Time
ErrorCount int
LastError error
LastLSN *LSN
LagBytes int64
}
ReplicaStatus represents the health and replication status of a replica
type RoundRobinLoadBalancer ¶
type RoundRobinLoadBalancer[T DBConnection] struct { // contains filtered or unexported fields }
RoundRobinLoadBalancer represent for RoundRobin LB policy
func (RoundRobinLoadBalancer[T]) Name ¶
func (lb RoundRobinLoadBalancer[T]) Name() LoadBalancerPolicy
Name return the LB policy name
func (*RoundRobinLoadBalancer[T]) Resolve ¶
func (lb *RoundRobinLoadBalancer[T]) Resolve(dbs []T) T
Resolve return the resolved option for RoundRobin LB
type RoundRobinRouter ¶
type RoundRobinRouter struct {
// contains filtered or unexported fields
}
RoundRobinRouter implements QueryRouter with round-robin database selection
func NewRoundRobinRouter ¶
func NewRoundRobinRouter(dbProvider DBProvider) *RoundRobinRouter
NewRoundRobinRouter creates a new router that uses round-robin selection
func (*RoundRobinRouter) RouteQuery ¶
RouteQuery routes queries using round-robin selection
func (*RoundRobinRouter) UpdateLSNAfterWrite ¶
func (r *RoundRobinRouter) UpdateLSNAfterWrite(_ context.Context) (LSN, error)
UpdateLSNAfterWrite is a no-op for RoundRobinRouter since it doesn't track LSN
type SimpleRouter ¶
type SimpleRouter struct {
// contains filtered or unexported fields
}
SimpleRouter implements QueryRouter with basic read/write routing without LSN tracking
func NewSimpleRouter ¶
func NewSimpleRouter(dbProvider DBProvider) *SimpleRouter
NewSimpleRouter creates a new simple router without LSN tracking
func (*SimpleRouter) RouteQuery ¶
RouteQuery implements basic read/write routing
func (*SimpleRouter) UpdateLSNAfterWrite ¶
func (r *SimpleRouter) UpdateLSNAfterWrite(_ context.Context) (LSN, error)
UpdateLSNAfterWrite is a no-op for SimpleRouter since it doesn't track LSN
type Stmt ¶
type Stmt interface {
Close() error
Exec(...interface{}) (sql.Result, error)
ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error)
Query(...interface{}) (*sql.Rows, error)
QueryContext(ctx context.Context, args ...interface{}) (*sql.Rows, error)
QueryRow(args ...interface{}) *sql.Row
QueryRowContext(ctx context.Context, args ...interface{}) *sql.Row
}
Stmt is an aggregate prepared statement. It holds a prepared statement for each underlying physical db.
type StmtLoadBalancer ¶
type StmtLoadBalancer LoadBalancer[*sql.Stmt]
StmtLoadBalancer is loadbalancer for query prepared statements
type Tx ¶
type Tx interface {
Commit() error
Rollback() error
Exec(query string, args ...interface{}) (sql.Result, error)
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
Prepare(query string) (Stmt, error)
PrepareContext(ctx context.Context, query string) (Stmt, error)
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
Stmt(stmt Stmt) Stmt
StmtContext(ctx context.Context, stmt Stmt) Stmt
}
Tx is a *sql.Tx wrapper. Its main purpose is to be able to return the internal Stmt interface.


