Documentation
¶
Overview ¶
Package store is the Postgres access layer for Caerus Motors.
We intentionally use raw pgx (not GORM). The framework owns the *pool* lifecycle; this package owns SQL. That split is the whole point of POSTGRES-HEAVY.md: ops chassis vs query engine.
Index ¶
- Variables
- type Lot
- type Price
- type Store
- func (s *Store) CreateLot(ctx context.Context, name, address string) (Lot, error)
- func (s *Store) CreateVehicle(ctx context.Context, vin, make, model string, year int, color string, ...) (Vehicle, error)
- func (s *Store) GetPrice(ctx context.Context, vehicleID uuid.UUID) (Price, error)
- func (s *Store) ListLots(ctx context.Context) ([]Lot, error)
- func (s *Store) ListVehicles(ctx context.Context) ([]Vehicle, error)
- func (s *Store) SeedLotsVehiclesPrices(ctx context.Context) error
- func (s *Store) UpsertPrice(ctx context.Context, vehicleID uuid.UUID, amountCents int64, currency string) (Price, error)
- func (s *Store) VehicleExists(ctx context.Context, id uuid.UUID) (bool, error)
- type Vehicle
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("store: not found")
ErrNotFound means the row isn't there — HTTP layer maps this to 404.
Functions ¶
This section is empty.
Types ¶
type Lot ¶
type Lot struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Address string `json:"address"`
CreatedAt time.Time `json:"created_at"`
}
Lot is a physical (or fictional) place cars sit.
type Price ¶
type Price struct {
VehicleID uuid.UUID `json:"vehicle_id"`
AmountCents int64 `json:"amount_cents"`
Currency string `json:"currency"`
UpdatedAt time.Time `json:"updated_at"`
}
Price is the asking price for one vehicle. This is what Valkey caches.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps the framework postgres component. The pool is owned by cf_postgres — we never Close it, and we never snapshot Pool() at Init (reload swaps the live pool).
func New ¶
func New(pg *cf_postgres.CFPostgres) *Store
New binds to the postgres component. Call Pool() on every query.
func (*Store) CreateVehicle ¶
func (s *Store) CreateVehicle(ctx context.Context, vin, make, model string, year int, color string, lotID *uuid.UUID) (Vehicle, error)
CreateVehicle inserts a vehicle. lotID may be nil (unassigned).
func (*Store) ListVehicles ¶
ListVehicles returns cars with optional lot name and price (LEFT JOINs).
func (*Store) SeedLotsVehiclesPrices ¶
SeedLotsVehiclesPrices is idempotent: re-running `demoapp seed` must not duplicate rows. We key lots by name and vehicles by VIN.
Why these cars? Mix of EV / ICE / truck / sports so screenshots look alive, and a Porsche so the lot doesn't look like a boring mid-market catalog.
type Vehicle ¶
type Vehicle struct {
ID uuid.UUID `json:"id"`
VIN string `json:"vin"`
Make string `json:"make"`
Model string `json:"model"`
Year int `json:"year"`
Color string `json:"color"`
LotID *uuid.UUID `json:"lot_id,omitempty"`
LotName string `json:"lot_name,omitempty"`
CreatedAt time.Time `json:"created_at"`
// Price fields filled when we JOIN prices (list endpoints).
AmountCents *int64 `json:"amount_cents,omitempty"`
Currency *string `json:"currency,omitempty"`
}
Vehicle is a car on the books. VIN values in the demo are DEMO-VIN-* strings, not ISO-3779 identifiers — we are teaching wiring, not DMS compliance.