pub struct DatabaseDriver { /* private fields */ }Implementations§
Source§impl DatabaseDriver
impl DatabaseDriver
Sourcepub fn open(path: &Path) -> Result<Self, Error>
pub fn open(path: &Path) -> Result<Self, Error>
Open (or create) the catalog at path and bring it to the crate’s SCHEMA_VERSION.
The migrator’s typed MigrationError is flattened into rusqlite::Error here
because this signature is consumed by capsule-core-ffi; the crate’s own library
opener goes through the crate-private open_typed so a catalog newer than this build
surfaces as a typed refusal rather than a message inside a SqliteFailure.
pub fn open_in_memory() -> Result<Self, Error>
Sourcepub fn with_transaction<T, E>(
&self,
f: impl FnOnce() -> Result<T, E>,
) -> Result<T, E>where
E: From<Error>,
pub fn with_transaction<T, E>(
&self,
f: impl FnOnce() -> Result<T, E>,
) -> Result<T, E>where
E: From<Error>,
Run f atomically: every catalog write it makes through this driver lands together or
not at all.
Outside any transaction the scope is its own transaction and commits when f returns
Ok. Inside one — a begin_batch batch, or an enclosing
with_transaction — it nests as a SAVEPOINT: Ok folds f’s writes into the
enclosing transaction (which commits them later), and Err (or a panic) rolls back
only f’s writes, leaving everything the enclosing transaction already wrote in
place. That is what lets a per-asset index write sit inside an import batch without one
failed asset costing its neighbours their rows.
Sourcepub fn in_transaction(&self) -> bool
pub fn in_transaction(&self) -> bool
Whether a transaction is open on the catalog connection — a
begin_batch batch or a with_transaction
scope. While it is, nothing written since it opened is durable yet.
Sourcepub fn begin_batch(&self) -> Result<(), Error>
pub fn begin_batch(&self) -> Result<(), Error>
Open a batch: one outer transaction that every following write (each
with_transaction scope nesting inside it as a savepoint)
joins until commit_batch. Bulk import uses it so a run of assets
costs one catalog commit instead of several per asset.
Refused if a transaction is already open: batches do not nest, and silently joining someone else’s transaction would move this batch’s commit point out of the caller’s control.
Sourcepub fn commit_batch(&self) -> Result<(), Error>
pub fn commit_batch(&self) -> Result<(), Error>
Commit the batch begin_batch opened, making every write in it
durable. On failure the batch’s writes are rolled back rather than left pending, so the
connection is never stranded inside a transaction.
Sourcepub fn init_schema(&self) -> Result<(), Error>
pub fn init_schema(&self) -> Result<(), Error>
Bring the catalog to the crate’s SCHEMA_VERSION, creating it if the database is empty
and otherwise migrating it forward (see the crate-private db::migrate).
The migrator’s typed MigrationError is flattened into rusqlite::Error here because
this signature is consumed by capsule-core-ffi and library::open; callers that want
the typed error (and the list of steps applied) call Self::migrate instead.
Sourcepub fn migrate(&self) -> Result<Outcome, MigrationError>
pub fn migrate(&self) -> Result<Outcome, MigrationError>
Bring the catalog to the crate’s SCHEMA_VERSION, reporting exactly what ran.
Refuses (without writing anything) a catalog stamped newer than this build supports —
see MigrationError::CatalogTooNew.
pub fn schema_version(&self) -> Result<u32, Error>
pub fn insert_asset(&self, row: &AssetRow) -> Result<(), Error>
pub fn upsert_asset(&self, row: &AssetRow) -> Result<(), Error>
pub fn find_by_uuid(&self, uuid: &str) -> Result<Option<AssetRow>, Error>
pub fn find_by_hash(&self, hash: &str) -> Result<Option<AssetRow>, Error>
pub fn query_timeline( &self, offset: usize, limit: usize, ) -> Result<Vec<AssetRow>, Error>
Sourcepub fn query_timeline_filtered(
&self,
asset_type: Option<&str>,
after: Option<i64>,
before: Option<i64>,
offset: usize,
limit: usize,
) -> Result<Vec<AssetRow>, Error>
pub fn query_timeline_filtered( &self, asset_type: Option<&str>, after: Option<i64>, before: Option<i64>, offset: usize, limit: usize, ) -> Result<Vec<AssetRow>, Error>
Query the timeline filtered by asset type and/or capture-time window.
after/before bound COALESCE(capture_utc, capture_timestamp)
(inclusive). Any filter argument left as None is not applied.
pub fn insert_stack(&self, row: &AssetStackRow) -> Result<(), Error>
pub fn insert_stack_member(&self, row: &StackMemberRow) -> Result<(), Error>
pub fn update_stack_primary( &self, stack_id: &str, primary_uuid: &str, ) -> Result<(), Error>
pub fn find_stack_by_detection( &self, key: &str, method: &str, ) -> Result<Option<AssetStackRow>, Error>
pub fn list_stack_members( &self, stack_id: &str, ) -> Result<Vec<StackMemberRow>, Error>
pub fn soft_delete(&self, uuid: &str, deleted_at: i64) -> Result<(), Error>
pub fn restore_asset(&self, uuid: &str) -> Result<(), Error>
Sourcepub fn query_trash(
&self,
offset: usize,
limit: usize,
) -> Result<Vec<AssetRow>, Error>
pub fn query_trash( &self, offset: usize, limit: usize, ) -> Result<Vec<AssetRow>, Error>
All currently soft-deleted assets — the Recently Deleted listing, most-recently-deleted first.
All user-hidden, non-deleted assets — the Hidden listing, newest first.
Hidden assets are excluded from every default projection (timeline, album), so this
is the only view that surfaces them; it is reached exclusively through
GateKeeper::query_hidden, which holds
it behind the same fresh-local-auth gate as Recently Deleted (SSoT:
design/organization § Hidden Assets, design/local-gallery SR1).
Soft-deleted assets are excluded even when hidden: a trashed asset belongs to Recently Deleted, so the two gated views never show the same row.
Set the index projection of an asset’s sidecar hidden register. Hiding is
view-layer only — the asset keeps its album, its stack, and its sync state.
Sourcepub fn update_asset_caption(
&self,
uuid: &str,
caption: Option<&str>,
) -> Result<bool, Error>
pub fn update_asset_caption( &self, uuid: &str, caption: Option<&str>, ) -> Result<bool, Error>
Set (or, with None or an empty string, clear) the index projection of an asset’s
sidecar caption register. Returns whether a row was updated: false means no asset
has uuid, and nothing was written.
Sourcepub fn purge_asset(&self, uuid: &str) -> Result<(), Error>
pub fn purge_asset(&self, uuid: &str) -> Result<(), Error>
Permanently remove an asset’s rows — its assets row, its indexed tags, its upload
source guard, its cached representations and its stack memberships — in one transaction, so no index row names
it afterwards. A stack whose primary or cover it was passes that role to its first
remaining member (by sequence, then id), and a stack it leaves empty is removed. An
album cover naming it is cleared. The on-disk files are the caller’s concern
(Workspace::purge removes them first).
Runs as one with_transaction scope, so it also nests inside
an enclosing batch.
pub fn insert_album(&self, row: &AlbumRow) -> Result<(), Error>
pub fn update_album(&self, row: &AlbumRow) -> Result<(), Error>
pub fn delete_album(&self, id: &str) -> Result<(), Error>
pub fn find_album(&self, id: &str) -> Result<Option<AlbumRow>, Error>
Sourcepub fn list_albums(&self) -> Result<Vec<AlbumRow>, Error>
pub fn list_albums(&self) -> Result<Vec<AlbumRow>, Error>
Every album row, in the album order (AlbumRecency): most recent visible asset first,
an empty album by its id’s creation time, ties by ascending id. The row’s local
created_at is not consulted: it differs per device and across a rebuild.
Sourcepub fn album_recency(&self) -> Result<AlbumRecency, Error>
pub fn album_recency(&self) -> Result<AlbumRecency, Error>
The album order’s input, read from the index: the latest effective capture among each
album’s assets that are neither hidden nor trashed. Served by
idx_assets_album_recency; nothing is stored, so every write to an asset’s album,
capture time, hidden or trashed state moves it with no extra bookkeeping.
Sourcepub fn set_asset_album(
&self,
uuid: &str,
album_id: Option<&str>,
) -> Result<(), Error>
pub fn set_asset_album( &self, uuid: &str, album_id: Option<&str>, ) -> Result<(), Error>
Set (or clear, with None) the album an asset belongs to.
Sourcepub fn query_album_assets(
&self,
album_id: &str,
offset: usize,
limit: usize,
) -> Result<Vec<AssetRow>, Error>
pub fn query_album_assets( &self, album_id: &str, offset: usize, limit: usize, ) -> Result<Vec<AssetRow>, Error>
Query the non-deleted, non-hidden assets in an album, newest first.
Sourcepub fn upsert_representation(
&self,
row: &CachedRepresentationRow,
) -> Result<(), Error>
pub fn upsert_representation( &self, row: &CachedRepresentationRow, ) -> Result<(), Error>
Insert or replace a cached representation row.
Sourcepub fn remove_representation(&self, uuid: &str, tier: &str) -> Result<(), Error>
pub fn remove_representation(&self, uuid: &str, tier: &str) -> Result<(), Error>
Remove a cached representation row (after its file has been deleted).
Sourcepub fn record_access(
&self,
uuid: &str,
tier: &str,
now: i64,
) -> Result<(), Error>
pub fn record_access( &self, uuid: &str, tier: &str, now: i64, ) -> Result<(), Error>
Stamp a representation’s last-access time (recency promotion) — viewing an asset keeps its
representations from eviction. now is injected so the policy stays deterministic.
Sourcepub fn eviction_candidates(
&self,
budget_bytes: i64,
) -> Result<Vec<CachedRepresentationRow>, Error>
pub fn eviction_candidates( &self, budget_bytes: i64, ) -> Result<Vec<CachedRepresentationRow>, Error>
The reclaimable representations to evict so the reclaimable set fits within budget_bytes.
Pinned and device-owned originals are never candidates. Rows are ranked most-valuable-to-
keep first (most-recently-accessed; thumbnail over preview over original at equal recency),
then everything past the budget is evicted — i.e. least-recently-accessed first, original →
preview → thumbnail at equal recency.
Sourcepub fn representations_for(
&self,
uuid: &str,
) -> Result<Vec<CachedRepresentationRow>, Error>
pub fn representations_for( &self, uuid: &str, ) -> Result<Vec<CachedRepresentationRow>, Error>
All cached representations recorded for uuid (any tier).
Replace the indexed user tags for uuid with tags (the asset’s current OR-set value).
Atomic: the delete and every insert run in one
with_transaction scope, so a failure part-way leaves the
previous tag set intact rather than a truncated one.
Sourcepub fn asset_ids(&self) -> Result<HashSet<String>, Error>
pub fn asset_ids(&self) -> Result<HashSet<String>, Error>
Every asset id the assets table holds — the cheap side of the open-time reconcile’s
set comparison (one key-only scan, no row decoding).
The indexed user tags for uuid, sorted.
Source§impl DatabaseDriver
impl DatabaseDriver
Sourcepub fn create_vector_tables(&self, specs: &[VectorTableSpec]) -> Result<()>
pub fn create_vector_tables(&self, specs: &[VectorTableSpec]) -> Result<()>
Create the vec0 partition tables for specs up front (idempotent).
Optional: every insert / query creates the table it needs on first use. Call this when a
caller already holds the whole inventory (ml::Registry::vector_tables()) and wants the
schema materialized eagerly — e.g. so an external tool inspecting the file sees it.
Sourcepub fn insert_embedding(
&self,
registry: &impl EmbeddingProvenance,
e: EmbeddingInsert<'_>,
) -> Result<(), VectorIndexError>
pub fn insert_embedding( &self, registry: &impl EmbeddingProvenance, e: EmbeddingInsert<'_>, ) -> Result<(), VectorIndexError>
Insert (or replace) the embedding described by e.
Enforces the embedding-provenance invariant via EmbeddingProvenance::check_insert: an unknown
model or a non-embedding task is refused, while any version of a known model is
admitted — a superseded-but-known version lands as a stale-flagged row (excluded from
queries until regenerated). Replacing an existing entry (e.g. regeneration at a new
version) drops the prior vector first, so an asset never carries two embeddings for the
same (task, platform).
Sourcepub fn knn(
&self,
registry: &impl EmbeddingProvenance,
task: TaskKind,
query: &[f32],
k: usize,
platform: &str,
) -> Result<Vec<KnnHit>, VectorIndexError>
pub fn knn( &self, registry: &impl EmbeddingProvenance, task: TaskKind, query: &[f32], k: usize, platform: &str, ) -> Result<Vec<KnnHit>, VectorIndexError>
K nearest neighbours for query in task’s current canonical (platform, model_version) partition. Stale embeddings (older versions) are excluded structurally.
Returns hits nearest-first (inner-product ranking over normalized vectors).
Sourcepub fn embeddings_for(
&self,
asset_id: &str,
) -> Result<Vec<EmbeddingRecord>, Error>
pub fn embeddings_for( &self, asset_id: &str, ) -> Result<Vec<EmbeddingRecord>, Error>
The provenance records of every embedding stored for asset_id (any task / platform).
Sourcepub fn delete_embeddings_for(&self, asset_id: &str) -> Result<(), Error>
pub fn delete_embeddings_for(&self, asset_id: &str) -> Result<(), Error>
Delete every embedding stored for asset_id (its vec0 rows and companion rows). Used
when an asset is purged.
Sourcepub fn stale_embedding_assets(
&self,
registry: &impl EmbeddingProvenance,
task: TaskKind,
platform: &str,
) -> Result<Vec<String>, Error>
pub fn stale_embedding_assets( &self, registry: &impl EmbeddingProvenance, task: TaskKind, platform: &str, ) -> Result<Vec<String>, Error>
Assets in task’s platform partition whose stored embedding is stale — its
model_version trails the registry’s canonical version. These are the regeneration
work-list after a model swap.
Sourcepub fn embedding_count(&self, task: TaskKind) -> Result<usize, Error>
pub fn embedding_count(&self, task: TaskKind) -> Result<usize, Error>
Total embeddings stored for task (all platforms / versions).
Trait Implementations§
Source§impl VectorIndex for DatabaseDriver
The catalog is the production VectorIndex: each port method is the inherent method of the
same name, with a SQLite failure type-erased into VectorIndexError::Store.
impl VectorIndex for DatabaseDriver
The catalog is the production VectorIndex: each port method is the inherent method of the
same name, with a SQLite failure type-erased into VectorIndexError::Store.
Source§fn insert_embedding<P: EmbeddingProvenance>(
&self,
registry: &P,
e: EmbeddingInsert<'_>,
) -> Result<(), VectorIndexError>
fn insert_embedding<P: EmbeddingProvenance>( &self, registry: &P, e: EmbeddingInsert<'_>, ) -> Result<(), VectorIndexError>
Source§fn knn<P: EmbeddingProvenance>(
&self,
registry: &P,
task: TaskKind,
query: &[f32],
k: usize,
platform: &str,
) -> Result<Vec<KnnHit>, VectorIndexError>
fn knn<P: EmbeddingProvenance>( &self, registry: &P, task: TaskKind, query: &[f32], k: usize, platform: &str, ) -> Result<Vec<KnnHit>, VectorIndexError>
k nearest neighbours of query in task’s current canonical platform partition.Source§fn stale_embedding_assets<P: EmbeddingProvenance>(
&self,
registry: &P,
task: TaskKind,
platform: &str,
) -> Result<Vec<String>, VectorIndexError>
fn stale_embedding_assets<P: EmbeddingProvenance>( &self, registry: &P, task: TaskKind, platform: &str, ) -> Result<Vec<String>, VectorIndexError>
task’s platform partition whose embedding is
stale under registry, sorted by asset id.Auto Trait Implementations§
impl !Freeze for DatabaseDriver
impl !RefUnwindSafe for DatabaseDriver
impl !Sync for DatabaseDriver
impl !UnwindSafe for DatabaseDriver
impl Send for DatabaseDriver
impl Unpin for DatabaseDriver
impl UnsafeUnpin for DatabaseDriver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more