Documentation
¶
Overview ¶
Package store is the single-source cart repository: one implementation against *sql.DB plus a kernel Dialect, following the comments/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 line uniqueness constraint behaves identically on every driver.
Index ¶
- type Store
- func (s *Store) AddLine(ctx context.Context, cartID int64, productContentID int, variantID *int64, ...) (cartdomain.StoredLine, error)
- func (s *Store) CreateCart(ctx context.Context, tokenHash string) (int64, error)
- func (s *Store) DeleteCart(ctx context.Context, cartID int64) error
- func (s *Store) FindCart(ctx context.Context, tokenHash string) (*cartdomain.StoredCart, error)
- func (s *Store) RemoveLine(ctx context.Context, cartID int64, itemID int64) error
- func (s *Store) SetLineQuantity(ctx context.Context, cartID int64, itemID int64, quantity int) 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 cart single-source store.
func New ¶
func New(db *sql.DB, dialect kerneldatabase.Dialect) *Store
New builds the store over an open database and its dialect.
func (*Store) AddLine ¶
func (s *Store) AddLine(ctx context.Context, cartID int64, productContentID int, variantID *int64, quantity int) (cartdomain.StoredLine, error)
AddLine appends a line, merging with an existing line on the same (product, variant) key by incrementing its quantity. A duplicate-key hit from a concurrent add retries once against the fresh row set.
func (*Store) CreateCart ¶
CreateCart persists an empty cart keyed by token hash and returns its ID.
func (*Store) DeleteCart ¶
DeleteCart removes the cart; unknown carts report cartdomain.ErrCartNotFound. The delete is the checkout claim: reporting the affected-row count is what makes the claim atomic, so of any parallel checkouts on one token exactly one proceeds and the losers read the cart as gone instead of silently double-deleting a row that is already gone.
func (*Store) FindCart ¶
func (s *Store) FindCart(ctx context.Context, tokenHash string) (*cartdomain.StoredCart, error)
FindCart returns the cart with its raw lines in id order, or cartdomain.ErrCartNotFound when the token hash matches no cart.
func (*Store) RemoveLine ¶
RemoveLine deletes one line of the cart; unknown lines are a no-op.