Documentation
¶
Overview ¶
Package outboxsql is the outbox for consumer apps running against database/sql, for both Postgres (any driver: lib/pq, pgx/stdlib, etc.) and MySQL (go-sql-driver/mysql). InitSchema (and the CreateOutboxTableSQLPostgres / CreateOutboxTableSQLMySQL constants it dispatches on) create the outbox_messages table an outbox processor then drains; Writer writes event, audit-log and dispatch-job rows into it inside the caller's transaction, the same rows outboxpgx writes.
Index ¶
Constants ¶
const CreateOutboxTableSQLMySQL = `` /* 783-byte string literal not displayed */
CreateOutboxTableSQLMySQL is the schema for MySQL 8.0+. Includes SDK-specific columns and indexes matching the Java outbox-processor's expectations. Mirrors the TypeScript SDK migration.
const CreateOutboxTableSQLPostgres = `` /* 814-byte string literal not displayed */
CreateOutboxTableSQLPostgres is the schema for Postgres. Mirrors the TypeScript SDK's migration so all SDKs converge on one shape.
Variables ¶
This section is empty.
Functions ¶
func InitSchema ¶
InitSchema creates the outbox_messages table for the given dialect. Idempotent. In production, run your real migration system instead.
Postgres: a single Exec covers all statements (the driver handles the script). MySQL: only one statement per Exec; this helper splits on bare semicolons at top level which is sufficient for the schema above (single CREATE TABLE statement, indexes inline). For richer schemas, use a real migration tool.
Types ¶
type Execer ¶
type Execer interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}
Execer is what a Writer writes through: *sql.Tx (the usual case: the caller's transaction, so the rows commit with the work) or *sql.DB.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes outbox rows through database/sql. Safe for concurrent use.
func NewWriter ¶
func NewWriter(dialect Dialect, cfg WriterConfig) (*Writer, error)
NewWriter builds a Writer for the dialect's placeholder style. It fails only on an invalid table name.
func (*Writer) WriteAudit ¶
func (w *Writer) WriteAudit(ctx context.Context, ex Execer, event usecase.DomainEvent, command any) error
WriteAudit inserts the AUDIT_LOG row of (event, command).
func (*Writer) WriteDispatchJob ¶
WriteDispatchJob validates job and inserts its DISPATCH_JOB row.
func (*Writer) WriteEvent ¶
WriteEvent inserts the EVENT row of a domain event.
type WriterConfig ¶
type WriterConfig struct {
// TableName is the outbox table. Default: "outbox_messages".
TableName string
// ClientID is stored in every row's client_id column. May be empty.
ClientID string
// ClientCode is the client's identifier slug, sent as clientCode in
// event and audit payloads. Empty leaves it out.
ClientCode string
// ApplicationCode is written as each audit row's applicationCode.
ApplicationCode string
// Now is the clock for created_at/updated_at. Default time.Now.
Now func() time.Time
}
WriterConfig configures a Writer. The fields mean what they mean on outboxpgx.Config.