data

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProjectStatusIdeating   = "ideating"
	ProjectStatusPlanned    = "planned"
	ProjectStatusQuoted     = "quoted"
	ProjectStatusInProgress = "underway"
	ProjectStatusDelayed    = "delayed"
	ProjectStatusCompleted  = "completed"
	ProjectStatusAbandoned  = "abandoned"
)
View Source
const (
	DeletionEntityProject     = "project"
	DeletionEntityQuote       = "quote"
	DeletionEntityMaintenance = "maintenance"
	DeletionEntityAppliance   = "appliance"
	DeletionEntityServiceLog  = "service_log"
	DeletionEntityVendor      = "vendor"
)
View Source
const (
	ColID                = "id"
	ColName              = "name"
	ColCreatedAt         = "created_at"
	ColUpdatedAt         = "updated_at"
	ColDeletedAt         = "deleted_at"
	ColStatus            = "status"
	ColActualCents       = "actual_cents"
	ColCostCents         = "cost_cents"
	ColIntervalMonths    = "interval_months"
	ColWarrantyExpiry    = "warranty_expiry"
	ColServicedAt        = "serviced_at"
	ColReceivedDate      = "received_date"
	ColRestoredAt        = "restored_at"
	ColVendorID          = "vendor_id"
	ColProjectID         = "project_id"
	ColApplianceID       = "appliance_id"
	ColMaintenanceItemID = "maintenance_item_id"
	ColEntity            = "entity"
	ColTargetID          = "target_id"
	ColContactName       = "contact_name"
	ColEmail             = "email"
	ColPhone             = "phone"
	ColWebsite           = "website"
	ColNotes             = "notes"
)

Column name constants for use in raw SQL queries. Centralising these prevents drift between struct fields and hand-written SQL fragments.

View Source
const AppName = "micasa"
View Source
const DateLayout = "2006-01-02"

Variables

View Source
var (
	ErrInvalidMoney = errors.New("invalid money value")
	ErrInvalidDate  = errors.New("invalid date value")
	ErrInvalidInt   = errors.New("invalid integer value")
	ErrInvalidFloat = errors.New("invalid decimal value")
)

Functions

func ComputeNextDue

func ComputeNextDue(last *time.Time, intervalMonths int) *time.Time

func DefaultDBPath

func DefaultDBPath() (string, error)

func FormatCents

func FormatCents(cents int64) string

func FormatCompactCents added in v1.17.0

func FormatCompactCents(cents int64) string

FormatCompactCents formats cents using abbreviated notation for large values: $1.2k, $45k, $1.3M. Values under $1,000 use full precision. Uses go-humanize for SI prefix formatting.

func FormatCompactOptionalCents added in v1.17.0

func FormatCompactOptionalCents(cents *int64) string

FormatCompactOptionalCents formats optional cents compactly.

func FormatDate

func FormatDate(value *time.Time) string

func FormatOptionalCents

func FormatOptionalCents(cents *int64) string

func ParseOptionalCents

func ParseOptionalCents(input string) (*int64, error)

func ParseOptionalDate

func ParseOptionalDate(input string) (*time.Time, error)

func ParseOptionalFloat

func ParseOptionalFloat(input string) (float64, error)

func ParseOptionalInt

func ParseOptionalInt(input string) (int, error)

func ParseRequiredCents

func ParseRequiredCents(input string) (int64, error)

func ParseRequiredDate

func ParseRequiredDate(input string) (time.Time, error)

func ParseRequiredFloat

func ParseRequiredFloat(input string) (float64, error)

func ParseRequiredInt

func ParseRequiredInt(input string) (int, error)

func ProjectStatuses

func ProjectStatuses() []string

func ValidateDBPath added in v1.10.1

func ValidateDBPath(path string) error

ValidateDBPath rejects paths that could be interpreted as URIs by the SQLite driver. The underlying go-sqlite driver passes query strings through net/url.ParseQuery (subject to CVE GO-2026-4341) and enables SQLITE_OPEN_URI, so both file:// URIs and scheme://... URLs must be blocked. Only plain filesystem paths and the special ":memory:" value are accepted.

Types

type Appliance

type Appliance struct {
	ID             uint `gorm:"primaryKey"`
	Name           string
	Brand          string
	ModelNumber    string
	SerialNumber   string
	PurchaseDate   *time.Time
	WarrantyExpiry *time.Time `gorm:"index"`
	Location       string
	CostCents      *int64
	Notes          string
	CreatedAt      time.Time
	UpdatedAt      time.Time
	DeletedAt      gorm.DeletedAt `gorm:"index"`
}

type DeletionRecord

type DeletionRecord struct {
	ID         uint       `gorm:"primaryKey"`
	Entity     string     `gorm:"index:idx_entity_restored,priority:1"`
	TargetID   uint       `gorm:"index"`
	DeletedAt  time.Time  `gorm:"index"`
	RestoredAt *time.Time `gorm:"index:idx_entity_restored,priority:2"`
}

type HouseProfile

type HouseProfile struct {
	ID               uint `gorm:"primaryKey"`
	Nickname         string
	AddressLine1     string
	AddressLine2     string
	City             string
	State            string
	PostalCode       string
	YearBuilt        int
	SquareFeet       int
	LotSquareFeet    int
	Bedrooms         int
	Bathrooms        float64
	FoundationType   string
	WiringType       string
	RoofType         string
	ExteriorType     string
	HeatingType      string
	CoolingType      string
	WaterSource      string
	SewerType        string
	ParkingType      string
	BasementType     string
	InsuranceCarrier string
	InsurancePolicy  string
	InsuranceRenewal *time.Time
	PropertyTaxCents *int64
	HOAName          string
	HOAFeeCents      *int64
	CreatedAt        time.Time
	UpdatedAt        time.Time
}

type MaintenanceCategory

type MaintenanceCategory struct {
	ID        uint   `gorm:"primaryKey"`
	Name      string `gorm:"uniqueIndex"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type MaintenanceItem

type MaintenanceItem struct {
	ID             uint `gorm:"primaryKey"`
	Name           string
	CategoryID     uint                `gorm:"index"`
	Category       MaintenanceCategory `gorm:"constraint:OnDelete:RESTRICT;"`
	ApplianceID    *uint               `gorm:"index"`
	Appliance      Appliance           `gorm:"constraint:OnDelete:SET NULL;"`
	LastServicedAt *time.Time
	IntervalMonths int
	ManualURL      string
	ManualText     string
	Notes          string
	CostCents      *int64
	CreatedAt      time.Time
	UpdatedAt      time.Time
	DeletedAt      gorm.DeletedAt `gorm:"index"`
}

type Project

type Project struct {
	ID                uint `gorm:"primaryKey"`
	Title             string
	ProjectTypeID     uint
	ProjectType       ProjectType `gorm:"constraint:OnDelete:RESTRICT;"`
	Status            string
	Description       string
	StartDate         *time.Time
	EndDate           *time.Time
	BudgetCents       *int64
	ActualCents       *int64
	PreferredVendorID *uint
	PreferredVendor   Vendor `gorm:"constraint:OnDelete:SET NULL;"`
	CreatedAt         time.Time
	UpdatedAt         time.Time
	DeletedAt         gorm.DeletedAt `gorm:"index"`
}

type ProjectType

type ProjectType struct {
	ID          uint   `gorm:"primaryKey"`
	Name        string `gorm:"uniqueIndex"`
	Description string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type Quote

type Quote struct {
	ID             uint    `gorm:"primaryKey"`
	ProjectID      uint    `gorm:"index"`
	Project        Project `gorm:"constraint:OnDelete:RESTRICT;"`
	VendorID       uint    `gorm:"index"`
	Vendor         Vendor  `gorm:"constraint:OnDelete:RESTRICT;"`
	TotalCents     int64
	LaborCents     *int64
	MaterialsCents *int64
	OtherCents     *int64
	ReceivedDate   *time.Time
	Notes          string
	CreatedAt      time.Time
	UpdatedAt      time.Time
	DeletedAt      gorm.DeletedAt `gorm:"index"`
}

type ServiceLogEntry

type ServiceLogEntry struct {
	ID                uint            `gorm:"primaryKey"`
	MaintenanceItemID uint            `gorm:"index"`
	MaintenanceItem   MaintenanceItem `gorm:"constraint:OnDelete:CASCADE;"`
	ServicedAt        time.Time
	VendorID          *uint  `gorm:"index"`
	Vendor            Vendor `gorm:"constraint:OnDelete:SET NULL;"`
	CostCents         *int64
	Notes             string
	CreatedAt         time.Time
	UpdatedAt         time.Time
	DeletedAt         gorm.DeletedAt `gorm:"index"`
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func Open

func Open(path string) (*Store, error)

func (*Store) AutoMigrate

func (s *Store) AutoMigrate() error

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) CountMaintenanceByAppliance

func (s *Store) CountMaintenanceByAppliance(applianceIDs []uint) (map[uint]int, error)

CountMaintenanceByAppliance returns the count of non-deleted maintenance items for each appliance ID.

func (*Store) CountQuotesByProject added in v1.18.0

func (s *Store) CountQuotesByProject(projectIDs []uint) (map[uint]int, error)

CountQuotesByProject returns the number of non-deleted quotes per project ID.

func (*Store) CountQuotesByVendor added in v1.6.0

func (s *Store) CountQuotesByVendor(vendorIDs []uint) (map[uint]int, error)

CountQuotesByVendor returns the number of non-deleted quotes per vendor ID.

func (*Store) CountServiceLogs

func (s *Store) CountServiceLogs(itemIDs []uint) (map[uint]int, error)

CountServiceLogs returns the number of non-deleted service log entries per maintenance item ID for the given set of IDs.

func (*Store) CountServiceLogsByVendor added in v1.6.0

func (s *Store) CountServiceLogsByVendor(vendorIDs []uint) (map[uint]int, error)

CountServiceLogsByVendor returns the number of non-deleted service log entries per vendor ID.

func (*Store) CreateAppliance

func (s *Store) CreateAppliance(item Appliance) error

func (*Store) CreateHouseProfile

func (s *Store) CreateHouseProfile(profile HouseProfile) error

func (*Store) CreateMaintenance

func (s *Store) CreateMaintenance(item MaintenanceItem) error

func (*Store) CreateProject

func (s *Store) CreateProject(project Project) error

func (*Store) CreateQuote

func (s *Store) CreateQuote(quote Quote, vendor Vendor) error

func (*Store) CreateServiceLog

func (s *Store) CreateServiceLog(entry ServiceLogEntry, vendor Vendor) error

func (*Store) CreateVendor added in v1.6.0

func (s *Store) CreateVendor(vendor Vendor) error

func (*Store) DeleteAppliance

func (s *Store) DeleteAppliance(id uint) error

func (*Store) DeleteMaintenance

func (s *Store) DeleteMaintenance(id uint) error

func (*Store) DeleteProject

func (s *Store) DeleteProject(id uint) error

func (*Store) DeleteQuote

func (s *Store) DeleteQuote(id uint) error

func (*Store) DeleteServiceLog

func (s *Store) DeleteServiceLog(id uint) error

func (*Store) DeleteVendor added in v1.11.0

func (s *Store) DeleteVendor(id uint) error

func (*Store) GetAppliance

func (s *Store) GetAppliance(id uint) (Appliance, error)

func (*Store) GetMaintenance

func (s *Store) GetMaintenance(id uint) (MaintenanceItem, error)

func (*Store) GetProject

func (s *Store) GetProject(id uint) (Project, error)

func (*Store) GetQuote

func (s *Store) GetQuote(id uint) (Quote, error)

func (*Store) GetServiceLog

func (s *Store) GetServiceLog(id uint) (ServiceLogEntry, error)

func (*Store) GetVendor added in v1.6.0

func (s *Store) GetVendor(id uint) (Vendor, error)

func (*Store) HouseProfile

func (s *Store) HouseProfile() (HouseProfile, error)

func (*Store) LastDeletion

func (s *Store) LastDeletion(entity string) (DeletionRecord, error)

func (*Store) ListActiveProjects

func (s *Store) ListActiveProjects() ([]Project, error)

ListActiveProjects returns non-deleted projects with status "underway" or "delayed", preloading ProjectType.

func (*Store) ListAppliances

func (s *Store) ListAppliances(includeDeleted bool) ([]Appliance, error)

func (*Store) ListExpiringWarranties

func (s *Store) ListExpiringWarranties(
	now time.Time,
	lookBack, horizon time.Duration,
) ([]Appliance, error)

ListExpiringWarranties returns non-deleted appliances whose warranty expires between (now - lookBack) and (now + horizon).

func (*Store) ListMaintenance

func (s *Store) ListMaintenance(includeDeleted bool) ([]MaintenanceItem, error)

func (*Store) ListMaintenanceByAppliance

func (s *Store) ListMaintenanceByAppliance(
	applianceID uint,
	includeDeleted bool,
) ([]MaintenanceItem, error)

func (*Store) ListMaintenanceWithSchedule

func (s *Store) ListMaintenanceWithSchedule() ([]MaintenanceItem, error)

ListMaintenanceWithSchedule returns all non-deleted maintenance items that have a positive interval, preloading Category and Appliance. These are the items eligible for overdue/upcoming computation.

func (*Store) ListProjects

func (s *Store) ListProjects(includeDeleted bool) ([]Project, error)

func (*Store) ListQuotes

func (s *Store) ListQuotes(includeDeleted bool) ([]Quote, error)

func (*Store) ListQuotesByProject added in v1.18.0

func (s *Store) ListQuotesByProject(
	projectID uint,
	includeDeleted bool,
) ([]Quote, error)

ListQuotesByProject returns all quotes for a specific project.

func (*Store) ListQuotesByVendor added in v1.18.0

func (s *Store) ListQuotesByVendor(
	vendorID uint,
	includeDeleted bool,
) ([]Quote, error)

ListQuotesByVendor returns all quotes for a specific vendor.

func (*Store) ListRecentServiceLogs

func (s *Store) ListRecentServiceLogs(limit int) ([]ServiceLogEntry, error)

ListRecentServiceLogs returns the most recent service log entries across all maintenance items, preloading MaintenanceItem and Vendor.

func (*Store) ListServiceLog

func (s *Store) ListServiceLog(
	maintenanceItemID uint,
	includeDeleted bool,
) ([]ServiceLogEntry, error)

func (*Store) ListServiceLogsByVendor added in v1.18.0

func (s *Store) ListServiceLogsByVendor(
	vendorID uint,
	includeDeleted bool,
) ([]ServiceLogEntry, error)

ListServiceLogsByVendor returns all service log entries for a specific vendor.

func (*Store) ListVendors

func (s *Store) ListVendors(includeDeleted bool) ([]Vendor, error)

func (*Store) MaintenanceCategories

func (s *Store) MaintenanceCategories() ([]MaintenanceCategory, error)

func (*Store) ProjectTypes

func (s *Store) ProjectTypes() ([]ProjectType, error)

func (*Store) RestoreAppliance

func (s *Store) RestoreAppliance(id uint) error

func (*Store) RestoreMaintenance

func (s *Store) RestoreMaintenance(id uint) error

func (*Store) RestoreProject

func (s *Store) RestoreProject(id uint) error

func (*Store) RestoreQuote

func (s *Store) RestoreQuote(id uint) error

func (*Store) RestoreServiceLog

func (s *Store) RestoreServiceLog(id uint) error

func (*Store) RestoreVendor added in v1.11.0

func (s *Store) RestoreVendor(id uint) error

func (*Store) SeedDefaults

func (s *Store) SeedDefaults() error

func (*Store) SeedDemoData

func (s *Store) SeedDemoData() error

SeedDemoData populates the database with realistic demo data using a fixed seed so the demo always looks the same. Skips if data already exists.

func (*Store) SeedDemoDataFrom added in v1.10.0

func (s *Store) SeedDemoDataFrom(h *fake.HomeFaker) error

SeedDemoDataFrom populates the database with demo data generated by the given HomeFaker. Callers can pass different seeds for varied test data.

func (*Store) UpdateAppliance

func (s *Store) UpdateAppliance(item Appliance) error

func (*Store) UpdateHouseProfile

func (s *Store) UpdateHouseProfile(profile HouseProfile) error

func (*Store) UpdateMaintenance

func (s *Store) UpdateMaintenance(item MaintenanceItem) error

func (*Store) UpdateProject

func (s *Store) UpdateProject(project Project) error

func (*Store) UpdateQuote

func (s *Store) UpdateQuote(quote Quote, vendor Vendor) error

func (*Store) UpdateServiceLog

func (s *Store) UpdateServiceLog(entry ServiceLogEntry, vendor Vendor) error

func (*Store) UpdateVendor added in v1.6.0

func (s *Store) UpdateVendor(vendor Vendor) error

func (*Store) YTDProjectSpendCents

func (s *Store) YTDProjectSpendCents() (int64, error)

YTDProjectSpendCents returns the total actual spend across all non-deleted projects.

func (*Store) YTDServiceSpendCents

func (s *Store) YTDServiceSpendCents(yearStart time.Time) (int64, error)

YTDServiceSpendCents returns the total cost of service log entries with ServicedAt on or after the given start-of-year.

type Vendor

type Vendor struct {
	ID          uint   `gorm:"primaryKey"`
	Name        string `gorm:"uniqueIndex"`
	ContactName string
	Email       string
	Phone       string
	Website     string
	Notes       string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	DeletedAt   gorm.DeletedAt `gorm:"index"`
}

Jump to

Keyboard shortcuts

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