store

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 6 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 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

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

func (s *Store) CreateCart(ctx context.Context, tokenHash string) (int64, error)

CreateCart persists an empty cart keyed by token hash and returns its ID.

func (*Store) DeleteCart

func (s *Store) DeleteCart(ctx context.Context, cartID int64) error

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

func (s *Store) RemoveLine(ctx context.Context, cartID int64, itemID int64) error

RemoveLine deletes one line of the cart; unknown lines are a no-op.

func (*Store) SetLineQuantity

func (s *Store) SetLineQuantity(ctx context.Context, cartID int64, itemID int64, quantity int) error

SetLineQuantity replaces a line's quantity; the line must belong to the cart or cartdomain.ErrLineNotFound results.

Jump to

Keyboard shortcuts

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