postgresql

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConnection

func NewConnection(cfg *config.DatabaseConfig, log logger.Logger) (types.Interface, error)

NewConnection creates and configures a PostgreSQL Connection using cfg and log. It validates cfg, builds or uses the provided DSN, sets pool options, ensures connectivity with a ping, logs success, and returns the wrapped Connection or an error.

Types

type Connection

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

Connection implements the types.Interface for PostgreSQL

func (*Connection) Begin

func (c *Connection) Begin(ctx context.Context) (types.Tx, error)

Begin starts a transaction

func (*Connection) BeginTx

func (c *Connection) BeginTx(ctx context.Context, opts *sql.TxOptions) (types.Tx, error)

BeginTx starts a transaction with options

func (*Connection) Close

func (c *Connection) Close() error

Close closes the database connection

func (*Connection) CreateMigrationTable

func (c *Connection) CreateMigrationTable(ctx context.Context) error

CreateMigrationTable creates the migration table if it doesn't exist

func (*Connection) DatabaseType

func (c *Connection) DatabaseType() string

DatabaseType returns the database type

func (*Connection) Exec

func (c *Connection) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

Exec executes a query without returning any rows

func (*Connection) Health

func (c *Connection) Health(ctx context.Context) error

Health checks database connectivity

func (*Connection) MigrationTable added in v0.19.0

func (c *Connection) MigrationTable() string

MigrationTable returns the migration table name for PostgreSQL

func (*Connection) Prepare

func (c *Connection) Prepare(ctx context.Context, query string) (types.Statement, error)

Prepare creates a prepared statement for later queries or executions

func (*Connection) Query

func (c *Connection) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)

Query executes a query that returns rows

func (*Connection) QueryRow

func (c *Connection) QueryRow(ctx context.Context, query string, args ...any) types.Row

QueryRow executes a query that returns at most one row

func (*Connection) Stats

func (c *Connection) Stats() (map[string]any, error)

Stats returns database connection statistics

type Statement added in v0.2.0

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

Statement wraps sql.Stmt to implement types.Statement

func (*Statement) Close added in v0.2.0

func (s *Statement) Close() error

Close closes the prepared statement

func (*Statement) Exec added in v0.2.0

func (s *Statement) Exec(ctx context.Context, args ...any) (sql.Result, error)

Exec executes a prepared statement with arguments

func (*Statement) Query added in v0.2.0

func (s *Statement) Query(ctx context.Context, args ...any) (*sql.Rows, error)

Query executes a prepared query with arguments

func (*Statement) QueryRow added in v0.2.0

func (s *Statement) QueryRow(ctx context.Context, args ...any) types.Row

QueryRow executes a prepared query that returns a single row

type Transaction added in v0.2.0

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

Transaction wraps sql.Tx to implement types.Tx

func (*Transaction) Commit added in v0.2.0

func (t *Transaction) Commit(_ context.Context) error

Commit commits the transaction Note: PostgreSQL's sql.Tx.Commit doesn't accept context; it's atomic and non-cancellable. The context parameter maintains interface consistency for databases that support it.

func (*Transaction) Exec added in v0.2.0

func (t *Transaction) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)

Exec executes a query without returning rows within the transaction

func (*Transaction) Prepare added in v0.2.0

func (t *Transaction) Prepare(ctx context.Context, query string) (types.Statement, error)

Prepare creates a prepared statement within the transaction

func (*Transaction) Query added in v0.2.0

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

Query executes a query within the transaction

func (*Transaction) QueryRow added in v0.2.0

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

QueryRow executes a query that returns a single row within the transaction

func (*Transaction) Rollback added in v0.2.0

func (t *Transaction) Rollback(_ context.Context) error

Rollback rolls back the transaction Note: PostgreSQL's sql.Tx.Rollback doesn't accept context; it's atomic and non-cancellable. The context parameter maintains interface consistency for databases that support it.

Jump to

Keyboard shortcuts

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