store

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package store provides a SQLite-backed configuration store for Nexus Open.

All persistent configuration lives in a single database file:

~/.config/nexus-open/nexus.db

Three logical areas are stored here:

  • settings table: flat key/value pairs for UI preferences (colours, locale, display config). Replaces config.yaml + shared_preferences.
  • zone_plugin_config table: per-zone plugin configuration overrides (graph types, units, etc.). Replaces zone-configs.yaml.
  • pages + zones tables: the hardware display layout (which modules appear where). Replaces configs/layouts/*.yaml for user-edited config; the YAML layout files remain as the factory default / import source.

On first run the store imports existing YAML files so users don't lose their configuration when upgrading.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateZoneWidths

func ValidateZoneWidths(zones []StoredZone) error

ValidateZoneWidths checks that zones for a page sum to exactly 640px.

Types

type DB

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

DB is the application's SQLite store. All methods are safe for concurrent use.

func Open

func Open(path string, logger *slog.Logger) (*DB, error)

Open opens (or creates) the SQLite database at path and runs any pending schema migrations. If path is empty it defaults to ~/.config/nexus-open/nexus.db.

func (*DB) Close

func (s *DB) Close() error

Close closes the underlying database connection.

func (*DB) CreatePage

func (s *DB) CreatePage(name string, ord int) (int64, error)

CreatePage inserts a new page and returns its ID.

func (*DB) CreateZone

func (s *DB) CreateZone(z StoredZone) error

CreateZone inserts a new zone.

func (*DB) DeletePage

func (s *DB) DeletePage(id int64) error

DeletePage deletes a page (cascades to zones).

func (*DB) DeleteZone

func (s *DB) DeleteZone(id string) error

DeleteZone removes a zone by ID.

func (*DB) GetFullLayout

func (s *DB) GetFullLayout() ([]StoredPage, map[int64][]StoredZone, error)

GetFullLayout returns all pages with their zones.

func (*DB) GetPages

func (s *DB) GetPages() ([]StoredPage, error)

GetPages returns all pages ordered by ord.

func (*DB) GetSetting

func (s *DB) GetSetting(key, defaultVal string) string

GetSetting returns the stored value for key, or defaultVal if not found.

func (*DB) GetSettings

func (s *DB) GetSettings() (map[string]string, error)

GetSettings returns all settings as a map.

func (*DB) GetZonePageID

func (s *DB) GetZonePageID(zoneID string) (int64, error)

GetZonePageID returns the page_id for a zone. Returns 0 if not found.

func (*DB) GetZonePluginConfig

func (s *DB) GetZonePluginConfig(zoneID string) (map[string]any, error)

GetZonePluginConfig returns the plugin config for a single zone. Returns nil if the zone has no stored config.

func (*DB) GetZonesForPage

func (s *DB) GetZonesForPage(pageID int64) ([]StoredZone, error)

GetZonesForPage returns all zones for a page ordered by ord.

func (*DB) HasLayout

func (s *DB) HasLayout() (bool, error)

HasLayout reports whether any pages exist in the DB.

func (*DB) ImportLayout

func (s *DB) ImportLayout(pages []StoredPage, zonesByPage map[int64][]StoredZone) error

ImportLayout writes a full layout in a single transaction, replacing any existing pages and zones. Used on first run to seed from YAML.

func (*DB) IsFirstRun

func (s *DB) IsFirstRun() bool

IsFirstRun reports whether the database was freshly created on this open. The answer is captured before migrate() runs so it remains correct even after migrations have bumped the schema version to the current value.

func (*DB) LoadPayloadCache

func (s *DB) LoadPayloadCache(zoneID string) (payload []byte, fetchedAt int64, err error)

LoadPayloadCache returns the cached payload bytes and fetch timestamp for a zone, or (nil, 0, nil) if no cache entry exists.

func (*DB) Path

func (s *DB) Path() string

Path returns the filesystem path of the database file.

func (*DB) ReorderPages

func (s *DB) ReorderPages(order []int64) error

ReorderPages sets ord for each page ID in a single transaction.

func (*DB) ReorderZones

func (s *DB) ReorderZones(pageID int64, order []string) error

ReorderZones sets ord for each zone ID within a page.

func (*DB) SavePayloadCache

func (s *DB) SavePayloadCache(zoneID, pluginID string, payload []byte, fetchedAt int64) error

SavePayloadCache persists a serialised DetailPayload for a zone. fetchedAt is the Unix timestamp of when the payload was fetched.

func (*DB) SetSetting

func (s *DB) SetSetting(key, value string) error

SetSetting upserts a setting key/value pair.

func (*DB) SetSettings

func (s *DB) SetSettings(settings map[string]string) error

SetSettings upserts multiple settings in a single transaction.

func (*DB) SetZonePlugin

func (s *DB) SetZonePlugin(zoneID, pluginID string) error

func (*DB) SetZonePluginConfig

func (s *DB) SetZonePluginConfig(zoneID string, cfg map[string]any) error

SetZonePluginConfig updates config_json for a zone.

func (*DB) UpdatePage

func (s *DB) UpdatePage(id int64, name string, ord int) error

UpdatePage updates a page's name and/or order.

func (*DB) UpdateZone

func (s *DB) UpdateZone(z StoredZone) error

UpdateZone updates a zone's mutable fields.

type StoredPage

type StoredPage struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
	Ord  int    `json:"ord"`
}

StoredPage is a page row from the DB.

type StoredZone

type StoredZone struct {
	ID         string         `json:"id"`
	PageID     int64          `json:"page_id"`
	Ord        int            `json:"ord"`
	WidthPx    int            `json:"width_px"`
	Plugin     string         `json:"plugin"`
	RefreshMs  int            `json:"refresh_ms"`
	Align      string         `json:"align"`
	OnTap      string         `json:"on_tap,omitempty"`
	Choices    []string       `json:"choices,omitempty"`
	ConfigJSON map[string]any `json:"config"`
	ThemeJSON  map[string]any `json:"theme_override,omitempty"`
}

StoredZone is a zone row from the DB.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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