Documentation
¶
Overview ¶
Package adapters provide database adapter implementations for the PostgreSQL event store.
This package implements the adapter pattern to support multiple PostgreSQL database libraries: pgx.Pool, sql.DB, and sqlx.DB. All adapters provide equivalent functionality through a common DBAdapter interface, allowing the event store to work seamlessly with any supported database connection type.
The adapters handle the specifics of each database library while presenting a unified interface for query execution and result handling.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBAdapter ¶
type DBAdapter interface { Query(ctx context.Context, query string) (DBRows, error) QueryRow(ctx context.Context, query string) DBRow Exec(ctx context.Context, query string) (DBResult, error) }
DBAdapter defines the interface for database operations needed by the event store.
type PGXAdapter ¶
type PGXAdapter struct {
// contains filtered or unexported fields
}
PGXAdapter implements DBAdapter for pgxpool.Pool.
func NewPGXAdapter ¶
func NewPGXAdapter(pool *pgxpool.Pool) *PGXAdapter
NewPGXAdapter creates a new PGX adapter with a primary pool.
func NewPGXAdapterWithReplica ¶
func NewPGXAdapterWithReplica(pool *pgxpool.Pool, replica *pgxpool.Pool) *PGXAdapter
NewPGXAdapterWithReplica creates a new PGX adapter with a primary pool and a replica pool.
func (*PGXAdapter) Query ¶
Query executes a query using consistency-aware routing. By default, uses primary pool for strong consistency (safe for event sourcing). Uses replica pool only when context explicitly requests eventual consistency.
func (*PGXAdapter) QueryRow ¶
func (p *PGXAdapter) QueryRow(ctx context.Context, query string) DBRow
QueryRow executes a query that returns a single row using consistency-aware routing. By default, uses primary pool for strong consistency (safe for event sourcing). Uses replica pool only when context explicitly requests eventual consistency.
type SQLAdapter ¶
type SQLAdapter struct {
// contains filtered or unexported fields
}
SQLAdapter implements DBAdapter for sql.DB.
func NewSQLAdapter ¶
func NewSQLAdapter(db *sql.DB) *SQLAdapter
NewSQLAdapter creates a new SQL adapter with a primary db connection.
func NewSQLAdapterWithReplica ¶
func NewSQLAdapterWithReplica(db *sql.DB, replicaDB *sql.DB) *SQLAdapter
NewSQLAdapterWithReplica creates a new SQL adapter with a primary db connection and a replica db connection.
func (*SQLAdapter) Query ¶
Query executes a query using consistency-aware routing. By default, uses primary pool for strong consistency (safe for event sourcing). Uses replica pool only when context explicitly requests eventual consistency.
func (*SQLAdapter) QueryRow ¶
func (s *SQLAdapter) QueryRow(ctx context.Context, query string) DBRow
QueryRow executes a query that returns a single row using consistency-aware routing. By default, uses primary pool for strong consistency (safe for event sourcing). Uses replica pool only when context explicitly requests eventual consistency.
type SQLXAdapter ¶
type SQLXAdapter struct {
// contains filtered or unexported fields
}
SQLXAdapter implements DBAdapter for sqlx.DB.
func NewSQLXAdapter ¶
func NewSQLXAdapter(db *sqlx.DB) *SQLXAdapter
NewSQLXAdapter creates a new SQLX adapter with a primary db connection.
func NewSQLXAdapterWithReplica ¶
func NewSQLXAdapterWithReplica(db *sqlx.DB, replicaDB *sqlx.DB) *SQLXAdapter
NewSQLXAdapterWithReplica creates a new SQLX adapter with a primary db connection and a replica db connection.
func (*SQLXAdapter) Query ¶
Query executes a query using consistency-aware routing. By default, uses primary pool for strong consistency (safe for event sourcing). Uses replica pool only when context explicitly requests eventual consistency.
func (*SQLXAdapter) QueryRow ¶
func (s *SQLXAdapter) QueryRow(ctx context.Context, query string) DBRow
QueryRow executes a query that returns a single row using consistency-aware routing. By default, uses primary pool for strong consistency (safe for event sourcing). Uses replica pool only when context explicitly requests eventual consistency.