From 2d9c5b2b49269c5e88b2d9649c8e0d47126e07d2 Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 06:35:23 +0000 Subject: [PATCH] refactor(store): clarify backing store names Co-Authored-By: Virgil --- coverage_test.go | 2 +- scope.go | 24 ++++++++++++------------ workspace.go | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/coverage_test.go b/coverage_test.go index d0fc2d7..dee047f 100644 --- a/coverage_test.go +++ b/coverage_test.go @@ -304,7 +304,7 @@ func TestCoverage_ScopedStore_Bad_GroupsSeqRowsError(t *testing.T) { defer database.Close() scopedStore := &ScopedStore{ - store: &Store{ + backingStore: &Store{ database: database, cancelPurge: func() {}, }, diff --git a/scope.go b/scope.go index 219ff9c..0ab34bc 100644 --- a/scope.go +++ b/scope.go @@ -23,23 +23,23 @@ type QuotaConfig struct { // Usage example: `scopedStore := store.NewScoped(storeInstance, "tenant-a"); if scopedStore == nil { return }; if err := scopedStore.Set("config", "colour", "blue"); err != nil { return }` type ScopedStore struct { - store *Store - namespace string - MaxKeys int - MaxGroups int + backingStore *Store + namespace string + MaxKeys int + MaxGroups int } func (scopedStore *ScopedStore) storeInstance(operation string) (*Store, error) { if scopedStore == nil { return nil, core.E(operation, "scoped store is nil", nil) } - if scopedStore.store == nil { + if scopedStore.backingStore == nil { return nil, core.E(operation, "underlying store is nil", nil) } - if err := scopedStore.store.ensureReady(operation); err != nil { + if err := scopedStore.backingStore.ensureReady(operation); err != nil { return nil, err } - return scopedStore.store, nil + return scopedStore.backingStore, nil } // Usage example: `scopedStore := store.NewScoped(storeInstance, "tenant-a")` @@ -50,7 +50,7 @@ func NewScoped(storeInstance *Store, namespace string) *ScopedStore { if !validNamespace.MatchString(namespace) { return nil } - scopedStore := &ScopedStore{store: storeInstance, namespace: namespace} + scopedStore := &ScopedStore{backingStore: storeInstance, namespace: namespace} return scopedStore } @@ -308,7 +308,7 @@ func (scopedStore *ScopedStore) checkQuota(operation, group, key string) error { namespacePrefix := scopedStore.namespacePrefix() // Check if this is an upsert (key already exists) — upserts never exceed quota. - _, err := scopedStore.store.Get(namespacedGroup, key) + _, err := scopedStore.backingStore.Get(namespacedGroup, key) if err == nil { // Key exists — this is an upsert, no quota check needed. return nil @@ -320,7 +320,7 @@ func (scopedStore *ScopedStore) checkQuota(operation, group, key string) error { // Check MaxKeys quota. if scopedStore.MaxKeys > 0 { - keyCount, err := scopedStore.store.CountAll(namespacePrefix) + keyCount, err := scopedStore.backingStore.CountAll(namespacePrefix) if err != nil { return core.E(operation, "quota check", err) } @@ -331,14 +331,14 @@ func (scopedStore *ScopedStore) checkQuota(operation, group, key string) error { // Check MaxGroups quota — only if this would create a new group. if scopedStore.MaxGroups > 0 { - existingGroupCount, err := scopedStore.store.Count(namespacedGroup) + existingGroupCount, err := scopedStore.backingStore.Count(namespacedGroup) if err != nil { return core.E(operation, "quota check", err) } if existingGroupCount == 0 { // This group is new — check if adding it would exceed the group limit. knownGroupCount := 0 - for _, iterationErr := range scopedStore.store.GroupsSeq(namespacePrefix) { + for _, iterationErr := range scopedStore.backingStore.GroupsSeq(namespacePrefix) { if iterationErr != nil { return core.E(operation, "quota check", iterationErr) } diff --git a/workspace.go b/workspace.go index 84c1a04..c4ee38c 100644 --- a/workspace.go +++ b/workspace.go @@ -35,7 +35,7 @@ var defaultWorkspaceStateDirectory = ".core/state" // Usage example: `workspace, err := storeInstance.NewWorkspace("scroll-session-2026-03-30"); if err != nil { return }; defer workspace.Discard()` type Workspace struct { name string - store *Store + backingStore *Store database *sql.DB databasePath string filesystem *core.Fs @@ -48,7 +48,7 @@ func (workspace *Workspace) ensureReady(operation string) error { if workspace == nil { return core.E(operation, "workspace is nil", nil) } - if workspace.store == nil { + if workspace.backingStore == nil { return core.E(operation, "workspace store is nil", nil) } if workspace.database == nil { @@ -57,7 +57,7 @@ func (workspace *Workspace) ensureReady(operation string) error { if workspace.filesystem == nil { return core.E(operation, "workspace filesystem is nil", nil) } - if err := workspace.store.ensureReady(operation); err != nil { + if err := workspace.backingStore.ensureReady(operation); err != nil { return err } @@ -98,7 +98,7 @@ func (storeInstance *Store) NewWorkspace(name string) (*Workspace, error) { return &Workspace{ name: name, - store: storeInstance, + backingStore: storeInstance, database: workspaceDatabase, databasePath: databasePath, filesystem: filesystem, @@ -156,7 +156,7 @@ func (storeInstance *Store) RecoverOrphans(stateDirectory string) []*Workspace { } workspaces = append(workspaces, &Workspace{ name: name, - store: storeInstance, + backingStore: storeInstance, database: workspaceDatabase, databasePath: databasePath, filesystem: filesystem, @@ -231,7 +231,7 @@ func (workspace *Workspace) Commit() core.Result { if err != nil { return core.Result{Value: core.E("store.Workspace.Commit", "aggregate workspace", err), OK: false} } - if err := workspace.store.commitWorkspaceAggregate(workspace.name, fields); err != nil { + if err := workspace.backingStore.commitWorkspaceAggregate(workspace.name, fields); err != nil { return core.Result{Value: err, OK: false} } if err := workspace.closeAndDelete(); err != nil { -- 2.45.3