[][src]Struct persy::Persy

pub struct Persy { /* fields omitted */ }

Main structure to manipolate persy storage files

Methods

impl Persy[src]

pub fn create<P: Into<String>>(path: P) -> PRes<()>[src]

Create a new database file.

Errors

if the file already exist fail.

pub fn create_from_file(file: File) -> PRes<()>[src]

Create a new database file.

Errors

if the file already exist fail.

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]

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]

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: &Vec<u8>
) -> PRes<PersyId>
[src]

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 transacion is commited.

Expample

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]

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]

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_records(&self, segment: &str) -> PRes<RecordScanner>[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 found in persy.scan_records("seg")? {
    println!("record size:{}",found.content.len());
    count+=1;
}
assert_eq!(count,1);

pub fn update_record(
    &self,
    tx: &mut Transaction,
    segment: &str,
    id: &PersyId,
    rec: &Vec<u8>
) -> PRes<()>
[src]

update the record content.

This updated content can be read only with the read_record_tx till the transacion is commited.

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]

delete a record.

The record will result deleted only reading it whit read_record_tx till the transacion is commited.

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 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 finalizated 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);

Trait Implementations

impl Clone for Persy[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Persy

impl Sync for Persy

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]