SqliteDb

Struct SqliteDb 

Source
pub struct SqliteDb { /* private fields */ }
Expand description

SQLite-backed items database

Implementations§

Source§

impl SqliteDb

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Open or create the database

Source

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

Open an in-memory database (for testing)

Source

pub fn get_setting(&self, key: &str) -> RepoResult<Option<String>>

Get a setting value

Source

pub fn set_setting(&self, key: &str, value: &str) -> RepoResult<()>

Set a setting value

Source

pub fn get_or_create_salt(&self) -> RepoResult<String>

Get the source salt, generating one if it doesn’t exist

Source

pub fn get_distinct_sources(&self) -> RepoResult<Vec<String>>

Get all distinct sources from the database

Source§

impl SqliteDb

Source

pub fn get_all_values_bulk( &self, serials: &[&str], ) -> RepoResult<Vec<ItemValue>>

Get all item_values for multiple serials (bulk fetch)

Trait Implementations§

Source§

impl ImportExportRepository for SqliteDb

Source§

fn import_from_dir(&self, dir: &Path) -> RepoResult<String>

Import an item from a directory
Source§

fn export_to_dir(&self, serial: &str, dir: &Path) -> RepoResult<()>

Export an item to a directory
Source§

impl ItemsRepository for SqliteDb

Source§

fn init(&self) -> RepoResult<()>

Initialize the database schema
Source§

fn add_item(&self, serial: &str) -> RepoResult<()>

Add a new item with just its serial
Source§

fn get_item(&self, serial: &str) -> RepoResult<Option<Item>>

Get an item by serial
Source§

fn update_item(&self, serial: &str, update: &ItemUpdate) -> RepoResult<()>

Update item metadata
Source§

fn list_items(&self, filter: &ItemFilter) -> RepoResult<Vec<Item>>

List items with optional filters
Source§

fn delete_item(&self, serial: &str) -> RepoResult<bool>

Delete an item
Source§

fn set_verification_status( &self, serial: &str, status: VerificationStatus, notes: Option<&str>, ) -> RepoResult<()>

Set verification status for an item
Set legal status for an item
Set legal status for all items
Source§

fn set_item_type(&self, serial: &str, item_type: &str) -> RepoResult<()>

Set item type
Source§

fn set_source(&self, serial: &str, source: &str) -> RepoResult<()>

Set source for an item
Source§

fn set_source_for_null(&self, source: &str) -> RepoResult<usize>

Set source for items without one
Source§

fn set_source_where(&self, source: &str, condition: &str) -> RepoResult<usize>

Set source for items matching a condition (SQL WHERE clause) WARNING: condition is inserted directly into SQL - do not use with untrusted input
Source§

fn get_parts(&self, serial: &str) -> RepoResult<Vec<ItemPart>>

Get parts for an item
Source§

fn set_value( &self, serial: &str, field: &str, value: &str, source: ValueSource, source_detail: Option<&str>, confidence: Confidence, ) -> RepoResult<()>

Set a field value with source attribution
Source§

fn get_values(&self, serial: &str, field: &str) -> RepoResult<Vec<ItemValue>>

Get all values for a field across sources
Source§

fn get_best_value( &self, serial: &str, field: &str, ) -> RepoResult<Option<ItemValue>>

Get the best value for a field
Source§

fn get_all_values(&self, serial: &str) -> RepoResult<Vec<ItemValue>>

Get all values for an item
Source§

fn get_best_values(&self, serial: &str) -> RepoResult<HashMap<String, String>>

Get best value for each field as a map
Source§

fn get_all_items_best_values( &self, ) -> RepoResult<HashMap<String, HashMap<String, String>>>

Get best values for all items (bulk query)
Source§

fn stats(&self) -> RepoResult<DbStats>

Get database statistics
Source§

fn migrate_column_values(&self, dry_run: bool) -> RepoResult<MigrationStats>

Migrate column values to item_values table

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.
Source§

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

Source§

fn vzip(self) -> V