sqlite

package module
v0.0.0-...-3538748 Latest Latest
Warning

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

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

Documentation

Overview

Package sqlite provides SQLite storage implementation for the memory layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SQLiteStorage

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

SQLiteStorage implements Storage using SQLite with sqlite-vec and FTS5.

func InMemory

func InMemory() (*SQLiteStorage, error)

InMemory creates a new in-memory SQLite storage instance.

func NewSQLiteStorage

func NewSQLiteStorage(path string) (*SQLiteStorage, error)

NewSQLiteStorage creates a new file-based SQLite storage.

func NewSQLiteStorageWithDB

func NewSQLiteStorageWithDB(db *sql.DB) (*SQLiteStorage, error)

NewSQLiteStorageWithDB creates a new SQLiteStorage from an existing database connection. The caller retains ownership of the provided *sql.DB and is responsible for closing it. This is useful when integrating with existing connection pools or when the database connection needs to be shared across multiple components.

func (*SQLiteStorage) Close

func (s *SQLiteStorage) Close() error

Close releases the database connection. Note: When using NewSQLiteStorageWithDB, the caller retains ownership of the *sql.DB connection and Close() does not close it.

func (*SQLiteStorage) Forget

func (s *SQLiteStorage) Forget(ctx context.Context, id idx.ID) error

Forget deletes an observation by ID. All deletes (main table, FTS5, vec0) are wrapped in a transaction so that a partial failure does not leave the database in an inconsistent state.

func (*SQLiteStorage) GetByID

func (s *SQLiteStorage) GetByID(ctx context.Context, id idx.ID) (*adapter.Observation, error)

GetByID retrieves an observation by its ID.

func (*SQLiteStorage) IncrementTimesDerived

func (s *SQLiteStorage) IncrementTimesDerived(ctx context.Context, id idx.ID) error

IncrementTimesDerived increments the times_derived counter for an observation. Returns an error if the observation does not exist.

func (*SQLiteStorage) Purge

func (s *SQLiteStorage) Purge(ctx context.Context, filter map[string]string) error

Purge deletes observations matching the filter. At least one recognized filter key (session_id, user_id, app_name) must be provided; otherwise an error is returned to prevent accidental full deletion. Unrecognized filter keys are rejected to prevent silent partial matching. All deletes (main table, FTS5, vec0) are wrapped in a transaction so that a partial failure does not leave the database in an inconsistent state.

func (*SQLiteStorage) QueryMostDerived

func (s *SQLiteStorage) QueryMostDerived(ctx context.Context, sessionID, userID, appName string, limit int) ([]adapter.Observation, error)

QueryMostDerived returns observations sorted by times_derived DESC. Most-derived facts (referenced multiple times) are returned first.

func (*SQLiteStorage) QueryRecent

func (s *SQLiteStorage) QueryRecent(ctx context.Context, sessionID, userID, appName string, limit int) ([]adapter.Observation, error)

QueryRecent returns observations sorted by created_at DESC. Most recent observations are returned first.

func (*SQLiteStorage) Search

Search finds observations matching the given options.

func (*SQLiteStorage) Store

func (s *SQLiteStorage) Store(ctx context.Context, obs *adapter.Observation) error

Store saves an observation to storage. The insert into the main table, FTS5, and vec0 virtual tables is wrapped in a transaction so that a partial failure does not leave the database in an inconsistent state.

Jump to

Keyboard shortcuts

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