sqladapter

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
const (
	// DefaultName is the default adapter registration name.
	DefaultName = "database/sql"
)

Variables

This section is empty.

Functions

func CurrentTx

func CurrentTx(work uow.UnitOfWork) (*sql.Tx, bool)

CurrentTx returns the active *sql.Tx when the UnitOfWork is transactional.

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 New

func New(name string) *Adapter

New returns a database/sql adapter. Empty names default to "database/sql".

func (*Adapter) Begin

func (a *Adapter) Begin(ctx context.Context, client any, opts uow.BeginOptions) (uow.Tx, error)

Begin implements uow.Adapter.

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.

func (*Adapter) Commit

func (a *Adapter) Commit(ctx context.Context, tx uow.Tx) error

Commit implements uow.Adapter.

func (*Adapter) Name

func (a *Adapter) Name() string

Name implements uow.Adapter.

func (*Adapter) Rollback

func (a *Adapter) Rollback(ctx context.Context, tx uow.Tx) error

Rollback implements uow.Adapter.

func (*Adapter) Unwrap

func (a *Adapter) Unwrap(tx uow.Tx) any

Unwrap 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.

type Tx

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

Tx wraps *sql.Tx for the uow.Adapter contract.

func (*Tx) Depth

func (t *Tx) Depth() int

Depth implements uow.Tx.

func (*Tx) Name

func (t *Tx) Name() string

Name implements uow.Tx.

func (*Tx) Raw

func (t *Tx) Raw() any

Raw implements uow.Tx.

Jump to

Keyboard shortcuts

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