Struct persy::OpenOptions
source · [−]pub struct OpenOptions { /* private fields */ }
Expand description
Options, flags, configs which can be used to configure how a persy database is opened.
use persy::{OpenOptions, Persy, PersyId, ValueMode};
// This function will only be called on database creation
fn init(persy: &Persy) -> Result<(), Box<dyn std::error::Error>> {
let mut tx = persy.begin()?;
tx.create_segment("data")?;
tx.create_index::<u64, PersyId>("index", ValueMode::Replace)?;
let prepared = tx.prepare()?;
prepared.commit()?;
println!("Segment and Index successfully created");
Ok(())
}
let persy = OpenOptions::new().create(true).prepare_with(init).open("target/persy.db")?;
Implementations
Truncate the file on open removing all the persistent data
Create a new file if not exists
Create a new file if exists fail
pub fn prepare_with<F>(&mut self, prepare: F) -> &mut OpenOptions where
F: Fn(&Persy) -> Result<(), Box<dyn Error>> + 'static,
pub fn prepare_with<F>(&mut self, prepare: F) -> &mut OpenOptions where
F: Fn(&Persy) -> Result<(), Box<dyn Error>> + 'static,
Provide a function for initialize the storage in case did not existed
pub fn recover_with<F>(&mut self, recover: F) -> &mut OpenOptions where
F: Fn(&Vec<u8>) -> bool + 'static,
pub fn recover_with<F>(&mut self, recover: F) -> &mut OpenOptions where
F: Fn(&Vec<u8>) -> bool + 'static,
Provide a function for check if a transaction must be committed or rollback in case of recover from crash
Provide general storage configurations
Open a file to a recover structure to list pending transactions and select witch commit and rollback
Open a file to a recover structure to list pending transactions and select witch commit and rollback
Open a file from the given path with the current options
Trait Implementations
Returns the “default value” for a type. Read more