Documentation
¶
Overview ¶
Package sql provides shared building blocks for database/sql-based outbox.Store implementations. Concrete dialect implementations live in subpackages such as outbox/sql/postgres and outbox/sql/sqlite.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScanMessages ¶
ScanMessages scans rows produced by a fetch query into outbox.Message values.
The expected column order is:
id, topic, key, payload, headers, status, retries, last_error, created_at, processed_at
processed_at is treated as nullable.
Types ¶
type Config ¶
type Config struct {
TableName string
MaxRetries int
RetryAfter time.Duration
// IDGenerator produces a new message id when Save receives a Message
// with an empty ID. Defaults to uuid.NewString. Override via
// WithIDGenerator to plug in your own (e.g. nanoid, ULID, snowflake).
IDGenerator func() string
}
Config holds the configuration shared by database/sql outbox stores.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default configuration used by dialect stores.
type DBTX ¶ added in v0.11.1
type DBTX interface {
Execer
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}
DBTX is the minimal database/sql interface needed for both reads and writes. *sql.DB, *sql.Tx and *sql.Conn all satisfy it.
The outbox.ProcessedStore implementations in outbox/sql/postgres and outbox/sql/sqlite accept any value satisfying DBTX so callers can pass a *sql.Tx for transactional exactly-once or *sql.DB for read-only checks and the cleanup loop.
type Execer ¶
type Execer interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
Execer is the minimal interface needed to execute a statement. Both *sql.DB, *sql.Tx and *sql.Conn satisfy it.
type Option ¶
type Option interface {
Apply(*Config)
}
An Option configures a Store instance.
func WithIDGenerator ¶ added in v0.11.1
WithIDGenerator overrides the default id generator (uuid.NewString). The function is called by Save when a message is persisted with an empty ID. nil is ignored.
func WithMaxRetries ¶
WithMaxRetries sets the maximum number of retries before a message is marked as failed.
func WithRetryAfter ¶
WithRetryAfter sets the duration after which a failed message is retried.
func WithTableName ¶
WithTableName sets the outbox table name.
Pass an unqualified name — the migration DDL derives index names from this value (idx_<table>_pending), and a dotted "schema.table" produces an invalid identifier. For Postgres, set the schema via the connection's search_path; SQLite has no schemas.
type OptionFunc ¶
type OptionFunc func(*Config)
OptionFunc is a function that configures a Store config.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package postgres provides a PostgreSQL implementation of outbox.Store using database/sql.
|
Package postgres provides a PostgreSQL implementation of outbox.Store using database/sql. |
|
Package sqlite provides a SQLite implementation of outbox.Store using database/sql.
|
Package sqlite provides a SQLite implementation of outbox.Store using database/sql. |