bundriver

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package bundriver provides a goncordia driver that accepts *bun.Tx transactions.

It is a thin adapter over driver/stdlib: bun.DB embeds *sql.DB and bun.Tx embeds *sql.Tx, so no reflection or internal field access is needed.

Usage:

sqlDB, _ := sql.Open("pgx", os.Getenv("DATABASE_URL"))
db := bun.NewDB(sqlDB, pgdialect.New())

d := bundriver.New(db)
d.Migrate(ctx)

client := bundriver.NewClient(d, goncordia.ClientConfig{})

// Transactional insert:
bunTx, _ := db.BeginTx(ctx, nil)
db.NewInsert().Model(&order).Exec(ctx)  // or bunTx.NewInsert()...
client.EnqueueTx(ctx, bunTx, SendConfirmationArgs{OrderID: order.ID}, nil)
bunTx.Commit()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchParams

func FetchParams(queue string, limit int) driver.FetchParams

FetchParams is a convenience constructor for driver.FetchParams used in tests.

Types

type Client

type Client = goncordia.Client[bun.Tx]

Client is a type alias so callers never write goncordia.Client[bun.Tx].

func NewClient

func NewClient(d *Driver, cfg goncordia.ClientConfig) *Client

NewClient creates a Client bound to this bun driver.

type Driver

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

Driver implements driver.Driver[bun.Tx]. Internally it delegates to the stdlib driver using the same SQL logic.

func New

func New(db *bun.DB, opts ...Option) *Driver

New creates a Driver from a *bun.DB. The dialect is detected automatically from db.Dialect().Name(). Call Migrate before starting workers.

func (*Driver) Capabilities

func (d *Driver) Capabilities() driver.Capabilities

func (*Driver) Close

func (d *Driver) Close() error

func (*Driver) Executor

func (d *Driver) Executor() driver.Executor

func (*Driver) Listener

func (d *Driver) Listener() driver.Listener

func (*Driver) Migrate

func (d *Driver) Migrate(ctx context.Context) error

Migrate creates the goncordia schema in the database.

func (*Driver) Name

func (d *Driver) Name() string

func (*Driver) UnwrapTx

func (d *Driver) UnwrapTx(tx bun.Tx) driver.ExecutorTx

UnwrapTx extracts the *sql.Tx embedded in bun.Tx. tx must be obtained from db.BeginTx or db.RunInTx.

type Option

type Option func(*driverConfig)

Option configures the Driver.

func WithClock

func WithClock(c clock.Clock) Option

WithClock injects a custom clock (useful for tests).

type WorkerPool

type WorkerPool = goncordia.WorkerPool[bun.Tx]

WorkerPool is a type alias so callers never write goncordia.WorkerPool[bun.Tx].

func NewWorkerPool

func NewWorkerPool(d *Driver, r *core.Registry, cfg goncordia.WorkerConfig) *WorkerPool

NewWorkerPool creates a WorkerPool bound to this bun driver.

Jump to

Keyboard shortcuts

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