opstate

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

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

func NewStore(db *sql.DB) (*Store, error)

NewStore creates an operational state store using the given database connection. The caller owns the connection — Store does not close it. The schema is created automatically on first use.

func (*Store) Delete

func (s *Store) Delete(namespace, key string) error

Delete removes a namespace/key entry. No error is returned if the key does not exist.

func (*Store) DeleteExpired

func (s *Store) DeleteExpired(ctx context.Context) (int64, error)

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

func (s *Store) DeleteNamespace(namespace string) error

DeleteNamespace removes all entries for a namespace. No error is returned if the namespace has no entries.

func (*Store) Get

func (s *Store) Get(namespace, key string) (string, error)

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

func (s *Store) List(namespace string) (map[string]string, error)

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

func (s *Store) Set(namespace, key, value string) error

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

func (s *Store) SetWithTTL(namespace, key, value string, ttl time.Duration) error

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].

Jump to

Keyboard shortcuts

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