orders

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OrderMeta = drel.ModelMeta[Order]{
	Table:         "orders",
	Columns:       []string{"id", "customer", "total", "status", "created_at", "updated_at"},
	PKColumns:     []string{"id"},
	Scan:          scanOrder,
	Snapshot:      snapshotOrder,
	Diff:          diffOrder,
	PKValue:       orderPKValue,
	InsertColumns: orderInsertColumns,
	ScanReturning: orderScanReturning,
	ColumnValue:   orderColumnValue,
	NormalizeKey:  orderNormalizeKey,
	KeyStrategy:   drel.KeyAppAssigned,
	GenerateKey:   drel.UUIDv7Key,
	SetKey:        func(p *Order, key any) { p.SetID(key.(uuid.UUID)) },
	KeyIsZero:     orderKeyIsZero,
	ScanGenerated: orderScanGenerated,
}
View Source
var Orders = struct {
	ID        drel.ComparableColumn[uuid.UUID]
	Customer  drel.StringColumn
	Total     drel.OrderedColumn[int]
	Status    drel.StringColumn
	CreatedAt drel.TimeColumn
	UpdatedAt drel.TimeColumn
}{
	ID:        drel.NewComparableCol[uuid.UUID]("id"),
	Customer:  drel.NewStringCol("customer"),
	Total:     drel.NewOrderedCol[int]("total"),
	Status:    drel.NewStringCol("status"),
	CreatedAt: drel.NewTimeCol("created_at"),
	UpdatedAt: drel.NewTimeCol("updated_at"),
}

Functions

This section is empty.

Types

type Order

type Order struct {
	drel.Model[uuid.UUID]
	Customer string `db:"customer"`
	Total    int    `db:"total"`
	Status   string `db:"status,index"`
}

Order is a SQLite-backed model that raises domain events from its behaviour. Embedding drel.Model[uuid.UUID] gives it an application-assigned UUIDv7 primary key (stamped at Add() time), plus ID(), RecordEvent and the change-tracking hooks the outbox relies on.

func NewOrder

func NewOrder(customer string, total int) *Order

NewOrder builds a placed-but-unsaved order. Total is in cents.

func (*Order) Place

func (o *Order) Place()

Place records an OrderPlaced event. The UUID id is assigned at Add() time, so ID() is already valid here — no flush required first.

func (*Order) Ship

func (o *Order) Ship(carrier string)

Ship marks the order shipped and records an OrderShipped event.

type OrderPlaced

type OrderPlaced struct {
	OrderID  uuid.UUID `json:"order_id"`
	Customer string    `json:"customer"`
	Total    int       `json:"total_cents"`
}

OrderPlaced is recorded when a new order is accepted.

type OrderRepository

type OrderRepository struct {
	*drel.Repository[Order]
}

func (*OrderRepository) FindByID

func (r *OrderRepository) FindByID(ctx context.Context, id uuid.UUID) (*Order, error)

type OrderShipped

type OrderShipped struct {
	OrderID uuid.UUID `json:"order_id"`
	Carrier string    `json:"carrier"`
}

OrderShipped is recorded when an order is dispatched to a carrier.

type TxOrderRepository

type TxOrderRepository struct {
	*drel.TxRepository[Order]
}

func (*TxOrderRepository) FindByID

func (r *TxOrderRepository) FindByID(ctx context.Context, id uuid.UUID) (*Order, error)

Jump to

Keyboard shortcuts

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