Skip to main content

SQLiteMap

Struct SQLiteMap 

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

A hash map with string keys and values, backed by an SQLite in-memory database.

By default, SQLiteMap treats its keys as case-sensitive, but a case-insensitive variant is available. Even when using the case-sensitive map variant, for some operations a dedicated “case-insensitive” version is provided.

Important: For bulk inserts or updates, it is strongly recommended to use an explicit transaction. Without one, SQLite executes each insert or update in its own transaction, which can significantly degrade performance.

Implementations§

Source§

impl SQLiteMap

Source

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

Creates a new, empty SQLite-backed hash map with case-sensitive keys.

Source

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

Creates a new, empty SQLite-backed hash map with case-insensitive keys.

Source

pub fn transaction(&mut self) -> Result<SQLiteMapTransaction<'_>, Error>

Starts a new SQLite transaction for this map.

Please note that using an explicit SQLite transaction allows for much more efficient bulk inserts 🚀

Returns the new SQLiteMapTransaction instance.

Source

pub fn insert(&mut self, key: &str, value: &str) -> Result<bool, Error>

Tries to insert the given key-value pair into the map.

If the map already contains the specified key, then its associated value is not updated to the new value!

Returns true, if the key-value pair was inserted; otherwise returns false.

Please use the update() function to update the value associated with a key that may already exist.

Source

pub fn update(&mut self, key: &str, value: &str) -> Result<(), Error>

Associates the specified value with the specified key.

If the map does not already contain the specified key, then the key is inserted automatically.

Due to limitations in SQLite, it is not possible to determine whether the key-value pair was inserted or updated.

Source

pub fn contains(&self, key: &str) -> Result<bool, Error>

Checks whether the map contains the specified key.

For case-sensitive maps, the check is case-sensitive; for case-insensitive maps, the check is case-insensitive.

Returns true, if the map contains the key; otherwise returns false.

Source

pub fn contains_nocase(&self, key: &str) -> Result<bool, Error>

This is the “case-insensitive” version of the contains() function.

The check is always performed case-insensitive.

Returns true, if the map contains the key; otherwise returns false.

Source

pub fn get(&self, key: &str) -> Result<Option<String>, Error>

Tries to retrieve the value for the specified key.

For case-sensitive maps, the key is treated as case-sensitive; for case-insensitive maps, it is treated as case-insensitive.

Returns the Some(value), if the map contains the key; otherwise returns None.

Source

pub fn get_nocase(&self, key: &str) -> Result<Option<String>, Error>

This is the “case-insensitive” version of the get() function.

The key is always treated as case-insensitive.

Returns the Some(value), if the map contains the key; otherwise returns None.

Source

pub fn remove(&mut self, key: &str) -> Result<bool, Error>

Removes the specified key from the map, if present.

For case-sensitive maps, the key is treated as case-sensitive; for case-insensitive maps, it is treated as case-insensitive.

Returns true, if the map contained the key; otherwise returns false.

Source

pub fn remove_nocase(&mut self, key: &str) -> Result<bool, Error>

This is the “case-insensitive” version of the remove() function.

The key is always treated as case-insensitive.

Returns true, if the map contained the key; otherwise returns false.

Source

pub fn for_each<F>(&self, callback: F) -> Result<(), Error>
where F: FnMut(&str, &str),

Invokes the given callback function for each key-value pair that is currently contained in the map.

This function does not guarantee a specific iteration order.

Source

pub fn find<P>(&self, predicate: P) -> Result<Option<(String, String)>, Error>
where P: Fn(&str, &str) -> bool,

Searches the map for the first key-value pair that satisfies the given predicate.

Returns the first key-value pair that satisfies the given predicate, or None if none satisfies the predicate or the map is empty.

This function does not guarantee a specific iteration order.

Also, the predicate is not always tested on all key-value pairs, because the function returns at the first match.

Source

pub fn len(&self) -> Result<SizeT, Error>

Returns the number of unique keys in the map.

Source

pub fn is_empty(&self) -> Result<bool, Error>

Returns true if the map contains no keys; otherwise returns false.

Source

pub fn clear(&mut self) -> Result<(), Error>

Removes all keys from the map.

Trait Implementations§

Source§

impl Default for SQLiteMap

Source§

fn default() -> Self

Returns a new, empty map, as created by the SQLiteMap::new() function.

§Panics

Panics if a new SQLiteMap instance could not be created, e.g., because of an SQLite error.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.