Documentation
¶
Overview ¶
Package sqlite provides a SQLite-backed implementation of the persistence ports. The driver is modernc.org/sqlite (pure Go, no CGO) so chronos builds and cross-compiles without a C toolchain.
The package owns one Conn type that bundles the per-aggregate repositories (entity states, signals) on a shared *sql.DB. SQL goes through sqlc-generated code in the sqlcgen subpackage; this file is only responsible for opening the database, configuring PRAGMAs, and applying migrations.
Index ¶
- func Bootstrap(db *sql.DB) error
- func TxFn(db *sql.DB) func(ctx context.Context, fn func(context.Context) error) error
- 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 ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Conn ¶
type Conn struct {
DB *sql.DB
EntityStates *EntityStateRepository
Signals *SignalRepository
// contains filtered or unexported fields
}
Conn bundles the SQLite-backed repositories. Construct with Open.
func NewFromDB ¶
NewFromDB wires the SQLite repositories onto a pre-opened *sql.DB without applying PRAGMAs or migrations. The libsql provider uses this to reuse the SQLite repositories on a libsql-driver-backed connection (libSQL is wire-compatible at the SQL level).
The caller owns db and is responsible for closing it. Conn.Close will close it; in shared scenarios call only one of them.
type EntityStateRepository ¶
type EntityStateRepository struct {
// contains filtered or unexported fields
}
EntityStateRepository persists entity states in SQLite. Features, Labels, and Meta are JSON-encoded TEXT to keep adapter-specific schema out of the engine's tables.
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 the scope's states, most recent first.
func (*EntityStateRepository) ListScopes ¶
ListScopes returns the distinct ScopeIDs that have at least one observation. Used by the in-process detection scheduler. The query is direct SQL rather than sqlc-generated to keep the surface minimal — there is exactly one query and it has no parameters.
func (*EntityStateRepository) Save ¶
func (r *EntityStateRepository) Save(ctx context.Context, adapterName string, states []chronos.EntityState) error
Save persists a batch of observations transactionally.
type SignalRepository ¶
type SignalRepository struct {
// contains filtered or unexported fields
}
SignalRepository persists signals and their evidence in SQLite.
Filtering uses dynamic SQL because sqlc cannot express optional predicates compactly. Inserts go through the sqlc-generated code so the same query pipeline carries them as the rest of the schema.
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 the filter, ordered detected-at desc then confidence desc.