storage

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenDB

func OpenDB(path string) (*sql.DB, error)

OpenDB opens (or creates) a SQLite file at the given path, configures WAL mode and foreign keys, and applies migrations via goose.

Types

type CachedTaskStore

type CachedTaskStore struct {
	model.TaskStore
	// contains filtered or unexported fields
}

CachedTaskStore is a decorator over model.TaskStore that caches ListProjects in memory. The cache is reset by an explicit Invalidate() call; write methods in transactions (CreateProjectTx/UpdateProjectTx) do not touch the cache — otherwise a concurrent ListProjects between invalidate() and tx.Commit() could cache the pre-commit state and return a stale list until the next invalidation. The use case must call Invalidate() after tx.Commit().

Used to serve frequent agent requests (injecting the project list into the system prompt) without extra database round-trips.

func NewCachedTaskStore

func NewCachedTaskStore(inner model.TaskStore) *CachedTaskStore

NewCachedTaskStore wraps inner and returns a cached decorator.

func (*CachedTaskStore) Invalidate

func (s *CachedTaskStore) Invalidate()

Invalidate resets the cache. The use case must call this method AFTER a successful tx.Commit() for operations that change the project set — otherwise a race between invalidate and commit could leave a pre-commit state in the cache.

func (*CachedTaskStore) ListProjects

func (s *CachedTaskStore) ListProjects(ctx context.Context) ([]model.Project, error)

ListProjects returns the project list from the cache; on the first call (or after invalidation) fetches from the underlying store. Errors are not cached.

type SQLiteForwardBuffer added in v0.6.0

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

SQLiteForwardBuffer implements model.ForwardBuffer using a SQLite table.

func NewSQLiteForwardBuffer added in v0.6.0

func NewSQLiteForwardBuffer(db *sql.DB) *SQLiteForwardBuffer

NewSQLiteForwardBuffer creates a new SQLiteForwardBuffer backed by db.

func (*SQLiteForwardBuffer) Append added in v0.6.0

Append inserts a forward entry into the buffer. Duplicate (ChatID, MessageID) pairs are silently ignored (INSERT OR IGNORE).

func (*SQLiteForwardBuffer) DeleteBatchTx added in v0.6.0

func (b *SQLiteForwardBuffer) DeleteBatchTx(ctx context.Context, tx *sql.Tx, chatID string) error

DeleteBatchTx deletes all entries for the given chat within the provided transaction.

func (*SQLiteForwardBuffer) LastReceivedAt added in v0.6.0

func (b *SQLiteForwardBuffer) LastReceivedAt(ctx context.Context, chatID string) (time.Time, bool, error)

LastReceivedAt returns the maximum ReceivedAt for the given chat. Returns zero time and false when the chat has no entries.

func (*SQLiteForwardBuffer) ListPendingChats added in v0.6.0

func (b *SQLiteForwardBuffer) ListPendingChats(ctx context.Context, before time.Time) ([]string, error)

ListPendingChats returns chat IDs whose MAX(received_at) is strictly before the given threshold.

func (*SQLiteForwardBuffer) LoadBatch added in v0.6.0

func (b *SQLiteForwardBuffer) LoadBatch(ctx context.Context, chatID string) ([]model.ForwardEntry, error)

LoadBatch returns all entries for the given chat ordered by OriginalDate ASC, id ASC.

type SQLiteGuardStore

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

SQLiteGuardStore implements model.GuardStore on top of SQLite.

func NewSQLiteGuardStore

func NewSQLiteGuardStore(db *sql.DB) *SQLiteGuardStore

NewSQLiteGuardStore creates a new SQLiteGuardStore.

func (*SQLiteGuardStore) DeletePending

func (s *SQLiteGuardStore) DeletePending(ctx context.Context, chatID int64) error

DeletePending removes the pending record for a chat.

func (*SQLiteGuardStore) ListPending

func (s *SQLiteGuardStore) ListPending(ctx context.Context) ([]model.GuardPending, error)

ListPending returns all pending approval records.

func (*SQLiteGuardStore) UpsertPending

func (s *SQLiteGuardStore) UpsertPending(ctx context.Context, chatID int64, welcomeMsgID int, deadline time.Time) error

UpsertPending saves or updates a pending approval record.

type SQLiteHistory

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

SQLiteHistory implements model.History on top of SQLite.

func NewSQLiteHistory

func NewSQLiteHistory(db *sql.DB, opts SQLiteHistoryOptions) *SQLiteHistory

NewSQLiteHistory creates a new SQLiteHistory with the given database and options.

func (*SQLiteHistory) Add

func (h *SQLiteHistory) Add(ctx context.Context, source string, entry model.HistoryEntry) error

Add adds a record to the history for the given source. After insertion, removes stale (TTL) and excess (MaxMessages) records. All operations run in a single transaction for consistency.

func (*SQLiteHistory) AddTx added in v0.7.0

func (h *SQLiteHistory) AddTx(ctx context.Context, tx *sql.Tx, source string, entry model.HistoryEntry) (string, error)

AddTx inserts a history record within the caller-owned transaction. Returns the generated messageID (UUID v4). TTL and MaxMessages cleanup are not performed — use Add for standalone writes that need cleanup.

func (*SQLiteHistory) Recent

func (h *SQLiteHistory) Recent(ctx context.Context, source string, limit int) ([]model.HistoryEntry, error)

Recent returns the last limit records from the given source in chronological order.

func (*SQLiteHistory) RecentActivity

func (h *SQLiteHistory) RecentActivity(ctx context.Context, source string, silenceGap time.Duration, fallbackLimit int) ([]model.HistoryEntry, error)

RecentActivity returns records from the most recent activity wave: searches for a stretch of records after a pause >= silenceGap (from end to start). If no pause is found, returns the last fallbackLimit records.

type SQLiteHistoryOptions

type SQLiteHistoryOptions struct {
	// MaxMessages is the maximum number of messages per source (0 = no limit).
	MaxMessages int
	// TTL is the record lifetime (0 = no limit).
	TTL time.Duration
}

SQLiteHistoryOptions holds configuration for SQLiteHistory.

type SQLiteMetaStore

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

SQLiteMetaStore implements model.MetaStore on top of SQLite. Supports keys of the form "project:<channelID>", mapped to the channel_projects table.

func NewSQLiteMetaStore

func NewSQLiteMetaStore(db *sql.DB) *SQLiteMetaStore

NewSQLiteMetaStore creates a new SQLiteMetaStore with the given database.

func (*SQLiteMetaStore) Get

func (s *SQLiteMetaStore) Get(ctx context.Context, key string) (string, error)

Get returns the value for the given key. Returns "", nil if the key is not found. Supported key format: "project:<channelID>".

func (*SQLiteMetaStore) SetTx

func (s *SQLiteMetaStore) SetTx(ctx context.Context, tx *sql.Tx, key, value string) error

SetTx sets the value for the given key within the given transaction. Supported key format: "project:<channelID>".

func (*SQLiteMetaStore) Values

func (s *SQLiteMetaStore) Values(ctx context.Context, prefix string) ([]string, error)

Values returns all values whose keys start with the given prefix. Returns nil, nil if no matching keys are found. Supported prefix: "project:".

type SQLiteStateStore

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

SQLiteStateStore implements model.StateStore on top of SQLite.

func NewSQLiteStateStore

func NewSQLiteStateStore(db *sql.DB) *SQLiteStateStore

NewSQLiteStateStore creates a new SQLiteStateStore with the given database.

func (*SQLiteStateStore) GetCursor

func (s *SQLiteStateStore) GetCursor(ctx context.Context, channelID string) (*model.Cursor, error)

GetCursor returns the saved cursor for a channel. Returns nil, nil if no cursor is found.

func (*SQLiteStateStore) SaveCursor

func (s *SQLiteStateStore) SaveCursor(ctx context.Context, channelID string, cursor model.Cursor) error

SaveCursor saves the cursor for a channel, overwriting any existing one.

type SQLiteTaskStore

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

SQLiteTaskStore implements model.TaskStore on top of SQLite.

func NewSQLiteTaskStore

func NewSQLiteTaskStore(db *sql.DB) (*SQLiteTaskStore, error)

NewSQLiteTaskStore creates a new SQLiteTaskStore and ensures the "Inbox" project exists as the default.

func (*SQLiteTaskStore) AddProjectAliasTx added in v0.3.0

func (s *SQLiteTaskStore) AddProjectAliasTx(ctx context.Context, tx *sql.Tx, projectID, alias string) error

AddProjectAliasTx inserts an alias for the project within the given transaction.

func (*SQLiteTaskStore) CreateProjectTx

func (s *SQLiteTaskStore) CreateProjectTx(ctx context.Context, tx *sql.Tx, p *model.Project) error

CreateProjectTx creates a new project within the given transaction. Requires p.Slug != "". Populates ID, TaskCounter, and CreatedAt in the passed struct.

func (*SQLiteTaskStore) CreateTaskTx

func (s *SQLiteTaskStore) CreateTaskTx(ctx context.Context, tx *sql.Tx, task *model.Task) error

CreateTaskTx creates a new task within the given transaction. Atomically increments the project's task_counter and assigns the number to the task. Populates ID, Number, Status, CreatedAt, UpdatedAt.

func (*SQLiteTaskStore) DefaultProjectID

func (s *SQLiteTaskStore) DefaultProjectID() string

DefaultProjectID returns the UUID of the "Inbox" project.

func (*SQLiteTaskStore) DeleteTaskTx added in v0.7.0

func (s *SQLiteTaskStore) DeleteTaskTx(ctx context.Context, tx *sql.Tx, id string) error

DeleteTaskTx physically deletes a task row by id within the given transaction.

func (*SQLiteTaskStore) FindProjectByName

func (s *SQLiteTaskStore) FindProjectByName(ctx context.Context, name string) (*model.Project, error)

FindProjectByName finds a project by name. Returns nil, nil if not found.

func (*SQLiteTaskStore) GetProject

func (s *SQLiteTaskStore) GetProject(ctx context.Context, id string) (*model.Project, error)

GetProject returns a project by UUID. Returns nil, nil if not found.

func (*SQLiteTaskStore) GetProjectTx

func (s *SQLiteTaskStore) GetProjectTx(ctx context.Context, tx *sql.Tx, id string) (*model.Project, error)

GetProjectTx reads a project by UUID within the given transaction.

func (*SQLiteTaskStore) GetTask

func (s *SQLiteTaskStore) GetTask(ctx context.Context, id string) (*model.Task, error)

GetTask returns a task by UUID. Returns nil, nil if not found.

func (*SQLiteTaskStore) GetTaskByRef

func (s *SQLiteTaskStore) GetTaskByRef(ctx context.Context, projectSlug string, number int) (*model.Task, error)

GetTaskByRef finds a task by its human-readable reference (project slug + number). Returns nil, nil if not found.

func (*SQLiteTaskStore) GetTaskTx

func (s *SQLiteTaskStore) GetTaskTx(ctx context.Context, tx *sql.Tx, id string) (*model.Task, error)

GetTaskTx reads a task by UUID within the given transaction.

func (*SQLiteTaskStore) ListAliasesForProject added in v0.3.0

func (s *SQLiteTaskStore) ListAliasesForProject(ctx context.Context, projectID string) ([]string, error)

ListAliasesForProject returns the aliases for a project sorted lexicographically.

func (*SQLiteTaskStore) ListClosedOlderThan added in v0.7.0

func (s *SQLiteTaskStore) ListClosedOlderThan(ctx context.Context, cutoff time.Time) ([]model.Task, error)

ListClosedOlderThan returns full snapshots of tasks with status "done"/"cancelled" whose closed_at is strictly before cutoff. Tasks without closed_at are skipped — their close time is unknown.

func (*SQLiteTaskStore) ListProjects

func (s *SQLiteTaskStore) ListProjects(ctx context.Context) ([]model.Project, error)

ListProjects returns all projects ordered by created_at, with their aliases.

func (*SQLiteTaskStore) ListTasks

func (s *SQLiteTaskStore) ListTasks(ctx context.Context, projectID string, filter model.TaskFilter) ([]model.Task, error)

ListTasks returns tasks matching the filter. projectID="" means all projects.

func (*SQLiteTaskStore) MoveTaskTx

func (s *SQLiteTaskStore) MoveTaskTx(ctx context.Context, tx *sql.Tx, taskID, newProjectID string) error

MoveTaskTx moves a task to another project within the given transaction. Atomically increments the target project's task_counter and assigns the task a new number. The source project's counter is not rolled back.

func (*SQLiteTaskStore) RemoveProjectAliasTx added in v0.3.0

func (s *SQLiteTaskStore) RemoveProjectAliasTx(ctx context.Context, tx *sql.Tx, projectID, alias string) error

RemoveProjectAliasTx deletes an alias within the given transaction. Returns nil when the alias does not exist (callers pre-validate membership).

func (*SQLiteTaskStore) UpdateProjectTx

func (s *SQLiteTaskStore) UpdateProjectTx(ctx context.Context, tx *sql.Tx, id string, upd model.ProjectUpdate) error

UpdateProjectTx applies changes to a project within the given transaction. Returns an error if the project is not found.

func (*SQLiteTaskStore) UpdateTaskTx

func (s *SQLiteTaskStore) UpdateTaskTx(ctx context.Context, tx *sql.Tx, id string, update model.TaskUpdate) error

UpdateTaskTx applies changes to a task within the given transaction. Returns an error if the task is not found.

type SQLiteVoiceQueue added in v0.6.1

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

SQLiteVoiceQueue implements model.VoiceQueue backed by the voice_queue table.

func NewSQLiteVoiceQueue added in v0.6.1

func NewSQLiteVoiceQueue(db *sql.DB) *SQLiteVoiceQueue

NewSQLiteVoiceQueue creates a new SQLiteVoiceQueue backed by db.

func (*SQLiteVoiceQueue) Claim added in v0.6.1

func (q *SQLiteVoiceQueue) Claim(ctx context.Context, now time.Time) (*model.VoiceJob, error)

Claim returns the first job with next_attempt_at <= now, ordered by id ASC. Returns nil, nil when the queue is empty or no job is due.

func (*SQLiteVoiceQueue) Complete added in v0.6.1

func (q *SQLiteVoiceQueue) Complete(ctx context.Context, id int64) error

Complete permanently removes a job from the queue.

func (*SQLiteVoiceQueue) Enqueue added in v0.6.1

func (q *SQLiteVoiceQueue) Enqueue(ctx context.Context, job model.VoiceJob) error

Enqueue inserts a voice job. For telegram jobs, duplicate (chat_id, message_id) pairs are silently ignored via the partial unique index. For client jobs, duplicate client_job_id values are silently ignored.

func (*SQLiteVoiceQueue) HasClientPayload added in v0.7.0

func (q *SQLiteVoiceQueue) HasClientPayload(ctx context.Context, payload string) (bool, error)

HasClientPayload reports whether a client voice upload file (identified by its relative path within uploads_dir) still has an active row in voice_queue. Implements events.VoiceOrphanChecker — used by the retention runner sweep.

func (*SQLiteVoiceQueue) Reschedule added in v0.6.1

func (q *SQLiteVoiceQueue) Reschedule(ctx context.Context, id int64, nextAt time.Time, lastErr string) error

Reschedule increments attempts, records the last error, and updates next_attempt_at.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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