Documentation
¶
Overview ¶
Package sqladapter provides a first-party uow adapter for database/sql.
The adapter keeps the core uow package dependency-free while giving users a concrete path for stdlib SQL integrations. Root transactions use *sql.DB as the registered client and expose *sql.Tx as the transactional current handle.
Index ¶
- Constants
- func CurrentTx(work uow.UnitOfWork) (*sql.Tx, bool)
- type Adapter
- func (a *Adapter) Begin(ctx context.Context, client any, opts uow.BeginOptions) (uow.Tx, error)
- func (a *Adapter) BeginNested(ctx context.Context, parent uow.Tx, opts uow.NestedOptions) (uow.Tx, error)
- func (a *Adapter) Capabilities() uow.Capabilities
- func (a *Adapter) Commit(ctx context.Context, tx uow.Tx) error
- func (a *Adapter) Name() string
- func (a *Adapter) Rollback(ctx context.Context, tx uow.Tx) error
- func (a *Adapter) Unwrap(tx uow.Tx) any
- type Handle
- type Tx
Constants ¶
const (
// DefaultName is the default adapter registration name.
DefaultName = "database/sql"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter implements uow.Adapter for database/sql.
The zero value is usable and registers as "database/sql".
func (*Adapter) BeginNested ¶
func (a *Adapter) BeginNested(ctx context.Context, parent uow.Tx, opts uow.NestedOptions) (uow.Tx, error)
BeginNested implements uow.Adapter.
func (*Adapter) Capabilities ¶
func (a *Adapter) Capabilities() uow.Capabilities
Capabilities implements uow.Adapter.
type Handle ¶
type Handle interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
Handle is the common query surface implemented by both *sql.DB and *sql.Tx.
func Current ¶
func Current(work uow.UnitOfWork) (Handle, error)
Current returns the current database/sql handle from a UnitOfWork.
The returned value is *sql.Tx inside a transaction and *sql.DB otherwise.
func MustCurrent ¶
func MustCurrent(work uow.UnitOfWork) Handle
MustCurrent returns the current handle or panics.