use persistent_map::sqlite::SqliteBackend;
use persistent_map::{PersistentMap, Result};
#[cfg(feature = "sqlite")]
#[tokio::main]
async fn main() -> Result<()> {
let backend = SqliteBackend::new("example_sqlite.db").await?;
let map = PersistentMap::new(backend).await?;
println!("Map initialized with {} entries", map.len());
map.insert(
"greeting".to_string(),
"Hello, Persistent World!".to_string(),
)
.await?;
map.insert("count".to_string(), "42".to_string()).await?;
map.insert("pi".to_string(), "3.14159".to_string()).await?;
println!("Inserted 3 entries");
if let Some(value) = map.get(&"greeting".to_string()) {
println!("Greeting: {}", value);
}
if map.contains_key(&"count".to_string()) {
println!("Count exists!");
if let Some(count) = map.get(&"count".to_string()) {
println!("Count value: {}", count);
}
}
let old_value = map.remove(&"pi".to_string()).await?;
println!("Removed pi value: {:?}", old_value);
map.flush().await?;
println!("Data persisted. Map contains {} entries.", map.len());
println!("Run this example again to see that data persists between runs!");
Ok(())
}
#[cfg(not(feature = "sqlite"))]
fn main() {
println!("This example requires the 'sqlite' feature to be enabled.");
println!("Add the following to your Cargo.toml:");
println!("persistent-map = {{ version = \"0.1.0\", features = [\"sqlite\"] }}");
}