pub struct SqliteBackend { /* private fields */ }Expand description
A SQLite-based storage backend for PersistentMap.
This backend stores key-value pairs in a SQLite database, providing durable persistence with good performance characteristics.
§Examples
use persistent_map::{PersistentMap, Result};
use persistent_map::sqlite::SqliteBackend;
// Create a SQLite backend
let backend = SqliteBackend::new("my_database.db").await?;
// Initialize a PersistentMap with the backend
let map: PersistentMap<String, String, _> = PersistentMap::new(backend).await?;Implementations§
Source§impl SqliteBackend
impl SqliteBackend
Sourcepub async fn new(db_path: &str) -> Result<Self>
pub async fn new(db_path: &str) -> Result<Self>
Creates a new SQLite backend with the given database path.
This method opens a connection to the SQLite database at the specified path and creates the necessary table if it doesn’t exist.
§Arguments
db_path- The path to the SQLite database file
§Returns
A Result containing the new SqliteBackend or an error
§Examples
use persistent_map::sqlite::SqliteBackend;
use persistent_map::Result;
let backend = SqliteBackend::new("my_database.db").await?;Trait Implementations§
Source§impl Debug for SqliteBackend
impl Debug for SqliteBackend
Source§impl<K, V> StorageBackend<K, V> for SqliteBackend
Implementation of the StorageBackend trait for SqliteBackend.
impl<K, V> StorageBackend<K, V> for SqliteBackend
Implementation of the StorageBackend trait for SqliteBackend.
This implementation provides methods for loading, saving, and deleting key-value pairs from a SQLite database.
Source§fn load_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<HashMap<K, V>, PersistentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn load_all<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<HashMap<K, V>, PersistentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Loads all key-value pairs from the SQLite database.
This method queries the database for all key-value pairs and deserializes them into the appropriate types.
Source§fn save<'life0, 'async_trait>(
&'life0 self,
key: K,
value: V,
) -> Pin<Box<dyn Future<Output = Result<(), PersistentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save<'life0, 'async_trait>(
&'life0 self,
key: K,
value: V,
) -> Pin<Box<dyn Future<Output = Result<(), PersistentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Saves a key-value pair to the SQLite database.
This method serializes the key and value to strings and inserts or replaces them in the database.
Source§fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 K,
) -> Pin<Box<dyn Future<Output = Result<(), PersistentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 K,
) -> Pin<Box<dyn Future<Output = Result<(), PersistentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Deletes a key-value pair from the SQLite database.
This method removes the key-value pair with the specified key from the database.
Source§fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PersistentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn flush<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), PersistentError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Flushes any buffered writes to the SQLite database.
This method ensures that all data is written to disk by executing a PRAGMA synchronous command.