store

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func New(db *sql.DB, dialect kerneldatabase.Dialect, piiCipher *pii.Cipher) *Store

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

func (s *Store) CreateOrder(ctx context.Context, order *ordersdomain.Order) (int64, error)

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

func (s *Store) EncryptPending(ctx context.Context, limit int) (int, error)

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

func (s *Store) ExpirePending(ctx context.Context, before time.Time, limit int) ([]int64, error)

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

func (s *Store) FindByID(ctx context.Context, id int64) (*ordersdomain.Order, error)

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

func (s *Store) MarkPaid(ctx context.Context, id int64) (bool, error)

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

func (s *Store) SetShipping(ctx context.Context, id int64, amount int64) (bool, error)

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.

func (*Store) SetStatus

func (s *Store) SetStatus(ctx context.Context, id int64, status ordersdomain.Status) error

SetStatus replaces the lifecycle status of the order, touching updated_at. An unknown order reads as ordersdomain.ErrOrderNotFound.

Jump to

Keyboard shortcuts

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