Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldPointers ¶
FieldPointers returns scan destination pointers for dest (pointer to struct) ordered to match cols from rows.Columns().
Types ¶
type ConnectionManager ¶
type ConnectionManager struct {
// contains filtered or unexported fields
}
ConnectionManager wraps a *sql.DB and provides transaction management.
func NewConnectionManager ¶
func NewConnectionManager(db *sql.DB) *ConnectionManager
NewConnectionManager returns a ConnectionManager for the given db.
func (*ConnectionManager) DB ¶
func (cm *ConnectionManager) DB(ctx context.Context) Querier
DB returns the active transaction from ctx if one exists, otherwise returns the underlying *sql.DB. Pass the result into generated repository constructors.
func (*ConnectionManager) StartTransaction ¶
func (cm *ConnectionManager) StartTransaction(ctx context.Context, cb func(ctx context.Context) error) error
StartTransaction begins a transaction, calls cb with a context carrying the transaction, then commits on success or rolls back on error. If cb panics, the transaction is rolled back before the panic is repropagated, so a panicking callback never leaves the transaction open. If ctx already carries a transaction, cb is called directly without starting a new one, making nested calls safe; the panic/rollback handling above only applies at the outermost call, which is the one that actually owns tx.
type Querier ¶
type Querier interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
Querier is satisfied by both *sql.DB and *sql.Tx.