store

package
v0.0.0-...-93c756f Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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) CreateLot

func (s *Store) CreateLot(ctx context.Context, name, address string) (Lot, error)

CreateLot inserts a lot. Name must be unique (DB enforces).

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) GetPrice

func (s *Store) GetPrice(ctx context.Context, vehicleID uuid.UUID) (Price, error)

GetPrice loads asking price from Postgres (source of truth).

func (*Store) ListLots

func (s *Store) ListLots(ctx context.Context) ([]Lot, error)

ListLots returns every lot, oldest first (stable for demos/screenshots).

func (*Store) ListVehicles

func (s *Store) ListVehicles(ctx context.Context) ([]Vehicle, error)

ListVehicles returns cars with optional lot name and price (LEFT JOINs).

func (*Store) SeedLotsVehiclesPrices

func (s *Store) SeedLotsVehiclesPrices(ctx context.Context) error

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.

func (*Store) UpsertPrice

func (s *Store) UpsertPrice(ctx context.Context, vehicleID uuid.UUID, amountCents int64, currency string) (Price, error)

UpsertPrice sets asking price and bumps updated_at. Callers should refresh Valkey after this.

func (*Store) VehicleExists

func (s *Store) VehicleExists(ctx context.Context, id uuid.UUID) (bool, error)

VehicleExists is a cheap check before enqueueing interest heat.

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.

Jump to

Keyboard shortcuts

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