Documentation
¶
Overview ¶
Package opstate provides a namespaced key-value store for persistent operational state. It is intended for lightweight data that needs to survive restarts — poller high-water marks, feature toggles, session preferences — not for structured domain data that deserves its own schema (contacts, conversations, facts). Those get their own stores.
Index ¶
- type Store
- func (s *Store) Close() error
- func (s *Store) Delete(namespace, key string) error
- func (s *Store) DeleteExpired(ctx context.Context) (int64, error)
- func (s *Store) DeleteNamespace(namespace string) error
- func (s *Store) Get(namespace, key string) (string, error)
- func (s *Store) List(namespace string) (map[string]string, error)
- func (s *Store) Set(namespace, key, value string) error
- func (s *Store) SetWithTTL(namespace, key, value string, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a namespaced key-value store backed by SQLite. All public methods are safe for concurrent use (SQLite serializes writes).
func NewStore ¶
NewStore creates an operational state store at the given database path. The schema is created automatically on first use.
func (*Store) Delete ¶
Delete removes a namespace/key entry. No error is returned if the key does not exist.
func (*Store) DeleteExpired ¶ added in v0.8.0
DeleteExpired removes all rows whose expires_at timestamp has passed. Returns the number of rows deleted. This is best-effort cleanup — expired rows are already invisible to [Get] and [List]. The context allows callers to bound execution time or cancel during shutdown.
func (*Store) DeleteNamespace ¶ added in v0.7.1
DeleteNamespace removes all entries for a namespace. No error is returned if the namespace has no entries.
func (*Store) Get ¶
Get returns the stored value for a namespace/key pair. Returns empty string and nil error if the key does not exist or has expired.
func (*Store) List ¶
List returns all non-expired key/value pairs for a namespace. Returns an empty (non-nil) map if the namespace has no live entries.
func (*Store) Set ¶
Set upserts a namespace/key/value triple. Existing values are overwritten and the updated_at timestamp is refreshed. The key never expires (expires_at is cleared on upsert).
func (*Store) SetWithTTL ¶ added in v0.8.0
SetWithTTL upserts a namespace/key/value triple that expires after the given duration. Expired keys are filtered out by [Get] and [List] and periodically removed by [DeleteExpired].