Documentation
¶
Index ¶
- Constants
- Variables
- type Database
- type GormDB
- func (g *GormDB) AddOrder(ctx context.Context, o *model.Order) error
- func (g *GormDB) AddOutboxItems(ctx context.Context, items []*model.OutboxItem) error
- func (g *GormDB) GetItemByName(ctx context.Context, name string) (*model.Item, error)
- func (g *GormDB) GetItemBySKU(ctx context.Context, sku string) (*model.Item, error)
- func (g *GormDB) GetItemsBySKU(ctx context.Context, skus []string) ([]*model.Item, error)
- func (g *GormDB) GetOrders(ctx context.Context, customerID string) ([]*model.Order, error)
- func (g *GormDB) GetOutboxItems(ctx context.Context, q *OutboxQuery) ([]*model.OutboxItem, error)
- func (g *GormDB) ListItems(ctx context.Context) ([]*model.Item, error)
- func (g *GormDB) Ping(ctx context.Context) error
- func (g *GormDB) SetDeliveredAt(ctx context.Context, id int64, t time.Time) error
- func (g *GormDB) SetDeliveredByEventID(ctx context.Context, eventID string, t time.Time) error
- func (g *GormDB) SetPublishedAt(ctx context.Context, id int64, t time.Time) error
- func (g *GormDB) Transaction(ctx context.Context, fn func(Database) error) error
- func (g *GormDB) UpsertItems(ctx context.Context, items []*model.Item) ([]*model.Item, error)
- type HealthChecker
- type InventoryStore
- type OrderStore
- type OutboxQuery
- type OutboxStore
Constants ¶
View Source
const DBName = "checkout"
View Source
const InMemoryDSN = ":memory:"
Variables ¶
View Source
var ErrOutboxItemNotFound = errors.New("outbox item not found")
ErrOutboxItemNotFound is returned when a strict update matches no row.
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database interface {
HealthChecker
InventoryStore
OrderStore
OutboxStore
Transaction(ctx context.Context, fn func(Database) error) error
}
type GormDB ¶
type GormDB struct {
// contains filtered or unexported fields
}
func NewPostgresDB ¶
NewPostgresDB returns a new GormDB with PostgreSQL engine.
func NewSQLiteDB ¶
NewSQLiteDB returns a new GormDB with SQLite engine.
func (*GormDB) AddOutboxItems ¶ added in v0.7.0
func (*GormDB) GetItemByName ¶
func (*GormDB) GetItemBySKU ¶
func (*GormDB) GetItemsBySKU ¶
func (*GormDB) GetOutboxItems ¶ added in v0.7.0
func (g *GormDB) GetOutboxItems(ctx context.Context, q *OutboxQuery) ([]*model.OutboxItem, error)
func (*GormDB) SetDeliveredAt ¶ added in v0.7.0
func (*GormDB) SetDeliveredByEventID ¶ added in v0.7.0
SetDeliveredByEventID marks the outbox row with the given event ID delivered. The notifier holds the event ID (not the row's serial ID), so it marks delivery by that. Strict: matching no row is an error.
func (*GormDB) SetPublishedAt ¶ added in v0.7.0
func (*GormDB) Transaction ¶ added in v0.7.0
type HealthChecker ¶
type InventoryStore ¶
type InventoryStore interface {
UpsertItems(ctx context.Context, items []*model.Item) ([]*model.Item, error)
ListItems(ctx context.Context) ([]*model.Item, error) // TODO - add pagination support
GetItemByName(ctx context.Context, name string) (*model.Item, error)
GetItemBySKU(ctx context.Context, sku string) (*model.Item, error)
GetItemsBySKU(ctx context.Context, sku []string) ([]*model.Item, error)
}
type OrderStore ¶
type OutboxQuery ¶ added in v0.7.0
type OutboxQuery struct {
// OnlyUnpublished restricts to rows not yet sent to the broker
// (published_at IS NULL). This is the relay's claim filter.
OnlyUnpublished bool
// OnlyUndelivered restricts to rows not yet marked delivered
// (delivered_at IS NULL).
OnlyUndelivered bool
// Limit caps the batch size; <= 0 means no limit.
Limit int
}
OutboxQuery filters an outbox read. The zero value selects everything.
type OutboxStore ¶ added in v0.7.0
type OutboxStore interface {
// AddOutboxItems enqueues items. Intended to run inside the same
// transaction as the business write it accompanies.
AddOutboxItems(ctx context.Context, items []*model.OutboxItem) error
// GetOutboxItems reads items, optionally filtered to those not yet
// published or delivered. Results are ordered by ID ascending (enqueue
// order).
GetOutboxItems(ctx context.Context, q *OutboxQuery) ([]*model.OutboxItem, error)
// SetPublishedAt strictly marks one item published: it errors with
// ErrOutboxItemNotFound if no row has that ID.
SetPublishedAt(ctx context.Context, id int64, t time.Time) error
// SetDeliveredAt strictly marks one item delivered, with the same
// not-found semantics as SetPublishedAt.
SetDeliveredAt(ctx context.Context, id int64, t time.Time) error
// SetDeliveredByEventID marks the item with the given event ID delivered.
// The notifier consumes events keyed by event ID, so it marks delivery by
// that rather than the row's serial ID.
SetDeliveredByEventID(ctx context.Context, eventID string, t time.Time) error
}
OutboxStore persists and drains transactional outbox rows.
Click to show internal directories.
Click to hide internal directories.