stores

package
v0.33.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error is a "not found" error.

func MigrateFromJSON

func MigrateFromJSON(ctx context.Context, database *db.DB, dataDir string) error

MigrateFromJSON migrates data from JSON files to SQLite if conditions are met: - sessions.json exists - Database has no sessions Skips migration if DB already populated to avoid duplicates.

Types

type KVStore

type KVStore struct {
	// contains filtered or unexported fields
}

KVStore implements kv.KV using SQLite.

func NewKVStore

func NewKVStore(db *db.DB) *KVStore

NewKVStore creates a new SQLite-backed KV store.

func (*KVStore) Delete

func (s *KVStore) Delete(ctx context.Context, key string) error

Delete removes a key.

func (*KVStore) Get

func (s *KVStore) Get(ctx context.Context, key string, dest any) error

Get retrieves and deserializes a value by key. Returns an error wrapping sql.ErrNoRows if the key does not exist. Expired entries are lazily deleted and treated as missing.

func (*KVStore) GetRaw

func (s *KVStore) GetRaw(ctx context.Context, key string) (kv.Entry, error)

GetRaw retrieves a raw KV entry with metadata. Returns an error wrapping sql.ErrNoRows if the key does not exist.

func (*KVStore) Has

func (s *KVStore) Has(ctx context.Context, key string) (bool, error)

Has returns whether a key exists (and is not expired).

func (*KVStore) ListKeys

func (s *KVStore) ListKeys(ctx context.Context) ([]string, error)

ListKeys returns all non-expired keys in sorted order.

func (*KVStore) Set

func (s *KVStore) Set(ctx context.Context, key string, value any) error

Set stores a value with no expiry.

func (*KVStore) SetTTL

func (s *KVStore) SetTTL(ctx context.Context, key string, value any, ttl time.Duration) error

SetTTL stores a value that expires after the given duration.

func (*KVStore) SweepExpired

func (s *KVStore) SweepExpired(ctx context.Context) error

SweepExpired deletes all entries whose TTL has passed.

type MessageStore

type MessageStore struct {
	// contains filtered or unexported fields
}

MessageStore implements messaging.Store using SQLite.

func NewMessageStore

func NewMessageStore(db *db.DB, maxMessages int) *MessageStore

NewMessageStore creates a new SQLite-backed message store. maxMessages controls retention per topic (0 = unlimited).

func (*MessageStore) Acknowledge

func (m *MessageStore) Acknowledge(ctx context.Context, consumerID string, messageIDs []string) error

Acknowledge marks messages as read by a consumer.

func (*MessageStore) GetUnread

func (m *MessageStore) GetUnread(ctx context.Context, consumerID string, topic string) ([]messaging.Message, error)

GetUnread returns messages not yet acknowledged by consumer. Supports wildcard topic patterns.

func (*MessageStore) List

func (m *MessageStore) List(ctx context.Context) ([]string, error)

List returns all topic names.

func (*MessageStore) Prune

func (m *MessageStore) Prune(ctx context.Context, olderThan time.Duration) (int, error)

Prune removes messages older than the given duration across all topics. Returns the number of messages removed.

func (*MessageStore) Publish

func (m *MessageStore) Publish(ctx context.Context, msg messaging.Message, topics []string) error

Publish adds a message to multiple topics. Wildcards are expanded before publishing. Enforces retention limit by deleting oldest messages if needed. All topics are published atomically within a single transaction.

func (*MessageStore) Subscribe

func (m *MessageStore) Subscribe(ctx context.Context, topic string, since time.Time) ([]messaging.Message, error)

Subscribe returns all messages for a topic pattern, optionally filtered by since timestamp. The topic parameter supports wildcards:

  • "*" or "" returns messages from all topics
  • "prefix.*" matches topics starting with "prefix."

Returns ErrTopicNotFound if no matching topics exist.

type NotifyStore

type NotifyStore struct {
	// contains filtered or unexported fields
}

NotifyStore implements notify.Store using SQLite.

func NewNotifyStore

func NewNotifyStore(db *db.DB) *NotifyStore

NewNotifyStore creates a new SQLite-backed notification store.

func (*NotifyStore) Clear

func (s *NotifyStore) Clear(ctx context.Context) error

Clear deletes all notifications.

func (*NotifyStore) Count

func (s *NotifyStore) Count(ctx context.Context) (int64, error)

Count returns the total number of notifications.

func (*NotifyStore) List

func (s *NotifyStore) List(ctx context.Context) ([]notify.Notification, error)

List returns all notifications ordered by newest first.

func (*NotifyStore) Save

Save persists a notification and returns its auto-generated ID.

type ReviewStore

type ReviewStore struct {
	// contains filtered or unexported fields
}

ReviewStore implements review.Store using SQLite.

func NewReviewStore

func NewReviewStore(db *db.DB) *ReviewStore

NewReviewStore creates a new SQLite-backed review store.

func (*ReviewStore) CleanupStaleSessions

func (s *ReviewStore) CleanupStaleSessions(ctx context.Context, documentPath string, currentHash string) error

CleanupStaleSessions removes review sessions for a document with different content hash.

func (*ReviewStore) CreateSession

func (s *ReviewStore) CreateSession(ctx context.Context, documentPath string, contentHash string) (review.Session, error)

CreateSession creates a new review session for a document with content hash.

func (*ReviewStore) DeleteComment

func (s *ReviewStore) DeleteComment(ctx context.Context, commentID string) error

DeleteComment removes a specific comment.

func (*ReviewStore) DeleteSession

func (s *ReviewStore) DeleteSession(ctx context.Context, sessionID string) error

DeleteSession removes a review session and all associated comments.

func (*ReviewStore) FinalizeSession

func (s *ReviewStore) FinalizeSession(ctx context.Context, sessionID string) error

FinalizeSession marks a review session as finalized.

func (*ReviewStore) GetAllActiveSessionsWithCounts

func (s *ReviewStore) GetAllActiveSessionsWithCounts(ctx context.Context) (map[string]SessionInfo, error)

GetAllActiveSessionsWithCounts returns all active (non-finalized) sessions with comment counts. This is optimized for batch operations like the document picker.

func (*ReviewStore) GetSession

func (s *ReviewStore) GetSession(ctx context.Context, documentPath string) (review.Session, error)

GetSession returns the most recent review session for the given document.

func (*ReviewStore) GetSessionByHash

func (s *ReviewStore) GetSessionByHash(ctx context.Context, documentPath string, contentHash string) (review.Session, error)

GetSessionByHash returns a review session for the given document and content hash.

func (*ReviewStore) ListComments

func (s *ReviewStore) ListComments(ctx context.Context, sessionID string) ([]review.Comment, error)

ListComments returns all comments for a review session, sorted by start line.

func (*ReviewStore) SaveComment

func (s *ReviewStore) SaveComment(ctx context.Context, comment review.Comment) error

SaveComment adds a comment to a review session.

func (*ReviewStore) UpdateComment

func (s *ReviewStore) UpdateComment(ctx context.Context, comment review.Comment) error

UpdateComment updates the comment text for an existing comment.

type SessionFile

type SessionFile struct {
	Sessions []session.Session `json:"sessions"`
}

SessionFile is the root JSON structure for sessions.json

type SessionInfo

type SessionInfo struct {
	Session      review.Session
	CommentCount int
}

SessionInfo contains session data with comment count for efficient batch queries.

type SessionStore

type SessionStore struct {
	// contains filtered or unexported fields
}

SessionStore implements session.Store using SQLite.

func NewSessionStore

func NewSessionStore(db *db.DB) *SessionStore

NewSessionStore creates a new SQLite-backed session store.

func (*SessionStore) Delete

func (s *SessionStore) Delete(ctx context.Context, id string) error

Delete removes a session by ID. Returns ErrNotFound if not found.

func (*SessionStore) FindRecyclable

func (s *SessionStore) FindRecyclable(ctx context.Context, remote string) (session.Session, error)

FindRecyclable returns a recyclable session for the given remote. Returns ErrNoRecyclable if none available.

func (*SessionStore) Get

func (s *SessionStore) Get(ctx context.Context, id string) (session.Session, error)

Get returns a session by ID. Returns ErrNotFound if not found.

func (*SessionStore) List

func (s *SessionStore) List(ctx context.Context) ([]session.Session, error)

List returns all sessions.

func (*SessionStore) Save

func (s *SessionStore) Save(ctx context.Context, sess session.Session) error

Save creates or updates a session.

type TopicFile

type TopicFile struct {
	Topic    string              `json:"topic"`
	Messages []messaging.Message `json:"messages"`
}

TopicFile is the root JSON structure for per-topic message files.

Jump to

Keyboard shortcuts

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