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 ¶
- func ValidateZoneWidths(zones []StoredZone) error
- type DB
- func (s *DB) Close() error
- func (s *DB) CreatePage(name string, ord int) (int64, error)
- func (s *DB) CreateZone(z StoredZone) error
- func (s *DB) DeletePage(id int64) error
- func (s *DB) DeleteZone(id string) error
- func (s *DB) GetFullLayout() ([]StoredPage, map[int64][]StoredZone, error)
- func (s *DB) GetPages() ([]StoredPage, error)
- func (s *DB) GetSetting(key, defaultVal string) string
- func (s *DB) GetSettings() (map[string]string, error)
- func (s *DB) GetZonePageID(zoneID string) (int64, error)
- func (s *DB) GetZonePluginConfig(zoneID string) (map[string]any, error)
- func (s *DB) GetZonesForPage(pageID int64) ([]StoredZone, error)
- func (s *DB) HasLayout() (bool, error)
- func (s *DB) ImportLayout(pages []StoredPage, zonesByPage map[int64][]StoredZone) error
- func (s *DB) IsFirstRun() bool
- func (s *DB) LoadPayloadCache(zoneID string) (payload []byte, fetchedAt int64, err error)
- func (s *DB) Path() string
- func (s *DB) ReorderPages(order []int64) error
- func (s *DB) ReorderZones(pageID int64, order []string) error
- func (s *DB) SavePayloadCache(zoneID, pluginID string, payload []byte, fetchedAt int64) error
- func (s *DB) SetSetting(key, value string) error
- func (s *DB) SetSettings(settings map[string]string) error
- func (s *DB) SetZonePlugin(zoneID, pluginID string) error
- func (s *DB) SetZonePluginConfig(zoneID string, cfg map[string]any) error
- func (s *DB) UpdatePage(id int64, name string, ord int) error
- func (s *DB) UpdateZone(z StoredZone) error
- type StoredPage
- type StoredZone
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 ¶
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) CreatePage ¶
CreatePage inserts a new page and returns its ID.
func (*DB) DeletePage ¶
DeletePage deletes a page (cascades to zones).
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 ¶
GetSetting returns the stored value for key, or defaultVal if not found.
func (*DB) GetSettings ¶
GetSettings returns all settings as a map.
func (*DB) GetZonePageID ¶
GetZonePageID returns the page_id for a zone. Returns 0 if not found.
func (*DB) GetZonePluginConfig ¶
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) 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 ¶
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 ¶
LoadPayloadCache returns the cached payload bytes and fetch timestamp for a zone, or (nil, 0, nil) if no cache entry exists.
func (*DB) ReorderPages ¶
ReorderPages sets ord for each page ID in a single transaction.
func (*DB) ReorderZones ¶
ReorderZones sets ord for each zone ID within a page.
func (*DB) SavePayloadCache ¶
SavePayloadCache persists a serialised DetailPayload for a zone. fetchedAt is the Unix timestamp of when the payload was fetched.
func (*DB) SetSetting ¶
SetSetting upserts a setting key/value pair.
func (*DB) SetSettings ¶
SetSettings upserts multiple settings in a single transaction.
func (*DB) SetZonePlugin ¶
func (*DB) SetZonePluginConfig ¶
SetZonePluginConfig updates config_json for a zone.
func (*DB) UpdatePage ¶
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 ¶
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.