Documentation
¶
Overview ¶
Package store is the single-source order repository: one implementation against *sql.DB plus a kernel Dialect, following the cart/media store pattern. Placeholder rendering and RETURNING support come from the dialect. Variant IDs map nil (base-product line) to 0 at the boundary so the schema behaves identically on every driver, and the shipping address round-trips as a JSON snapshot.
Index ¶
- type Store
- func (s *Store) CreateOrder(ctx context.Context, order *ordersdomain.Order) (int64, error)
- func (s *Store) EncryptPending(ctx context.Context, limit int) (int, error)
- func (s *Store) ExpirePending(ctx context.Context, before time.Time, limit int) ([]int64, error)
- func (s *Store) FindByID(ctx context.Context, id int64) (*ordersdomain.Order, error)
- func (s *Store) FindByNumberAndEmailAndToken(ctx context.Context, id int64, email string, tokenHash string) (*ordersdomain.Order, error)
- func (s *Store) List(ctx context.Context, status *ordersdomain.Status, beforeID int64, limit int) ([]ordersdomain.Order, error)
- func (s *Store) MarkPaid(ctx context.Context, id int64) (bool, error)
- func (s *Store) SetShipping(ctx context.Context, id int64, amount int64) (bool, error)
- func (s *Store) SetStatus(ctx context.Context, id int64, status ordersdomain.Status) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the order single-source store. PII fields (customer email, name, phone, shipping snapshot) are encrypted at this boundary: writes seal them through the cipher and reads open them, while guest tracking resolves through the blind-index column. A nil cipher stores and reads plaintext (legacy mode); the startup sweep encrypts those rows once a key is provisioned.
func New ¶
New builds the store over an open database, its dialect, and the PII cipher. A nil cipher stores and reads plaintext (legacy mode); a set cipher seals the customer PII fields on write and resolves guest tracking through the blind-index column.
func (*Store) CreateOrder ¶
CreateOrder persists the order and its item snapshot in one transaction: the order row inserts first for the generated ID, then every item row carries it. Storage identities and timestamps fill the struct before return.
func (*Store) EncryptPending ¶
EncryptPending encrypts up to limit legacy plaintext rows in place and fills their blind-index columns, returning how many rows changed. The startup backfill sweep calls it in batches until it reports zero: a second boot is a no-op because enveloped rows no longer match the sweep predicate. A nil cipher encrypts nothing and reports zero. Fields already carrying the envelope are left untouched, so concurrent sweeps converge instead of double-encrypting.
func (*Store) ExpirePending ¶
ExpirePending flips up to limit pending orders created before the boundary to expired and returns the flipped IDs. The candidate list reads inside the transaction and every flip carries the pending guard, so a payment that lands mid-sweep keeps its win.
func (*Store) FindByID ¶
FindByID returns the order with its items, or ordersdomain.ErrOrderNotFound.
func (*Store) FindByNumberAndEmailAndToken ¶
func (s *Store) FindByNumberAndEmailAndToken(ctx context.Context, id int64, email string, tokenHash string) (*ordersdomain.Order, error)
FindByNumberAndEmailAndToken returns the order with its items when the order ID, the customer email, and the tracking-token hash all match, or ordersdomain.ErrOrderNotFound. Matching is exact: the service normalizes the presented email and hashes the presented token the way checkout stored them.
func (*Store) List ¶
func (s *Store) List(ctx context.Context, status *ordersdomain.Status, beforeID int64, limit int) ([]ordersdomain.Order, error)
List returns the newest orders carrying the given status (nil is any), strictly below the keyset boundary (0 means from the newest), at most limit rows. Items are not loaded; the per-order line count rides the read-time COUNT aggregate into ItemCount.
func (*Store) MarkPaid ¶
MarkPaid flips a pending order to paid and reports whether this call did the flip. The pending guard lives in the statement, so racing confirms, retried webhooks, and the expiry sweep serialize on it — the loser reads zero rows.
func (*Store) SetShipping ¶
SetShipping replaces the shipping line of a pending order and reports whether this call did the write. The pending guard lives in the statement, mirroring MarkPaid: a status flip racing the write loses it, and the service reads the loss as a refused transition.