diff --git a/CLAUDE.md b/CLAUDE.md index cb16a2b..914e99c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -11,6 +11,7 @@ SQLite key-value store with TTL, namespace isolation, and reactive events. Pure - Prefer descriptive names over abbreviations. - Public comments should show real usage with concrete values. - Keep examples in UK English. +- Prefer `StoreConfig` and `ScopedStoreConfig` literals over option chains when the configuration is already known. - Do not add compatibility aliases; the primary API names are the contract. - Preserve the single-connection SQLite design. - Verify with `go test ./...`, `go test -race ./...`, and `go vet ./...` before committing. @@ -71,20 +72,37 @@ func main() { } defer storeInstance.Close() - if err := storeInstance.Set("group", "key", "value"); err != nil { + configuredStore, err := store.NewConfigured(store.StoreConfig{ + DatabasePath: ":memory:", + Journal: store.JournalConfiguration{ + EndpointURL: "http://127.0.0.1:8086", + Organisation: "core", + BucketName: "events", + }, + PurgeInterval: 30 * time.Second, + }) + if err != nil { return } - value, err := storeInstance.Get("group", "key") + defer configuredStore.Close() + + if err := configuredStore.Set("group", "key", "value"); err != nil { + return + } + value, err := configuredStore.Get("group", "key") if err != nil { return } fmt.Println(value) - if err := storeInstance.SetWithTTL("session", "token", "abc123", 5*time.Minute); err != nil { + if err := configuredStore.SetWithTTL("session", "token", "abc123", 5*time.Minute); err != nil { return } - scopedStore, err := store.NewScoped(storeInstance, "tenant") + scopedStore, err := store.NewScopedConfigured(configuredStore, store.ScopedStoreConfig{ + Namespace: "tenant", + Quota: store.QuotaConfig{MaxKeys: 100, MaxGroups: 10}, + }) if err != nil { return } @@ -92,23 +110,15 @@ func main() { return } - quotaScopedStore, err := store.NewScopedWithQuota(storeInstance, "tenant", store.QuotaConfig{MaxKeys: 100, MaxGroups: 10}) - if err != nil { - return - } - if err := quotaScopedStore.SetIn("prefs", "locale", "en-GB"); err != nil { - return - } - - events := storeInstance.Watch("group") - defer storeInstance.Unwatch("group", events) + events := configuredStore.Watch("group") + defer configuredStore.Unwatch("group", events) go func() { for event := range events { fmt.Println(event.Type, event.Group, event.Key, event.Value) } }() - unregister := storeInstance.OnChange(func(event store.Event) { + unregister := configuredStore.OnChange(func(event store.Event) { fmt.Println("changed", event.Group, event.Key, event.Value) }) defer unregister() diff --git a/CODEX.md b/CODEX.md index 1ee757f..f163ed7 100644 --- a/CODEX.md +++ b/CODEX.md @@ -8,6 +8,7 @@ Keep the two files aligned. - Prefer descriptive names over abbreviations. - Public comments should show real usage with concrete values. - Keep examples in UK English. +- Prefer `StoreConfig` and `ScopedStoreConfig` literals over option chains when the configuration is already known. - Do not add compatibility aliases; the primary API names are the contract. - Preserve the single-connection SQLite design. - Verify with `go test ./...`, `go test -race ./...`, and `go vet ./...` before committing. diff --git a/README.md b/README.md index f81b42d..1749a84 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,11 @@ func main() { // Configure a persistent store with "/tmp/go-store.db", or use ":memory:" for ephemeral data. storeInstance, err := store.NewConfigured(store.StoreConfig{ DatabasePath: "/tmp/go-store.db", + Journal: store.JournalConfiguration{ + EndpointURL: "http://127.0.0.1:8086", + Organisation: "core", + BucketName: "events", + }, PurgeInterval: 30 * time.Second, }) if err != nil { @@ -55,8 +60,11 @@ func main() { }() // Store tenant-42 preferences under the "tenant-42:" prefix. - scopedStore := store.NewScoped(storeInstance, "tenant-42") - if scopedStore == nil { + scopedStore, err := store.NewScopedConfigured(storeInstance, store.ScopedStoreConfig{ + Namespace: "tenant-42", + Quota: store.QuotaConfig{MaxKeys: 100, MaxGroups: 10}, + }) + if err != nil { return } if err := scopedStore.SetIn("preferences", "locale", "en-GB"); err != nil {