Documentation
¶
Index ¶
- func NewConnection(cfg *config.DatabaseConfig, log logger.Logger) (types.Interface, error)
- type Connection
- func (c *Connection) Begin(ctx context.Context) (types.Tx, error)
- func (c *Connection) BeginTx(ctx context.Context, opts *sql.TxOptions) (types.Tx, error)
- func (c *Connection) Close() error
- func (c *Connection) CreateMigrationTable(ctx context.Context) error
- func (c *Connection) DatabaseType() string
- func (c *Connection) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (c *Connection) Health(ctx context.Context) error
- func (c *Connection) MigrationTable() string
- func (c *Connection) Prepare(ctx context.Context, query string) (types.Statement, error)
- func (c *Connection) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (c *Connection) QueryRow(ctx context.Context, query string, args ...any) types.Row
- func (c *Connection) Stats() (map[string]any, error)
- type Statement
- type Transaction
- func (t *Transaction) Commit(_ context.Context) error
- func (t *Transaction) Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (t *Transaction) Prepare(ctx context.Context, query string) (types.Statement, error)
- func (t *Transaction) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (t *Transaction) QueryRow(ctx context.Context, query string, args ...any) types.Row
- func (t *Transaction) Rollback(_ context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewConnection ¶
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) 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) 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
type Statement ¶ added in v0.2.0
type Statement struct {
// contains filtered or unexported fields
}
Statement wraps sql.Stmt to implement types.Statement
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
Exec executes a query without returning rows within the transaction
func (*Transaction) Prepare ¶ added in v0.2.0
Prepare creates a prepared statement within the transaction
func (*Transaction) QueryRow ¶ added in v0.2.0
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.