Documentation
¶
Overview ¶
Package postgres provides a PostgreSQL-backed Storage adapter for Chronos.
Index ¶
- type Option
- type Store
- func (s *Store) AppendAuditLog(ctx context.Context, log *storage.AuditLog) error
- func (s *Store) AppendEvent(ctx context.Context, e *storage.Event) error
- func (s *Store) AppendEvents(ctx context.Context, events []*storage.Event) error
- func (s *Store) Close() error
- func (s *Store) CreateSession(ctx context.Context, sess *storage.Session) error
- func (s *Store) DeleteMemory(ctx context.Context, id string) error
- func (s *Store) GetCheckpoint(ctx context.Context, id string) (*storage.Checkpoint, error)
- func (s *Store) GetLatestCheckpoint(ctx context.Context, sessionID string) (*storage.Checkpoint, error)
- func (s *Store) GetMemory(ctx context.Context, agentID, key string) (*storage.MemoryRecord, error)
- func (s *Store) GetSession(ctx context.Context, id string) (*storage.Session, error)
- func (s *Store) GetTrace(ctx context.Context, id string) (*storage.Trace, error)
- func (s *Store) InsertTrace(ctx context.Context, t *storage.Trace) error
- func (s *Store) InsertTraces(ctx context.Context, traces []*storage.Trace) error
- func (s *Store) ListAuditLogs(ctx context.Context, sessionID string, limit, offset int) ([]*storage.AuditLog, error)
- func (s *Store) ListCheckpoints(ctx context.Context, sessionID string) ([]*storage.Checkpoint, error)
- func (s *Store) ListCheckpointsPaged(ctx context.Context, sessionID string, limit int, cursor string) (*storage.CheckpointPage, error)
- func (s *Store) ListEvents(ctx context.Context, sessionID string, afterSeq int64) ([]*storage.Event, error)
- func (s *Store) ListEventsPaged(ctx context.Context, sessionID string, afterSeq int64, limit int, ...) (*storage.EventPage, error)
- func (s *Store) ListMemory(ctx context.Context, agentID, kind string) ([]*storage.MemoryRecord, error)
- func (s *Store) ListSessions(ctx context.Context, agentID string, limit, offset int) ([]*storage.Session, error)
- func (s *Store) ListTraces(ctx context.Context, sessionID string) ([]*storage.Trace, error)
- func (s *Store) ListTracesPaged(ctx context.Context, sessionID string, limit int, cursor string) (*storage.TracePage, error)
- func (s *Store) Migrate(ctx context.Context) error
- func (s *Store) PutMemory(ctx context.Context, m *storage.MemoryRecord) error
- func (s *Store) SaveCheckpoint(ctx context.Context, cp *storage.Checkpoint) error
- func (s *Store) SaveCheckpointAndEvent(ctx context.Context, cp *storage.Checkpoint, evt *storage.Event) error
- func (s *Store) TrimAuditLogs(ctx context.Context, olderThan time.Time) (int64, error)
- func (s *Store) TrimCheckpoints(ctx context.Context, sessionID string, keep int) (int64, error)
- func (s *Store) TrimEvents(ctx context.Context, olderThan time.Time) (int64, error)
- func (s *Store) TrimTraces(ctx context.Context, olderThan time.Time) (int64, error)
- func (s *Store) UpdateSession(ctx context.Context, sess *storage.Session) error
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
WithConnMaxLifetime sets the maximum lifetime of a connection (default 5m).
func WithMaxIdleConns ¶ added in v0.4.0
WithMaxIdleConns sets the maximum number of idle connections (default 5).
func WithMaxOpenConns ¶ added in v0.4.0
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 ¶
New opens a PostgreSQL connection with the given DSN using the pgx driver (registered via the blank import above).
func (*Store) AppendAuditLog ¶
func (*Store) AppendEvent ¶
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
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) CreateSession ¶
func (*Store) GetCheckpoint ¶
func (*Store) GetLatestCheckpoint ¶
func (*Store) GetSession ¶
func (*Store) InsertTrace ¶
func (*Store) InsertTraces ¶ added in v0.4.0
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 (*Store) ListCheckpoints ¶
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 (*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 (*Store) ListSessions ¶
func (*Store) ListTraces ¶
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 ¶
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) SaveCheckpoint ¶
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
TrimAuditLogs deletes audit logs created strictly before olderThan.
func (*Store) TrimCheckpoints ¶ added in v0.4.0
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
TrimEvents deletes events created strictly before olderThan.
func (*Store) TrimTraces ¶ added in v0.4.0
TrimTraces deletes traces started strictly before olderThan.