sqlite

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sqlite provides utility functions for SQLite database operations such as online backup and integrity verification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backup

func Backup(dbPath string) (backupPath string, err error)

Backup creates a safe online backup of a SQLite database using VACUUM INTO. VACUUM INTO produces a clean, defragmented copy of the database while allowing concurrent reads on the source. The backup file is named with a timestamp suffix (e.g., "loom.db.backup.20260224T153000"). On failure, any partially written backup file is removed before returning.

func VerifyBackup

func VerifyBackup(backupPath string) error

VerifyBackup opens a SQLite database file and runs PRAGMA integrity_check to confirm the file is a valid, uncorrupted SQLite database.

Types

type GraphMemoryOption added in v1.3.0

type GraphMemoryOption func(*GraphMemoryStore)

GraphMemoryOption configures a GraphMemoryStore.

func WithSalienceConfig added in v1.3.0

func WithSalienceConfig(cfg memory.SalienceConfig) GraphMemoryOption

WithSalienceConfig overrides the default salience configuration.

type GraphMemoryStore added in v1.3.0

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

GraphMemoryStore implements memory.GraphMemoryStore for SQLite.

func NewGraphMemoryStore added in v1.3.0

func NewGraphMemoryStore(db *sql.DB, tc memory.TokenCounter, tracer observability.Tracer, opts ...GraphMemoryOption) *GraphMemoryStore

NewGraphMemoryStore creates a new SQLite-backed graph memory store.

func (*GraphMemoryStore) Close added in v1.3.0

func (s *GraphMemoryStore) Close() error

func (*GraphMemoryStore) Consolidate added in v1.3.0

func (s *GraphMemoryStore) Consolidate(ctx context.Context, memoryIDs []string, consolidated *memory.Memory) (*memory.Memory, error)

func (*GraphMemoryStore) ContextFor added in v1.3.0

func (*GraphMemoryStore) CreateEntity added in v1.3.0

func (s *GraphMemoryStore) CreateEntity(ctx context.Context, entity *memory.Entity) (*memory.Entity, error)

func (*GraphMemoryStore) DecayAll added in v1.3.0

func (s *GraphMemoryStore) DecayAll(ctx context.Context, agentID string, decayFactor float64) error

func (*GraphMemoryStore) DeleteEntity added in v1.3.0

func (s *GraphMemoryStore) DeleteEntity(ctx context.Context, agentID, name string) error

func (*GraphMemoryStore) Forget added in v1.3.0

func (s *GraphMemoryStore) Forget(ctx context.Context, memoryID string) error

func (*GraphMemoryStore) GetEntity added in v1.3.0

func (s *GraphMemoryStore) GetEntity(ctx context.Context, agentID, name string) (*memory.Entity, error)

func (*GraphMemoryStore) GetLineage added in v1.3.0

func (s *GraphMemoryStore) GetLineage(ctx context.Context, memoryID string) ([]*memory.MemoryLineage, error)

func (*GraphMemoryStore) GetMemory added in v1.3.0

func (s *GraphMemoryStore) GetMemory(ctx context.Context, agentID, memoryID string) (*memory.Memory, error)

func (*GraphMemoryStore) GetStats added in v1.3.0

func (s *GraphMemoryStore) GetStats(ctx context.Context, agentID string) (*memory.GraphStats, error)

func (*GraphMemoryStore) ListEdgesFrom added in v1.3.0

func (s *GraphMemoryStore) ListEdgesFrom(ctx context.Context, entityID string) ([]*memory.Edge, error)

func (*GraphMemoryStore) ListEdgesTo added in v1.3.0

func (s *GraphMemoryStore) ListEdgesTo(ctx context.Context, entityID string) ([]*memory.Edge, error)

func (*GraphMemoryStore) ListEntities added in v1.3.0

func (s *GraphMemoryStore) ListEntities(ctx context.Context, agentID, entityType string, limit, offset int) ([]*memory.Entity, int, error)

func (*GraphMemoryStore) Neighbors added in v1.3.0

func (s *GraphMemoryStore) Neighbors(ctx context.Context, entityID string, relation string, direction string, depth int) ([]*memory.Edge, error)

func (*GraphMemoryStore) Recall added in v1.3.0

func (s *GraphMemoryStore) Recall(ctx context.Context, opts memory.RecallOpts) ([]*memory.Memory, error)

func (*GraphMemoryStore) Relate added in v1.3.0

func (s *GraphMemoryStore) Relate(ctx context.Context, edge *memory.Edge) (*memory.Edge, error)

func (*GraphMemoryStore) Remember added in v1.3.0

func (s *GraphMemoryStore) Remember(ctx context.Context, mem *memory.Memory) (*memory.Memory, error)

func (*GraphMemoryStore) SearchEntities added in v1.3.0

func (s *GraphMemoryStore) SearchEntities(ctx context.Context, agentID, query string, limit int) ([]*memory.Entity, error)

func (*GraphMemoryStore) Supersede added in v1.3.0

func (s *GraphMemoryStore) Supersede(ctx context.Context, oldMemoryID string, newMem *memory.Memory) (*memory.Memory, error)

func (*GraphMemoryStore) TouchMemories added in v1.3.0

func (s *GraphMemoryStore) TouchMemories(ctx context.Context, memoryIDs []string) error

func (*GraphMemoryStore) Unrelate added in v1.3.0

func (s *GraphMemoryStore) Unrelate(ctx context.Context, sourceID, targetID, relation string) error

func (*GraphMemoryStore) UpdateEntity added in v1.3.0

func (s *GraphMemoryStore) UpdateEntity(ctx context.Context, entity *memory.Entity) (*memory.Entity, error)

func (*GraphMemoryStore) VectorRecall added in v1.3.0

func (s *GraphMemoryStore) VectorRecall(ctx context.Context, opts memory.VectorRecallOpts) ([]*memory.Memory, error)

VectorRecall performs brute-force cosine similarity search over all memories with embeddings for the given agent. Returns memories sorted by similarity. This is O(n) and fine for <100K memories per agent. For larger scale, use PostgreSQL with pgvector HNSW index.

type Migration

type Migration struct {
	Version     int
	Description string
	UpSQL       string
	DownSQL     string
}

Migration represents a single database migration step.

type Migrator

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

Migrator manages SQLite schema migrations using embedded SQL files. Unlike the PostgreSQL migrator which uses advisory locks, this uses a sync.Mutex to prevent concurrent migration execution within the process.

func NewMigrator

func NewMigrator(db *sql.DB, tracer observability.Tracer) (*Migrator, error)

NewMigrator creates a new migrator with embedded SQL migrations. It sets PRAGMA busy_timeout = 5000 on the database to handle lock contention.

func (*Migrator) CurrentVersion

func (m *Migrator) CurrentVersion(ctx context.Context) (int, error)

CurrentVersion returns the highest applied migration version. Returns 0 if the schema_migrations table does not exist yet.

func (*Migrator) MigrateDown

func (m *Migrator) MigrateDown(ctx context.Context, steps int) error

MigrateDown rolls back the specified number of migrations.

func (*Migrator) MigrateUp

func (m *Migrator) MigrateUp(ctx context.Context) error

MigrateUp applies all pending migrations up to the latest version. Uses a sync.Mutex to prevent concurrent migration execution.

func (*Migrator) PendingMigrations

func (m *Migrator) PendingMigrations(ctx context.Context) ([]Migration, error)

PendingMigrations returns the list of migrations that have not yet been applied.

type TaskStore added in v1.3.0

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

TaskStore implements task.TaskStore for SQLite.

func NewTaskStore added in v1.3.0

func NewTaskStore(db *sql.DB, tracer observability.Tracer) *TaskStore

NewTaskStore creates a new SQLite-backed task store.

func (*TaskStore) AddDependency added in v1.3.0

func (s *TaskStore) AddDependency(ctx context.Context, dep *task.TaskDependency) error

func (*TaskStore) ClaimTask added in v1.3.0

func (s *TaskStore) ClaimTask(ctx context.Context, taskID, agentID, sessionID string) (*task.Task, error)

func (*TaskStore) Close added in v1.3.0

func (s *TaskStore) Close() error

Close closes the underlying database connection.

func (*TaskStore) CloseTask added in v1.3.0

func (s *TaskStore) CloseTask(ctx context.Context, taskID, reason string) (*task.Task, error)

func (*TaskStore) CreateBoard added in v1.3.0

func (s *TaskStore) CreateBoard(ctx context.Context, board *task.TaskBoard) (*task.TaskBoard, error)

func (*TaskStore) CreateTask added in v1.3.0

func (s *TaskStore) CreateTask(ctx context.Context, t *task.Task) (*task.Task, error)

func (*TaskStore) DeleteTask added in v1.3.0

func (s *TaskStore) DeleteTask(ctx context.Context, id string) error

func (*TaskStore) GetBlockedTasks added in v1.3.0

func (s *TaskStore) GetBlockedTasks(ctx context.Context, boardID string) ([]*task.Task, error)

func (*TaskStore) GetBoard added in v1.3.0

func (s *TaskStore) GetBoard(ctx context.Context, id string) (*task.TaskBoard, error)

func (*TaskStore) GetDependencies added in v1.3.0

func (s *TaskStore) GetDependencies(ctx context.Context, taskID string) ([]*task.TaskDependency, error)

func (*TaskStore) GetDependents added in v1.3.0

func (s *TaskStore) GetDependents(ctx context.Context, taskID string) ([]*task.TaskDependency, error)

func (*TaskStore) GetHistory added in v1.3.0

func (s *TaskStore) GetHistory(ctx context.Context, taskID string) ([]*task.TaskHistoryEntry, error)

func (*TaskStore) GetReadyFront added in v1.3.0

func (s *TaskStore) GetReadyFront(ctx context.Context, boardID string, opts task.ReadyFrontOpts) ([]*task.Task, error)

func (*TaskStore) GetTask added in v1.3.0

func (s *TaskStore) GetTask(ctx context.Context, id string) (*task.Task, error)

func (*TaskStore) GetTaskByIdempotencyKey added in v1.3.0

func (s *TaskStore) GetTaskByIdempotencyKey(ctx context.Context, key string) (*task.Task, error)

GetTaskByIdempotencyKey returns the task that owns the given idempotency key, or (nil, nil) when no such task exists. Used by the skills task emitter to dedupe concurrent skill activations.

func (*TaskStore) HasOpenSkillTasks added in v1.3.0

func (s *TaskStore) HasOpenSkillTasks(ctx context.Context, skillName, sessionID string) (bool, error)

HasOpenSkillTasks returns true when any task with skill_idempotency_key matching skill:<name>|sess:<sess>|% is still in flight (status not DONE and not CANCELLED). Soft-deleted tasks are excluded.

func (*TaskStore) ListBoards added in v1.3.0

func (s *TaskStore) ListBoards(ctx context.Context) ([]*task.TaskBoard, error)

func (*TaskStore) ListBySkillRun added in v1.3.0

func (s *TaskStore) ListBySkillRun(ctx context.Context, skillName, sessionID string) ([]*task.Task, error)

ListBySkillRun returns every non-deleted task whose skill_idempotency_key matches skill:<name>|sess:<sess>|%, regardless of status. Used by the end-of-turn hygiene auditor to inventory the active skill's tasks.

func (*TaskStore) ListTasks added in v1.3.0

func (s *TaskStore) ListTasks(ctx context.Context, opts task.ListTasksOpts) ([]*task.Task, int, error)

func (*TaskStore) RecordHistory added in v1.3.0

func (s *TaskStore) RecordHistory(ctx context.Context, entry *task.TaskHistoryEntry) error

func (*TaskStore) ReleaseTask added in v1.3.0

func (s *TaskStore) ReleaseTask(ctx context.Context, taskID, sessionID string) (*task.Task, error)

func (*TaskStore) RemoveDependency added in v1.3.0

func (s *TaskStore) RemoveDependency(ctx context.Context, fromTaskID, toTaskID string) error

func (*TaskStore) TransitionTask added in v1.3.0

func (s *TaskStore) TransitionTask(ctx context.Context, taskID string, newStatus loomv1.TaskStatus) (*task.Task, error)

func (*TaskStore) UpdateTask added in v1.3.0

func (s *TaskStore) UpdateTask(ctx context.Context, t *task.Task, _ []string) (*task.Task, error)

Jump to

Keyboard shortcuts

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