Help us shape the future of Go! Take the 2026 Go Developer Survey

store

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package store is hive.db persistence: one store per aggregate over the sqlc queries in store/db.

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 HCStore

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

HCStore implements hc.Store using SQLite.

func NewHCStore

func NewHCStore(database *db.DB) *HCStore

NewHCStore creates a new SQLite-backed HC store.

func (*HCStore) AddBlocker

func (s *HCStore) AddBlocker(ctx context.Context, blockerID, blockedID string) error

AddBlocker records that blockerID blocks blockedID. Cycle detection and the INSERT are performed inside a single transaction so no partial state is possible. Returns ErrCyclicDependency if the edge would create a cycle.

func (*HCStore) AddComment

func (s *HCStore) AddComment(ctx context.Context, c hc.Comment) error

AddComment records a comment on an HC item.

func (*HCStore) BulkUpdateStatus

func (s *HCStore) BulkUpdateStatus(ctx context.Context, epicID string, status hc.Status) error

BulkUpdateStatus sets the status of all non-terminal descendants of the given epic to the specified status. Items already in a terminal status are not modified.

func (*HCStore) CreateBulkWithEdges

func (s *HCStore) CreateBulkWithEdges(ctx context.Context, items []hc.Item, edges [][2]string) error

CreateBulkWithEdges creates items and wires their explicit blocker edges atomically. Cycle validation must be done by the caller; this method only enforces FK constraints.

func (*HCStore) CreateItems

func (s *HCStore) CreateItems(ctx context.Context, items []hc.Item) error

CreateItems persists one or more HC items atomically.

func (*HCStore) DeleteItem

func (s *HCStore) DeleteItem(ctx context.Context, id string) error

DeleteItem removes an HC item and all its descendants by ID.

func (*HCStore) Fingerprint

func (s *HCStore) Fingerprint(ctx context.Context) (hc.Fingerprint, error)

Fingerprint summarizes every hc table in one read.

func (*HCStore) GetItem

func (s *HCStore) GetItem(ctx context.Context, id string) (hc.Item, error)

GetItem retrieves a single HC item by ID.

func (*HCStore) ListBlockerEdges

func (s *HCStore) ListBlockerEdges(ctx context.Context) ([][2]string, error)

ListBlockerEdges returns all blocker edges as [blockerID, blockedID] pairs.

func (*HCStore) ListBlockers

func (s *HCStore) ListBlockers(ctx context.Context, itemID string) ([]string, error)

ListBlockers returns IDs of open/in_progress items that explicitly block the given item.

func (*HCStore) ListComments

func (s *HCStore) ListComments(ctx context.Context, itemID string) ([]hc.Comment, error)

ListComments returns all comments for the given item in chronological order.

func (*HCStore) ListItems

func (s *HCStore) ListItems(ctx context.Context, filter hc.ListFilter) ([]hc.Item, error)

ListItems returns HC items matching the given filter.

func (*HCStore) ListRepoKeys

func (s *HCStore) ListRepoKeys(ctx context.Context) ([]string, error)

ListRepoKeys returns all distinct, non-empty repo keys in sorted order.

func (*HCStore) NextItem

func (s *HCStore) NextItem(ctx context.Context, filter hc.NextFilter) (hc.Item, bool, error)

NextItem returns the next actionable item for the given filter. When filter.SessionID is set, it first tries to resume an in_progress task for that session before falling back to claiming an unassigned open task.

func (*HCStore) Prune

func (s *HCStore) Prune(ctx context.Context, opts hc.PruneOpts) (int, error)

Prune removes old done/cancelled items and their comments.

func (*HCStore) RemoveBlocker

func (s *HCStore) RemoveBlocker(ctx context.Context, blockerID, blockedID string) error

RemoveBlocker removes the explicit blocker relationship.

func (*HCStore) UpdateItem

func (s *HCStore) UpdateItem(ctx context.Context, id string, update hc.ItemUpdate) (hc.Item, error)

UpdateItem applies partial updates to an HC item.

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 kv.ErrNotFound 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 kv.ErrNotFound 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) (messaging.PublishResult, 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) 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 TodoStore

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

TodoStore implements todo.Store using SQLite.

func NewTodoStore

func NewTodoStore(logger zerolog.Logger, db *db.DB) *TodoStore

NewTodoStore creates a new SQLite-backed todo store.

func (*TodoStore) CountOpen

func (s *TodoStore) CountOpen(ctx context.Context) (int, error)

CountOpen returns the number of open (pending + acknowledged) todo items.

func (*TodoStore) CountPending

func (s *TodoStore) CountPending(ctx context.Context) (int, error)

CountPending returns the number of pending todo items.

func (*TodoStore) CountRecentBySession

func (s *TodoStore) CountRecentBySession(ctx context.Context, sessionID string, since time.Time) (int, error)

CountRecentBySession returns the number of todo items created by a session since the given time.

func (*TodoStore) Create

func (s *TodoStore) Create(ctx context.Context, t todo.Todo) error

Create persists a new todo item.

func (*TodoStore) Delete

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

Delete removes a todo item by ID.

func (*TodoStore) Get

func (s *TodoStore) Get(ctx context.Context, id string) (todo.Todo, error)

Get retrieves a single todo item by ID.

func (*TodoStore) List

func (s *TodoStore) List(ctx context.Context, filter todo.ListFilter) ([]todo.Todo, error)

List returns todo items matching the given filter.

func (*TodoStore) Update

func (s *TodoStore) Update(ctx context.Context, id string, status todo.Status) error

Update changes the status of a todo item.

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.

Directories

Path Synopsis
Package migrate is a small SQLite migration runner shared across hive's databases.
Package migrate is a small SQLite migration runner shared across hive's databases.

Jump to

Keyboard shortcuts

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