Documentation
¶
Overview ¶
Package postgres provides a PostgreSQL-backed implementation of the persistence ports. Postgres is the recommended backend for multi- process deployments; SQLite covers single-binary, embedded, and test use cases.
Wire-protocol compatibles supported by this provider via the same driver: CockroachDB, Yugabyte, Neon, Crunchy Bridge, TimescaleDB, AlloyDB Omni. They all speak the libpq wire protocol; Chronos doesn't use any postgres-specific extension.
Per Mnemos ADR 0001 §3, ?namespace= translates to a Postgres schema: CREATE SCHEMA IF NOT EXISTS <ns> + SET search_path TO <ns> runs at every Open. The schema-version table lives inside the namespace, so two tools (Mnemos and Chronos) sharing one Postgres database track their migrations independently.
Index ¶
- Constants
- type Conn
- type EntityStateRepository
- func (r *EntityStateRepository) Count(ctx context.Context, adapterName string) (int64, error)
- func (r *EntityStateRepository) DeleteOlderThan(ctx context.Context, cutoff time.Time, adapterName string) error
- func (r *EntityStateRepository) Ingest(ctx context.Context, adapterName string, state chronos.EntityState) error
- func (r *EntityStateRepository) ListByEntity(ctx context.Context, entityID uuid.UUID) ([]chronos.EntityState, error)
- func (r *EntityStateRepository) ListByScope(ctx context.Context, scopeID uuid.UUID) ([]chronos.EntityState, error)
- func (r *EntityStateRepository) ListScopes(ctx context.Context) ([]uuid.UUID, error)
- func (r *EntityStateRepository) Save(ctx context.Context, adapterName string, states []chronos.EntityState) error
- type SignalRepository
- func (r *SignalRepository) Count(ctx context.Context, filter ports.SignalFilter) (int64, error)
- func (r *SignalRepository) Get(ctx context.Context, id uuid.UUID) (domain.Signal, error)
- func (r *SignalRepository) List(ctx context.Context, filter ports.SignalFilter) ([]domain.Signal, error)
- func (r *SignalRepository) Save(ctx context.Context, sig domain.Signal) error
Constants ¶
const BulkSaveThreshold = 200
BulkSaveThreshold is the row count above which Save switches to the chunked multi-row INSERT path.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
DB *sql.DB
EntityStates *EntityStateRepository
Signals *SignalRepository
}
Conn bundles the Postgres-backed repositories.
type EntityStateRepository ¶
type EntityStateRepository struct {
// contains filtered or unexported fields
}
EntityStateRepository persists entity states in PostgreSQL.
func (*EntityStateRepository) DeleteOlderThan ¶
func (r *EntityStateRepository) DeleteOlderThan(ctx context.Context, cutoff time.Time, adapterName string) error
DeleteOlderThan removes states observed before cutoff for adapterName.
func (*EntityStateRepository) Ingest ¶
func (r *EntityStateRepository) Ingest(ctx context.Context, adapterName string, state chronos.EntityState) error
Ingest persists a single observation.
func (*EntityStateRepository) ListByEntity ¶
func (r *EntityStateRepository) ListByEntity(ctx context.Context, entityID uuid.UUID) ([]chronos.EntityState, error)
ListByEntity returns all observations of an entity, most recent first.
func (*EntityStateRepository) ListByScope ¶
func (r *EntityStateRepository) ListByScope(ctx context.Context, scopeID uuid.UUID) ([]chronos.EntityState, error)
ListByScope returns all entity states for a scope, most recent first.
func (*EntityStateRepository) ListScopes ¶
ListScopes returns the distinct ScopeIDs that have at least one observation. Used by the in-process detection scheduler.
func (*EntityStateRepository) Save ¶
func (r *EntityStateRepository) Save(ctx context.Context, adapterName string, states []chronos.EntityState) error
Save upserts a batch of observations inside a single transaction. Above BulkSaveThreshold rows the batch switches to a multi-row INSERT (chunks of [bulkChunkSize]) instead of one statement per row. This avoids the round-trip overhead of per-row INSERT against the wire protocol while staying portable across every Postgres- wire-compatible engine (CockroachDB, YugabyteDB, Neon, etc.) — including engines whose pgx COPY support is incomplete.
type SignalRepository ¶
type SignalRepository struct {
// contains filtered or unexported fields
}
SignalRepository persists signals and their evidence in PostgreSQL.
func (*SignalRepository) Count ¶
func (r *SignalRepository) Count(ctx context.Context, filter ports.SignalFilter) (int64, error)
Count returns the number of signals matching filter.
func (*SignalRepository) List ¶
func (r *SignalRepository) List(ctx context.Context, filter ports.SignalFilter) ([]domain.Signal, error)
List returns signals matching filter, ordered detected-at desc then confidence desc.