Struct persy::Persy [−][src]
pub struct Persy { /* fields omitted */ }
Expand description
Main structure to operate persy storage files
Implementations
Open a database file.
The file should have been created with Persy::create
Errors
Fails if the file does not exist.
Open a database file from a path with a recover function.
The file should have been created with Persy::create
Errors
Fails if the file does not exist.
Open a database file from a path and return a recover structure that allow to select the transactions to commit and recover them.
The file should have been created with Persy::create
Errors
Fails if the file does not exist.
Open a database file from a direct file handle.
The file should have been created with Persy::create
Errors
Fails if the file does not exist.
Open a database file, from a direct file handle and a transaction recover function.
The file should have been created with Persy::create
Errors
Fails if the file does not exist.
Open an existing database or create it if it does not exist yet,
calling the prepare
function just after the creation.
Example
use std::path::Path;
use persy::{Persy, Config, PersyId, ValueMode};
let path = Path::new("target/open_or_create.db");
let config = Config::new();
let persy = Persy::open_or_create_with(path, config, |persy| {
// this closure is only called on database creation
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(())
})?;
Begin a new transaction specifying parameters for the transaction.
The transaction isolation level is ‘read_commited’.
for commit call prepare
and commit
Example
let tx_id = vec![2;2];
let mut tx = persy.begin_with(TransactionConfig::new().set_transaction_id(tx_id))?;
// ...
tx.prepare()?.commit()?;
Check if a segment already exist in the storage
Example
let mut tx = persy.begin()?;
tx.create_segment("my_new_segment")?;
let prepared = tx.prepare()?;
prepared.commit()?;
assert!(persy.exists_segment("my_new_segment")?);
pub fn solve_segment_id(
&self,
segment: impl ToSegmentId
) -> Result<SegmentId, PE<SegmentError>>
pub fn solve_segment_id(
&self,
segment: impl ToSegmentId
) -> Result<SegmentId, PE<SegmentError>>
Resolves the segment to a SegmentId
Example
let mut tx = persy.begin()?;
tx.create_segment("my_new_segment")?;
let prepared = tx.prepare()?;
prepared.commit()?;
let segment_id = persy.solve_segment_id("my_new_segment")?;
Resolves the index to a IndexId, this has no public use as today, may be used in future.
Example
let mut tx = persy.begin()?;
tx.create_index::<u8,u8>("my_new_index", ValueMode::Cluster)?;
let prepared = tx.prepare()?;
prepared.commit()?;
let index_id = persy.solve_index_id("my_new_index")?;
Read the record content from persistent data.
Example
let mut tx = persy.begin()?;
let data = vec![1;20];
let id = tx.insert("seg", &data)?;
let prepared = tx.prepare()?;
prepared.commit()?;
let read = persy.read("seg", &id)?.expect("record exits");
assert_eq!(data,read);
Scan a segment for persistent records
Example
let mut tx = persy.begin()?;
let data = vec![1;20];
let id = tx.insert("seg", &data)?;
let prepared = tx.prepare()?;
prepared.commit()?;
let mut count = 0;
for (id,content) in persy.scan("seg")? {
println!("record size:{}",content.len());
count+=1;
}
assert_eq!(count,1);
Check if a segment already exist in the storage
Example
let mut tx = persy.begin()?;
tx.create_index::<u8,u8>("my_new_index", ValueMode::Replace)?;
let prepared = tx.prepare()?;
prepared.commit()?;
assert!(persy.exists_index("my_new_index")?);
Get a value or a group of values from a key.
Example
let values = persy.get::<u8,u8>("my_new_index",&10)?;
for value in values {
//...
}
Get one value or none from a key.
Example
if let Some(value) = persy.one::<u8,u8>("my_new_index",&10)? {
//...
}
pub fn range<K, V, R>(
&self,
index_name: &str,
range: R
) -> Result<IndexIter<K, V>, PE<IndexOpsError>> where
K: IndexType,
V: IndexType,
R: RangeBounds<K>,
pub fn range<K, V, R>(
&self,
index_name: &str,
range: R
) -> Result<IndexIter<K, V>, PE<IndexOpsError>> where
K: IndexType,
V: IndexType,
R: RangeBounds<K>,
Browse a range of keys and values from and index.
Example
let iter:IndexIter<u8,u8> = persy.range("my_new_index",10..12)?;
for (k,values) in iter {
for value in values {
//...
}
}
List all the existing segments.
Example
let mut tx = persy.begin()?;
tx.create_segment("seg")?;
let prepared = tx.prepare()?;
prepared.commit()?;
let segments = persy.list_segments()?;
let names = segments.into_iter().map(|(name,_id)|name).collect::<Vec<String>>();
assert!(names.contains(&"seg".to_string()));
List all the existing indexes.
Example
let mut tx = persy.begin()?;
tx.create_index::<u8,u8>("index", ValueMode::Cluster)?;
let prepared = tx.prepare()?;
prepared.commit()?;
let indexes = persy.list_indexes()?;
let names = indexes.into_iter().map(|(name,_info)|name).collect::<Vec<String>>();
assert!(names.contains(&"index".to_string()));
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Persy
impl !UnwindSafe for Persy
Blanket Implementations
Mutably borrows from an owned value. Read more