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) GetMigrationTable() string
- func (c *Connection) Health(ctx context.Context) error
- 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() 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() 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) GetMigrationTable ¶
func (c *Connection) GetMigrationTable() string
GetMigrationTable returns the migration table name for PostgreSQL
func (*Connection) Health ¶
func (c *Connection) Health(ctx context.Context) error
Health checks database connectivity
type Statement ¶ added in v0.3.1
type Statement struct {
// contains filtered or unexported fields
}
Statement wraps sql.Stmt to implement types.Statement
type Transaction ¶ added in v0.3.1
type Transaction struct {
// contains filtered or unexported fields
}
Transaction wraps sql.Tx to implement types.Tx
func (*Transaction) Commit ¶ added in v0.3.1
func (t *Transaction) Commit() error
Commit commits the transaction
func (*Transaction) Exec ¶ added in v0.3.1
Exec executes a query without returning rows within the transaction
func (*Transaction) Prepare ¶ added in v0.3.1
Prepare creates a prepared statement within the transaction
func (*Transaction) QueryRow ¶ added in v0.3.1
QueryRow executes a query that returns a single row within the transaction
func (*Transaction) Rollback ¶ added in v0.3.1
func (t *Transaction) Rollback() error
Rollback rolls back the transaction