pub struct Store { /* private fields */ }Expand description
A handle to the trendkit SQLite database.
The connection sits behind a mutex so a Store is Send + Sync:
sources run sequentially today, but later milestones run them
concurrently against one store. Individual statements are short; no
lock is held across .await points.
Implementations§
Source§impl Store
impl Store
Sourcepub fn open(path: &Path) -> Result<Store, TrendError>
pub fn open(path: &Path) -> Result<Store, TrendError>
Open (and migrate) the database at path.
§Errors
Fails when the file cannot be opened or the schema cannot migrate.
Sourcepub fn open_in_memory() -> Result<Store, TrendError>
pub fn open_in_memory() -> Result<Store, TrendError>
Open an in-memory database (tests).
§Errors
Fails when the in-memory database cannot be created or migrated.
Sourcepub fn from_connection(conn: Connection) -> Result<Store, TrendError>
pub fn from_connection(conn: Connection) -> Result<Store, TrendError>
Adopt an existing connection (tests: legacy-schema migration).
§Errors
Fails when the schema cannot migrate.
Sourcepub fn with_conn<T>(
&self,
f: impl FnOnce(&Connection) -> Result<T, Error>,
) -> Result<T, TrendError>
pub fn with_conn<T>( &self, f: impl FnOnce(&Connection) -> Result<T, Error>, ) -> Result<T, TrendError>
Run f with the underlying connection — the escape hatch for
downstream analysts (e.g. signalkit-integrity) that need custom
queries without duplicating the schema. The connection is never
exposed across an .await point.
§Errors
Propagates lock poisoning and anything f returns.
Sourcepub fn upsert_subject(&self, subject: &SubjectRecord) -> Result<i64, TrendError>
pub fn upsert_subject(&self, subject: &SubjectRecord) -> Result<i64, TrendError>
Insert or update a subject identity row; returns its subject_id.
Non-null existing fields win over absent ones (COALESCE), so a
sparse source cannot blank out data a richer source contributed.
§Errors
Propagates SQLite failures.
Sourcepub fn insert_observation(
&self,
subject_id: i64,
obs: &Observation,
) -> Result<(), TrendError>
pub fn insert_observation( &self, subject_id: i64, obs: &Observation, ) -> Result<(), TrendError>
Append one observation for subject_id.
§Errors
Propagates SQLite failures (including missing foreign key).
Sourcepub fn record_run(
&self,
ts: i64,
source: &str,
pages: i64,
items: i64,
) -> Result<(), TrendError>
pub fn record_run( &self, ts: i64, source: &str, pages: i64, items: i64, ) -> Result<(), TrendError>
Sourcepub fn velocity_rows(
&self,
window_days: u32,
limit: u32,
) -> Result<Vec<VelocityRow>, TrendError>
pub fn velocity_rows( &self, window_days: u32, limit: u32, ) -> Result<Vec<VelocityRow>, TrendError>
Highest-velocity subjects over the last window_days days.
Subjects with a single observation inside the window are included with zero velocity rather than skipped, so early-stage databases still show what is being tracked.
§Errors
Propagates SQLite failures.