postgres

package
v0.1.0-20260312-120723... Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PgxExecResult

type PgxExecResult struct {
	// contains filtered or unexported fields
}

PgxExecResult adapts pgconn.CommandTag to database.ExecResult interface.

func (*PgxExecResult) LastInsertId

func (r *PgxExecResult) LastInsertId() int64

LastInsertId returns 0 as PostgreSQL does not support retrieving the last inserted ID.

func (*PgxExecResult) RowsAffected

func (r *PgxExecResult) RowsAffected() int64

RowsAffected returns the number of rows affected from the underlying pgconn.CommandTag.

type PgxRowAdapter

type PgxRowAdapter struct {
	// contains filtered or unexported fields
}

PgxRowAdapter adapts pgx.Row to database.Row interface.

func (*PgxRowAdapter) Scan

func (a *PgxRowAdapter) Scan(dest ...any) error

Scan calls Scan on the underlying pgx.Row.

type PgxRowsAdapter

type PgxRowsAdapter struct {
	// contains filtered or unexported fields
}

PgxRowsAdapter adapts pgx.Rows to database.Rows interface.

func (*PgxRowsAdapter) Close

func (a *PgxRowsAdapter) Close() error

Close closes the underlying pgx.Rows.

func (*PgxRowsAdapter) Columns

func (a *PgxRowsAdapter) Columns() ([]string, error)

func (*PgxRowsAdapter) Err

func (a *PgxRowsAdapter) Err() error

Err returns the error from the underlying pgx.Rows.

func (*PgxRowsAdapter) Next

func (a *PgxRowsAdapter) Next() bool

Next calls Next on the underlying pgx.Rows.

func (*PgxRowsAdapter) Scan

func (a *PgxRowsAdapter) Scan(dest ...any) error

Scan calls Scan on the underlying pgx.Rows.

type PostgresDB

type PostgresDB[T any] struct {
	// contains filtered or unexported fields
}

PostgresDB provides a generic PostgreSQL database adapter with connection pooling. It supports query factories, health monitoring, and pgx connection management.

func NewPostgresFactory

func NewPostgresFactory[T any](options *database.PostgresDBOptions, factory database.GenericQueriesFactory[T]) *PostgresDB[T]

NewPostgresFactory creates a new PostgresDB instance with the specified options and query factory. The factory function is used to create query objects for database operations.

func (*PostgresDB[T]) BeginTransaction

func (db *PostgresDB[T]) BeginTransaction(ctx context.Context) (database.Transaction, error)

BeginTransaction starts a new database transaction.

func (*PostgresDB[T]) Close

func (db *PostgresDB[T]) Close() error

Close closes the connection pool.

func (*PostgresDB[T]) Connect

func (p *PostgresDB[T]) Connect(ctx context.Context) error

Connect establishes a PostgreSQL connection pool and initializes query providers. It configures connection pooling, performs health checks, and sets up monitoring.

func (*PostgresDB[T]) Exec

func (db *PostgresDB[T]) Exec(ctx context.Context, query string, args ...any) (database.ExecResult, error)

Exec executes a SQL statement that does not return rows.

func (*PostgresDB[T]) FetchCheckAliveInterval

func (db *PostgresDB[T]) FetchCheckAliveInterval() time.Duration

FetchCheckAliveInterval returns the interval for checking the health of the database connection.

func (*PostgresDB[T]) FetchStopChannel

func (db *PostgresDB[T]) FetchStopChannel() <-chan struct{}

FetchStopChannel returns a channel that is closed when the database connection is closed.

func (*PostgresDB[T]) GetLogger

func (p *PostgresDB[T]) GetLogger() *log.Log

GetLogger returns the configured logger instance for the PostgreSQL adapter. It provides access to the logger for debugging and monitoring purposes.

func (*PostgresDB[T]) GetProviderDB

func (p *PostgresDB[T]) GetProviderDB() any

GetProviderDB returns the database query provider instance. It supports different query providers and returns the appropriate type.

func (*PostgresDB[T]) IsDebugQuery

func (db *PostgresDB[T]) IsDebugQuery(query string, args ...any)

IsDebugQuery logs the query and arguments if debug mode is enabled.

func (*PostgresDB[T]) IsQueryProviderAvailable

func (p *PostgresDB[T]) IsQueryProviderAvailable() bool

IsQueryProviderAvailable checks if a query provider is configured. It returns true if a query provider is set in the options.

func (*PostgresDB[T]) Ping

func (p *PostgresDB[T]) Ping() error

Ping tests the PostgreSQL connection and verifies database existence. It performs both connection pool health check and database availability check.

func (*PostgresDB[T]) Query

func (db *PostgresDB[T]) Query(ctx context.Context, query string, args ...any) (database.Rows, error)

Query executes a SQL query and returns a Rows object.

func (*PostgresDB[T]) QueryRow

func (db *PostgresDB[T]) QueryRow(ctx context.Context, query string, args ...any) database.Row

QueryRow executes a SQL query that is expected to return at most one row.

func (*PostgresDB[T]) RowsToSlice

func (db *PostgresDB[T]) RowsToSlice(rows database.Rows) ([][]string, error)

RowsToSlice converts rows to a [][]string representation.

func (*PostgresDB[T]) StartMonitor

func (p *PostgresDB[T]) StartMonitor()

StartMonitor begins database health monitoring in a separate goroutine. It stops any existing monitor before starting a new one to prevent duplicates.

func (*PostgresDB[T]) StartMonitorEnabled

func (db *PostgresDB[T]) StartMonitorEnabled() bool

StartMonitorEnabled returns whether health monitoring should start automatically.

func (*PostgresDB[T]) Stat

func (db *PostgresDB[T]) Stat() *pgxpool.Stat

Stat returns statistics about the connection pool.

func (*PostgresDB[T]) StopMonitor

func (p *PostgresDB[T]) StopMonitor()

StopMonitor gracefully stops the database health monitoring goroutine. It cancels the context and closes channels to ensure clean shutdown.

type PostgresTransaction

type PostgresTransaction struct {
	// contains filtered or unexported fields
}

PostgresTransaction represents a database transaction within the PostgreSQL context.

func (*PostgresTransaction) Commit

func (t *PostgresTransaction) Commit(ctx context.Context) error

Commit commits the current transaction.

func (*PostgresTransaction) Exec

func (t *PostgresTransaction) Exec(ctx context.Context, query string, args ...any) (database.ExecResult, error)

Exec executes a SQL statement that does not return rows within the current transaction.

func (*PostgresTransaction) GetTx

func (db *PostgresTransaction) GetTx() any

GetTx returns the transaction object.

func (*PostgresTransaction) IsDebugQuery

func (db *PostgresTransaction) IsDebugQuery(query string, args ...any)

IsDebugQuery logs the query and arguments if debug mode is enabled.

func (*PostgresTransaction) Query

func (t *PostgresTransaction) Query(ctx context.Context, query string, args ...any) (database.Rows, error)

Query executes a SQL query within the current transaction.

func (*PostgresTransaction) QueryRow

func (t *PostgresTransaction) QueryRow(ctx context.Context, query string, args ...any) database.Row

QueryRow executes a SQL query that is expected to return at most one row within the current transaction.

func (*PostgresTransaction) Rollback

func (t *PostgresTransaction) Rollback(ctx context.Context) error

Rollback rolls back the current transaction.

func (*PostgresTransaction) RowsToSlice

func (t *PostgresTransaction) RowsToSlice(rows database.Rows) ([][]string, error)

RowsToSlice converts rows to a [][]string representation.

Jump to

Keyboard shortcuts

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