[−][src]Struct persy::Persy
Main structure to operate persy storage files
Methods
impl Persy
[src]
pub fn create<P: Into<String>>(path: P) -> PRes<()>
[src]
pub fn create_from_file(file: File) -> PRes<()>
[src]
pub fn open<P: Into<String>>(path: P, config: Config) -> PRes<Persy>
[src]
Open a database file.
The file should have been created with Persy::create
Errors
if the file does not exist fail.
pub fn open_with_recover<P: Into<String>, C>(
path: P,
config: Config,
recover: C
) -> PRes<Persy> where
C: Fn(&TransactionId) -> bool,
[src]
path: P,
config: Config,
recover: C
) -> PRes<Persy> where
C: Fn(&TransactionId) -> bool,
Open a database file from a path with a recover function.
The file should have been created with Persy::create
Errors
if the file does not exist fail.
pub fn open_from_file(path: File, config: Config) -> PRes<Persy>
[src]
Open a database file from a direct file handle.
The file should have been created with Persy::create
Errors
if the file does not exist fail.
pub fn open_from_file_with_recover<C>(
path: File,
config: Config,
recover: C
) -> PRes<Persy> where
C: Fn(&TransactionId) -> bool,
[src]
path: File,
config: Config,
recover: C
) -> PRes<Persy> where
C: Fn(&TransactionId) -> bool,
Open a database file, from a direct file handle and a transaction recover function.
The file should have been created with Persy::create
Errors
if the file does not exist fail.
pub fn begin(&self) -> PRes<Transaction>
[src]
Begin a new transaction.
The transaction isolation level is 'read_commited'.
for commit call prepare_commit
and commit
Example
let mut tx = persy.begin()?; // ... let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn begin_id(&self, meta_id: TransactionId) -> PRes<Transaction>
[src]
Begin a new transaction specifying and id usable for crash recover.
The transaction isolation level is 'read_commited'.
for commit call prepare_commit
and commit
Example
let tx_id = vec![2;2]; let mut tx = persy.begin_id(tx_id)?; // ... let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn create_segment(&self, tx: &mut Transaction, segment: &str) -> PRes<()>
[src]
Create a new segment with the provided name
Example
let mut tx = persy.begin()?; persy.create_segment(&mut tx, "my_new_segment")?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn drop_segment(&self, tx: &mut Transaction, segment: &str) -> PRes<()>
[src]
Drop a existing segment
Example
let mut tx = persy.begin()?; persy.drop_segment(&mut tx, "existing_segment_name")?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn exists_segment(&self, segment: &str) -> PRes<bool>
[src]
Check if a segment already exist in the storage
Example
let mut tx = persy.begin()?; persy.create_segment(&mut tx, "my_new_segment")?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?; assert!(persy.exists_segment("my_new_segment")?);
pub fn exists_segment_tx(&self, tx: &Transaction, segment: &str) -> PRes<bool>
[src]
Check if a segment already exist in the storage considering the transaction
Example
let mut tx = persy.begin()?; persy.create_segment(&mut tx, "my_new_segment")?; assert!(persy.exists_segment_tx(&mut tx, "my_new_segment")?);
pub fn insert_record(
&self,
tx: &mut Transaction,
segment: &str,
rec: &[u8]
) -> PRes<PersyId>
[src]
&self,
tx: &mut Transaction,
segment: &str,
rec: &[u8]
) -> PRes<PersyId>
create a new record
This function return an id that can be used by read_record
and read_record_tx
,
the record content can be read only with the read_record_tx
till the transaction is committed.
Example
let mut tx = persy.begin()?; let data = vec![1;20]; persy.insert_record(&mut tx, "seg", &data)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn read_record_tx(
&self,
tx: &mut Transaction,
segment: &str,
id: &PersyId
) -> PRes<Option<Vec<u8>>>
[src]
&self,
tx: &mut Transaction,
segment: &str,
id: &PersyId
) -> PRes<Option<Vec<u8>>>
Read the record content considering eventual in transaction changes.
Example
let mut tx = persy.begin()?; let data = vec![1;20]; let id = persy.insert_record(&mut tx, "seg", &data)?; let read = persy.read_record_tx(&mut tx, "seg", &id)?.expect("record exists"); assert_eq!(data,read);
pub fn read_record(&self, segment: &str, id: &PersyId) -> PRes<Option<Vec<u8>>>
[src]
Read the record content from persistent data.
Example
let mut tx = persy.begin()?; let data = vec![1;20]; let id = persy.insert_record(&mut tx, "seg", &data)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?; let read = persy.read_record("seg", &id)?.expect("record exits"); assert_eq!(data,read);
pub fn scan_records_tx<'a>(
&'a self,
tx: &'a Transaction,
segment: &str
) -> PRes<RecordScannerTx<'a>>
[src]
&'a self,
tx: &'a Transaction,
segment: &str
) -> PRes<RecordScannerTx<'a>>
please use scan_tx
instead
Scan for persistent and in transaction records
Example
let mut tx = persy.begin()?; let data = vec![1;20]; let id = persy.insert_record(&mut tx, "seg", &data)?; let mut count = 0; for found in persy.scan_records_tx(&tx, "seg")? { println!("record size:{}",found.content.len()); count+=1; } assert_eq!(count,1);
pub fn scan_tx<'a>(
&'a self,
tx: &'a Transaction,
segment: &str
) -> PRes<TxSegmentIter<'a>>
[src]
&'a self,
tx: &'a Transaction,
segment: &str
) -> PRes<TxSegmentIter<'a>>
Scan for persistent and in transaction records
Example
let mut tx = persy.begin()?; let data = vec![1;20]; let id = persy.insert_record(&mut tx, "seg", &data)?; let mut count = 0; for (id,content) in persy.scan_tx(&tx, "seg")? { println!("record size:{}",content.len()); count+=1; } assert_eq!(count,1);
pub fn scan_records(&self, segment: &str) -> PRes<RecordScanner>
[src]
please use scan
instead
Scan a segment for persistent records
Example
let mut tx = persy.begin()?; let data = vec![1;20]; let id = persy.insert_record(&mut tx, "seg", &data)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?; let mut count = 0; for found in persy.scan_records("seg")? { println!("record size:{}",found.content.len()); count+=1; } assert_eq!(count,1);
pub fn scan(&self, segment: &str) -> PRes<SegmentIter>
[src]
Scan a segment for persistent records
Example
let mut tx = persy.begin()?; let data = vec![1;20]; let id = persy.insert_record(&mut tx, "seg", &data)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?; let mut count = 0; for (id,content) in persy.scan("seg")? { println!("record size:{}",content.len()); count+=1; } assert_eq!(count,1);
pub fn update_record(
&self,
tx: &mut Transaction,
segment: &str,
id: &PersyId,
rec: &[u8]
) -> PRes<()>
[src]
&self,
tx: &mut Transaction,
segment: &str,
id: &PersyId,
rec: &[u8]
) -> PRes<()>
update the record content.
This updated content can be read only with the read_record_tx
till the transaction is committed.
Example
let mut tx = persy.begin()?; let data = vec![1;20]; let id = persy.insert_record(&mut tx, "seg", &data)?; let new_data = vec![2;20]; persy.update_record(&mut tx, "seg", &id, &new_data)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn delete_record(
&self,
tx: &mut Transaction,
segment: &str,
id: &PersyId
) -> PRes<()>
[src]
&self,
tx: &mut Transaction,
segment: &str,
id: &PersyId
) -> PRes<()>
delete a record.
The record will result deleted only reading it whit read_record_tx
till the transaction is committed.
Example
let mut tx = persy.begin()?; let data = vec![1;20]; let id = persy.insert_record(&mut tx, "seg", &data)?; persy.delete_record(&mut tx, "seg", &id)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn create_index<K, V>(
&self,
tx: &mut Transaction,
index_name: &str,
value_mode: ValueMode
) -> PRes<()> where
K: IndexType,
V: IndexType,
[src]
&self,
tx: &mut Transaction,
index_name: &str,
value_mode: ValueMode
) -> PRes<()> where
K: IndexType,
V: IndexType,
Create a new index with the name and the value management mode.
The create operation require two template arguments that are the types as keys and values of the index this have to match the following operation on the indexes.
Example
let mut tx = persy.begin()?; persy.create_index::<u8,u8>(&mut tx, "my_new_index", ValueMode::CLUSTER)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn drop_index(&self, tx: &mut Transaction, index_name: &str) -> PRes<()>
[src]
Drop an existing index.
Example
let mut tx = persy.begin()?; persy.drop_index(&mut tx, "my_new_index")?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn exists_index(&self, segment: &str) -> PRes<bool>
[src]
Check if a segment already exist in the storage
Example
let mut tx = persy.begin()?; persy.create_index::<u8,u8>(&mut tx, "my_new_index", ValueMode::REPLACE)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?; assert!(persy.exists_index("my_new_index")?);
pub fn exists_index_tx(&self, tx: &Transaction, segment: &str) -> PRes<bool>
[src]
Check if a segment already exist in the storage considering the transaction
Example
let mut tx = persy.begin()?; persy.create_index::<u8,u8>(&mut tx, "my_new_index", ValueMode::REPLACE)?; assert!(persy.exists_index_tx(&mut tx, "my_new_index")?);
pub fn put<K, V>(
&self,
tx: &mut Transaction,
index_name: &str,
k: K,
v: V
) -> PRes<()> where
K: IndexType,
V: IndexType,
[src]
&self,
tx: &mut Transaction,
index_name: &str,
k: K,
v: V
) -> PRes<()> where
K: IndexType,
V: IndexType,
Put a key value in an index following the value mode strategy.
Example
let mut tx = persy.begin()?; persy.create_index::<u8,u8>(&mut tx, "my_new_index", ValueMode::CLUSTER)?; persy.put::<u8,u8>(&mut tx, "my_new_index",10,10)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn remove<K, V>(
&self,
tx: &mut Transaction,
index_name: &str,
k: K,
v: Option<V>
) -> PRes<()> where
K: IndexType,
V: IndexType,
[src]
&self,
tx: &mut Transaction,
index_name: &str,
k: K,
v: Option<V>
) -> PRes<()> where
K: IndexType,
V: IndexType,
Remove a key and optionally a specific value from an index following the value mode strategy.
Example
let mut tx = persy.begin()?; persy.create_index::<u8,u8>(&mut tx, "my_new_index", ValueMode::CLUSTER)?; persy.put::<u8,u8>(&mut tx, "my_new_index",10,10)?; persy.remove::<u8,u8>(&mut tx, "my_new_index",10,Some(10))?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn get<K, V>(&self, index_name: &str, k: &K) -> PRes<Option<Value<V>>> where
K: IndexType,
V: IndexType,
[src]
K: IndexType,
V: IndexType,
Get a value or a group of values from a key.
Example
let val = persy.get::<u8,u8>("my_new_index",&10)?; if let Some(is_there) = val { // A value is actually there match is_there { Value::SINGLE(actual_value) => { }, Value::CLUSTER(actual_value) => { }, } }
pub fn get_tx<K, V>(
&self,
tx: &mut Transaction,
index_name: &str,
k: &K
) -> PRes<Option<Value<V>>> where
K: IndexType,
V: IndexType,
[src]
&self,
tx: &mut Transaction,
index_name: &str,
k: &K
) -> PRes<Option<Value<V>>> where
K: IndexType,
V: IndexType,
Get a value or a group of values from a key considering changes in transaction.
Example
persy.put::<u8,u8>(&mut tx, "my_new_index",10,10)?; let val = persy.get_tx::<u8,u8>(&mut tx,"my_new_index",&10)?; if let Some(is_there) = val { // A value is actually there match is_there { Value::SINGLE(actual_value) => { }, Value::CLUSTER(actual_value) => { }, } }
pub fn range<K, V, R>(
&self,
index_name: &str,
range: R
) -> PRes<IndexIter<K, V>> where
K: IndexType,
V: IndexType,
R: RangeBounds<K>,
[src]
&self,
index_name: &str,
range: R
) -> PRes<IndexIter<K, V>> 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,val) in iter { // A value is actually there match val { Value::SINGLE(actual_value) => { }, Value::CLUSTER(actual_value) => { }, } }
pub fn range_tx<'a, K, V, R>(
&self,
tx: &'a Transaction,
index_name: &str,
range: R
) -> PRes<TxIndexIter<'a, K, V>> where
K: IndexType,
V: IndexType,
R: RangeBounds<K> + Clone,
[src]
&self,
tx: &'a Transaction,
index_name: &str,
range: R
) -> PRes<TxIndexIter<'a, K, V>> where
K: IndexType,
V: IndexType,
R: RangeBounds<K> + Clone,
Browse a range of keys and values from and index including the transaction changes
Example
let persy = Persy::open("./data.persy",Config::new())?; let mut tx = persy.begin()?; persy.put::<u8,u8>(&mut tx, "my_new_index",10,10)?; { let iter:TxIndexIter<u8,u8> = persy.range_tx(&tx,"my_new_index",10..12)?; for (k,val) in iter { // A value is actually there match val { Value::SINGLE(actual_value) => { }, Value::CLUSTER(actual_value) => { }, } } } let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
pub fn rollback(&self, tx: Transaction) -> PRes<()>
[src]
Rollback a not yet prepared transaction.
All the resources used for eventual insert or update are released.
Example
let mut tx = persy.begin()?; let data = vec![1;20]; persy.insert_record(&mut tx, "seg", &data)?; persy.rollback(tx)?;
pub fn prepare_commit(&self, tx: Transaction) -> PRes<TransactionFinalize>
[src]
Prepare to commit a transaction, it will lock all the records involved in the transaction
till a commit
or rollback_prepared
is called.
Example
let mut tx = persy.begin()?; //Do what ever operations on the records let data = vec![1;20]; persy.insert_record(&mut tx, "seg", &data)?; let _= persy.prepare_commit(tx)?;
pub fn rollback_prepared(&self, finalizer: TransactionFinalize) -> PRes<()>
[src]
Rollback a prepared commit.
All the modification are rolled back and all the used resources are put released
Example
let mut tx = persy.begin()?; //Do what ever operations on the records let data = vec![1;20]; persy.insert_record(&mut tx, "seg", &data)?; let prepared = persy.prepare_commit(tx)?; persy.rollback_prepared(prepared)?;
pub fn commit(&self, finalizer: TransactionFinalize) -> PRes<()>
[src]
Finalize the commit result of a prepared commit.
All the operation done on the transaction are finalized all the lock released, all the old resources are released for reuse.
Example
let mut tx = persy.begin()?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared);
pub fn list_segments(&self) -> PRes<Vec<(String, SegmentId)>>
[src]
List all the existing segments.
Example
let mut tx = persy.begin()?; persy.create_segment(&mut tx, "seg")?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?; let segments = persy.list_segments()?; let names = segments.into_iter().map(|(name,_id)|name).collect::<Vec<String>>(); assert!(names.contains(&"seg".to_string()));
pub fn list_indexes(&self) -> PRes<Vec<(String, IndexInfo)>>
[src]
List all the existing segments.
Example
let mut tx = persy.begin()?; persy.create_segment(&mut tx, "seg")?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?; let segments = persy.list_segments()?; let names = segments.into_iter().map(|(name,_id)|name).collect::<Vec<String>>(); assert!(names.contains(&"seg".to_string()));
pub fn list_segments_tx(
&self,
tx: &Transaction
) -> PRes<Vec<(String, SegmentId)>>
[src]
&self,
tx: &Transaction
) -> PRes<Vec<(String, SegmentId)>>
List all the existing indexes.
Example
let mut tx = persy.begin()?; persy.create_index::<u8, u8>(&mut tx, "idx", ValueMode::REPLACE)?; let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?; let indexes = persy.list_indexes()?; let names = indexes.into_iter().map(|(name,_id)|name).collect::<Vec<String>>(); assert!(names.contains(&"idx".to_string()));
pub fn list_indexes_tx(
&self,
tx: &Transaction
) -> PRes<Vec<(String, IndexInfo)>>
[src]
&self,
tx: &Transaction
) -> PRes<Vec<(String, IndexInfo)>>
List all the existing indexes, considering changes in the transaction.
Example
let mut tx = persy.begin()?; persy.create_index::<u8, u8>(&mut tx, "idx", ValueMode::REPLACE)?; let indexes = persy.list_indexes_tx(&tx)?; let names = indexes.into_iter().map(|(name,_id)|name).collect::<Vec<String>>(); assert!(names.contains(&"idx".to_string())); let prepared = persy.prepare_commit(tx)?; persy.commit(prepared)?;
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,