Skip to main content

DatabaseDriver

Struct DatabaseDriver 

Source
pub struct DatabaseDriver { /* private fields */ }

Implementations§

Source§

impl DatabaseDriver

Source

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.

Source

pub fn open_in_memory() -> Result<Self, Error>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn schema_version(&self) -> Result<u32, Error>

Source

pub fn insert_asset(&self, row: &AssetRow) -> Result<(), Error>

Source

pub fn upsert_asset(&self, row: &AssetRow) -> Result<(), Error>

Source

pub fn find_by_uuid(&self, uuid: &str) -> Result<Option<AssetRow>, Error>

Source

pub fn find_by_hash(&self, hash: &str) -> Result<Option<AssetRow>, Error>

Source

pub fn query_timeline( &self, offset: usize, limit: usize, ) -> Result<Vec<AssetRow>, Error>

Source

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.

Source

pub fn insert_stack(&self, row: &AssetStackRow) -> Result<(), Error>

Source

pub fn insert_stack_member(&self, row: &StackMemberRow) -> Result<(), Error>

Source

pub fn update_stack_hidden(&self, uuid: &str, hidden: bool) -> Result<(), Error>

Source

pub fn update_stack_primary( &self, stack_id: &str, primary_uuid: &str, ) -> Result<(), Error>

Source

pub fn find_stack_by_detection( &self, key: &str, method: &str, ) -> Result<Option<AssetStackRow>, Error>

Source

pub fn list_stack_members( &self, stack_id: &str, ) -> Result<Vec<StackMemberRow>, Error>

Source

pub fn soft_delete(&self, uuid: &str, deleted_at: i64) -> Result<(), Error>

Source

pub fn restore_asset(&self, uuid: &str) -> Result<(), Error>

Source

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.

Source

pub fn query_hidden( &self, offset: usize, limit: usize, ) -> Result<Vec<AssetRow>, Error>

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.

Source

pub fn update_asset_hidden(&self, uuid: &str, hidden: bool) -> Result<(), Error>

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.

Source

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.

Source

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.

Source

pub fn insert_album(&self, row: &AlbumRow) -> Result<(), Error>

Source

pub fn update_album(&self, row: &AlbumRow) -> Result<(), Error>

Source

pub fn delete_album(&self, id: &str) -> Result<(), Error>

Source

pub fn find_album(&self, id: &str) -> Result<Option<AlbumRow>, Error>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn upsert_representation( &self, row: &CachedRepresentationRow, ) -> Result<(), Error>

Insert or replace a cached representation row.

Source

pub fn remove_representation(&self, uuid: &str, tier: &str) -> Result<(), Error>

Remove a cached representation row (after its file has been deleted).

Source

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.

Source

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.

Source

pub fn representations_for( &self, uuid: &str, ) -> Result<Vec<CachedRepresentationRow>, Error>

All cached representations recorded for uuid (any tier).

Source

pub fn replace_asset_tags( &self, uuid: &str, tags: &[String], ) -> Result<(), Error>

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.

Source

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).

Source

pub fn tags_for(&self, uuid: &str) -> Result<Vec<String>, Error>

The indexed user tags for uuid, sorted.

Source§

impl DatabaseDriver

Source

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.

Source

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).

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source§

fn insert_embedding<P: EmbeddingProvenance>( &self, registry: &P, e: EmbeddingInsert<'_>, ) -> Result<(), VectorIndexError>

Insert (or replace) one provenanced embedding.
Source§

fn knn<P: EmbeddingProvenance>( &self, registry: &P, task: TaskKind, query: &[f32], k: usize, platform: &str, ) -> Result<Vec<KnnHit>, VectorIndexError>

The 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>

The regeneration work-list: assets in task’s platform partition whose embedding is stale under registry, sorted by asset id.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more