postgres

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package postgres provides a PostgreSQL-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.

func WithConnMaxLifetime added in v0.4.0

func WithConnMaxLifetime(d time.Duration) Option

WithConnMaxLifetime sets the maximum lifetime of a connection (default 5m).

func WithMaxIdleConns added in v0.4.0

func WithMaxIdleConns(n int) Option

WithMaxIdleConns sets the maximum number of idle connections (default 5).

func WithMaxOpenConns added in v0.4.0

func WithMaxOpenConns(n int) Option

WithMaxOpenConns sets the maximum number of open connections (default 25).

type Store

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

Store implements storage.Storage using PostgreSQL.

func New

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

New opens a PostgreSQL connection with the given DSN using the pgx driver (registered via the blank import above).

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 (P0-004).

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 (ON CONFLICT DO NOTHING). The batch is split into chunks so the per-statement bind-parameter count stays under pgMaxBindParams; 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) DeleteMemory

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

func (*Store) GetCheckpoint

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

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 bulk-loads many trace spans using PostgreSQL's COPY protocol via the pgx driver, which is materially faster than per-row INSERTs at scale.

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) 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, giving a deterministic order that matches the SQLite adapter.

func (*Store) Migrate

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

Migrate creates all required tables and indexes via the versioned migration framework, holding a pg_advisory_lock so concurrent migrators serialize (P1-014).

func (*Store) PutMemory

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

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 (P0-004).

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 (P0-004).

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

Jump to

Keyboard shortcuts

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