Documentation
¶
Overview ¶
Package store is the single-source catalog repository: one implementation against *sql.DB plus a kernel Dialect, following the comments/media store pattern. Upsert rendering and placeholder differences come from the dialect; everything else (columns, scans, messages) is shared.
Index ¶
- type Store
- func (s *Store) AdjustStock(ctx context.Context, contentID int, variantID *int64, delta int) (bool, error)
- func (s *Store) GetProduct(ctx context.Context, contentID int) (*catalogdomain.Product, error)
- func (s *Store) UpsertProduct(ctx context.Context, contentID int, product *catalogdomain.Product) 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 catalog 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) AdjustStock ¶
func (s *Store) AdjustStock(ctx context.Context, contentID int, variantID *int64, delta int) (bool, error)
AdjustStock applies the signed delta to one tracked stock bucket with the condition carried in the statement itself: the row-level guard `stock + delta >= 0` makes the read-modify-write atomic, so two concurrent adjustments serialize at the row and the loser reads zero rows. Reports whether the row changed; a zero report means the bucket vanished or the move fell below zero (the service classifies).
func (*Store) GetProduct ¶
GetProduct returns the product with its full variant matrix, or catalogdomain.ErrProductNotFound when the content item has no row.
func (*Store) UpsertProduct ¶
func (s *Store) UpsertProduct(ctx context.Context, contentID int, product *catalogdomain.Product) error
UpsertProduct writes the product row (insert or update via the dialect's upsert) and replaces the variant matrix wholesale, atomically.