sqlite

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sqlite provides a SQLite-backed Storage adapter for Chronos.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option added in v0.4.0

type Option func(*poolConfig)

Option configures a Store's connection pool. SQLite defaults to a single open connection because it is single-writer; overrides are honored but rarely advisable for on-disk databases.

func WithConnMaxLifetime added in v0.4.0

func WithConnMaxLifetime(d time.Duration) Option

WithConnMaxLifetime sets the maximum lifetime of a connection.

func WithMaxIdleConns added in v0.4.0

func WithMaxIdleConns(n int) Option

WithMaxIdleConns sets the maximum number of idle connections.

func WithMaxOpenConns added in v0.4.0

func WithMaxOpenConns(n int) Option

WithMaxOpenConns sets the maximum number of open connections.

type Store

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

Store implements storage.Storage using SQLite.

func New

func New(dsn string, opts ...Option) (*Store, error)

New opens a SQLite database at the given DSN (file path or ":memory:").

func (*Store) AppendAuditLog

func (s *Store) AppendAuditLog(ctx context.Context, log *storage.AuditLog) error

func (*Store) AppendEvent

func (s *Store) AppendEvent(ctx context.Context, e *storage.Event) error

AppendEvent appends a ledger event. It is idempotent: re-appending an event with an existing id is a no-op, so replay/resume cannot error on the primary key or duplicate the ledger.

func (*Store) AppendEvents added in v0.4.0

func (s *Store) AppendEvents(ctx context.Context, events []*storage.Event) error

AppendEvents appends many events within one transaction. It is idempotent on event id (INSERT OR IGNORE). The batch is split into chunks so the per-statement bind-parameter count stays under sqliteMaxBindParams; all chunks run in the same transaction, so the whole batch still commits (or rolls back) atomically.

func (*Store) Close

func (s *Store) Close() error

func (*Store) CreateSession

func (s *Store) CreateSession(ctx context.Context, sess *storage.Session) error

func (*Store) DeleteFile added in v0.10.0

func (s *Store) DeleteFile(ctx context.Context, sessionID, path string) error

DeleteFile removes the session file at path; deleting a missing file is a no-op.

func (*Store) DeleteMemory

func (s *Store) DeleteMemory(ctx context.Context, id string) error

func (*Store) DeleteSession added in v0.15.0

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

DeleteSession permanently removes a session and all session-scoped records. Every delete is constrained by the context tenant, so a caller cannot remove another tenant's records even when both tenants use the same session ID.

func (*Store) GetCheckpoint

func (s *Store) GetCheckpoint(ctx context.Context, id string) (*storage.Checkpoint, error)

func (*Store) GetFile added in v0.10.0

func (s *Store) GetFile(ctx context.Context, sessionID, path string) ([]byte, error)

GetFile returns the content of the session file at path.

func (*Store) GetLatestCheckpoint

func (s *Store) GetLatestCheckpoint(ctx context.Context, sessionID string) (*storage.Checkpoint, error)

func (*Store) GetMemory

func (s *Store) GetMemory(ctx context.Context, agentID, key string) (*storage.MemoryRecord, error)

func (*Store) GetSession

func (s *Store) GetSession(ctx context.Context, id string) (*storage.Session, error)

func (*Store) GetTrace

func (s *Store) GetTrace(ctx context.Context, id string) (*storage.Trace, error)

func (*Store) InsertTrace

func (s *Store) InsertTrace(ctx context.Context, t *storage.Trace) error

func (*Store) InsertTraces added in v0.4.0

func (s *Store) InsertTraces(ctx context.Context, traces []*storage.Trace) error

InsertTraces inserts many trace spans within one transaction. As with AppendEvents the batch is chunked to respect sqliteMaxBindParams while keeping the whole insert atomic.

func (*Store) ListAuditLogs

func (s *Store) ListAuditLogs(ctx context.Context, sessionID string, limit, offset int) ([]*storage.AuditLog, error)

func (*Store) ListCheckpoints

func (s *Store) ListCheckpoints(ctx context.Context, sessionID string) ([]*storage.Checkpoint, error)

func (*Store) ListCheckpointsPaged added in v0.4.0

func (s *Store) ListCheckpointsPaged(ctx context.Context, sessionID string, limit int, cursor string) (*storage.CheckpointPage, error)

ListCheckpointsPaged returns a cursor-paginated page of checkpoints ordered by seq_num.

func (*Store) ListEvents

func (s *Store) ListEvents(ctx context.Context, sessionID string, afterSeq int64) ([]*storage.Event, error)

func (*Store) ListEventsPaged added in v0.4.0

func (s *Store) ListEventsPaged(ctx context.Context, sessionID string, afterSeq int64, limit int, cursor string) (*storage.EventPage, error)

ListEventsPaged returns a cursor-paginated page of events after afterSeq, ordered by seq_num. It fetches limit+1 rows to detect whether a further page exists, so the final page never carries a dangling cursor.

func (*Store) ListFiles added in v0.10.0

func (s *Store) ListFiles(ctx context.Context, sessionID, prefix string) ([]storage.FileInfo, error)

ListFiles returns metadata for every session file whose path has the given prefix, ordered by path.

func (*Store) ListMemory

func (s *Store) ListMemory(ctx context.Context, agentID, kind string) ([]*storage.MemoryRecord, error)

func (*Store) ListSessions

func (s *Store) ListSessions(ctx context.Context, agentID string, limit, offset int) ([]*storage.Session, error)

func (*Store) ListTraces

func (s *Store) ListTraces(ctx context.Context, sessionID string) ([]*storage.Trace, error)

func (*Store) ListTracesPaged added in v0.4.0

func (s *Store) ListTracesPaged(ctx context.Context, sessionID string, limit int, cursor string) (*storage.TracePage, error)

ListTracesPaged returns a cursor-paginated page of traces. It keysets on the stable primary key id (rather than the wall-clock started_at, whose text storage makes cross-timezone comparison unreliable), which gives a deterministic order across SQLite and Postgres.

func (*Store) Migrate

func (s *Store) Migrate(ctx context.Context) error

Migrate creates all required tables and indexes via the versioned migration framework. Migration v2 adds tenant scoping.

func (*Store) PutFile added in v0.10.0

func (s *Store) PutFile(ctx context.Context, sessionID, path string, content []byte) error

PutFile creates or overwrites the session file at path.

func (*Store) PutMemory

func (s *Store) PutMemory(ctx context.Context, m *storage.MemoryRecord) error

func (*Store) ReadSessionSummary added in v0.15.0

func (s *Store) ReadSessionSummary(ctx context.Context, sessionID string, maxBytes int) (text, source string, sourceSeq int64, truncated bool, err error)

ReadSessionSummary returns the latest nonempty chat_summary, or up to 32 recent user/assistant messages in chronological order when no summary exists. Text is valid UTF-8 and at most maxBytes bytes. Empty text with no error means no usable context (or a nonpositive budget). source is chat_summary or chat_message; sourceSeq is the latest selected event sequence. truncated reports omitted text or older fallback messages. All reads are scoped to the context tenant.

This additive capability deliberately uses built-in return types so consumers can detect it structurally without extending storage.Storage. SQL projects only bounded text and scalar metadata, never raw event payloads into Go.

func (*Store) SaveCheckpoint

func (s *Store) SaveCheckpoint(ctx context.Context, cp *storage.Checkpoint) error

SaveCheckpoint persists a checkpoint. It is idempotent: saving a checkpoint with an existing id overwrites it, so resuming/replaying a run cannot error on the primary key.

func (*Store) SaveCheckpointAndEvent added in v0.4.0

func (s *Store) SaveCheckpointAndEvent(ctx context.Context, cp *storage.Checkpoint, evt *storage.Event) error

SaveCheckpointAndEvent persists a checkpoint and its ledger event atomically in a single transaction, satisfying graph.CheckpointCommitter. A crash cannot leave the checkpoint and event ledger out of sync.

func (*Store) TrimAuditLogs added in v0.4.0

func (s *Store) TrimAuditLogs(ctx context.Context, olderThan time.Time) (int64, error)

TrimAuditLogs deletes audit logs created strictly before olderThan.

func (*Store) TrimCheckpoints added in v0.4.0

func (s *Store) TrimCheckpoints(ctx context.Context, sessionID string, keep int) (int64, error)

TrimCheckpoints keeps only the most recent keep checkpoints (by seq_num) for the session and deletes the rest.

func (*Store) TrimEvents added in v0.4.0

func (s *Store) TrimEvents(ctx context.Context, olderThan time.Time) (int64, error)

TrimEvents deletes events created strictly before olderThan.

func (*Store) TrimTraces added in v0.4.0

func (s *Store) TrimTraces(ctx context.Context, olderThan time.Time) (int64, error)

TrimTraces deletes traces started strictly before olderThan.

func (*Store) UpdateSession

func (s *Store) UpdateSession(ctx context.Context, sess *storage.Session) error

func (*Store) UpdateSessionStatus added in v0.13.0

func (s *Store) UpdateSessionStatus(ctx context.Context, sessionID, status string, updatedAt time.Time) error

UpdateSessionStatus implements storage.SessionStatusUpdater: a narrow UPDATE touching only status/updated_at, so it can never clobber a concurrent Metadata writer's row the way a whole-record UpdateSession (which always rewrites the metadata column) could.

Jump to

Keyboard shortcuts

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