[][src]Struct persy::Transaction

pub struct Transaction { /* fields omitted */ }

Transaction container, it include all the changes done in a transaction.

Implementations

impl Transaction[src]

pub fn create_segment(&mut self, segment: &str) -> PRes<SegmentId>[src]

Create a new segment with the provided name

Example

let mut tx = persy.begin()?;
tx.create_segment("my_new_segment")?;
tx.prepare()?.commit()?;

pub fn drop_segment(&mut self, segment: &str) -> PRes<()>[src]

Drop a existing segment

Example

let mut tx = persy.begin()?;
tx.drop_segment("existing_segment_name")?;
tx.prepare()?.commit()?;

pub fn exists_segment(&self, segment: &str) -> PRes<bool>[src]

Check if a segment already exist in the storage considering the transaction

Example

let mut tx = persy.begin()?;
tx.create_segment("my_new_segment")?;
assert!(tx.exists_segment("my_new_segment")?);

pub fn solve_segment_id(&self, segment: impl ToSegmentId) -> PRes<SegmentId>[src]

Resolves the segment to a SegmentId, considering the transaction

Example

let mut tx = persy.begin()?;
tx.create_segment("my_new_segment")?;
let segment_id = tx.solve_segment_id("my_new_segment")?;

pub fn solve_index_id(&self, index: impl ToIndexId) -> PRes<IndexId>[src]

Resolves the index name to a IndexId, considering the transaction

Example

let mut tx = persy.begin()?;
tx.create_index::<u8,u8>("my_new_index", ValueMode::CLUSTER)?;
let segment_id = tx.solve_index_id("my_new_index")?;

pub fn insert_record(
    &mut self,
    segment: impl ToSegmentId,
    rec: &[u8]
) -> PRes<PersyId>
[src]

👎 Deprecated:

use Transaction::insert instead

pub fn insert(&mut self, segment: impl ToSegmentId, rec: &[u8]) -> PRes<PersyId>[src]

Create a new record.

This function return an id that can be used by read, the record content can be read only with the transaction read till the transaction is committed.

Example

let mut tx = persy.begin()?;
let data = vec![1;20];
tx.insert("seg", &data)?;
tx.prepare()?.commit()?;

pub fn read_record(
    &mut self,
    segment: impl ToSegmentId,
    id: &PersyId
) -> PRes<Option<Vec<u8>>>
[src]

👎 Deprecated:

use Transaction::read instead

pub fn read(
    &mut self,
    segment: impl ToSegmentId,
    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 = tx.insert("seg", &data)?;
let read = tx.read("seg", &id)?.expect("record exists");
assert_eq!(data,read);

pub fn scan<'a>(
    &'a mut self,
    segment: impl ToSegmentId
) -> PRes<TxSegmentIter<'a>>
[src]

Scan for persistent and in transaction records

Example

let mut tx = persy.begin()?;
let data = vec![1;20];
let id = tx.insert("seg", &data)?;
let mut count = 0;
for (id,content) in tx.scan("seg")? {
    println!("record size:{}",content.len());
    count+=1;
}
assert_eq!(count,1);

pub fn update_record(
    &mut self,
    segment: impl ToSegmentId,
    id: &PersyId,
    rec: &[u8]
) -> PRes<()>
[src]

👎 Deprecated:

use Transaction::update instead

pub fn update(
    &mut self,
    segment: impl ToSegmentId,
    id: &PersyId,
    rec: &[u8]
) -> PRes<()>
[src]

Update the record content.

This updated content can be read only with the [transaction read] till the transaction is committed.

Example

let mut tx = persy.begin()?;
let data = vec![1;20];
let id = tx.insert("seg", &data)?;
let new_data = vec![2;20];
tx.update("seg", &id, &new_data)?;

pub fn delete_record(
    &mut self,
    segment: impl ToSegmentId,
    id: &PersyId
) -> PRes<()>
[src]

👎 Deprecated:

use Transaction::delete instead

pub fn delete(&mut self, segment: impl ToSegmentId, id: &PersyId) -> PRes<()>[src]

Delete a record.

The record will result deleted only reading it with transaction read till the transaction is committed.

Example

let mut tx = persy.begin()?;
let data = vec![1;20];
let id = tx.insert("seg", &data)?;
tx.delete_record("seg", &id)?;

pub fn create_index<K, V>(
    &mut self,
    index_name: &str,
    value_mode: ValueMode
) -> PRes<()> where
    K: IndexType,
    V: IndexType
[src]

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()?;
tx.create_index::<u8,u8>("my_new_index", ValueMode::CLUSTER)?;

pub fn drop_index(&mut self, index_name: &str) -> PRes<()>[src]

Drop an existing index.

Example

let mut tx = persy.begin()?;
tx.drop_index("my_new_index")?;

pub fn exists_index(&self, segment: &str) -> PRes<bool>[src]

Check if a segment already exist in the storage considering the transaction

Example

let mut tx = persy.begin()?;
tx.create_index::<u8,u8>("my_new_index", ValueMode::REPLACE)?;
assert!(tx.exists_index("my_new_index")?);

pub fn put<K, V>(&mut self, index_name: &str, k: K, v: V) -> PRes<()> where
    K: IndexType,
    V: IndexType
[src]

Put a key value in an index following the value mode strategy.

Example

let mut tx = persy.begin()?;
tx.create_index::<u8,u8>("my_new_index", ValueMode::CLUSTER)?;
tx.put::<u8,u8>("my_new_index",10,10)?;
tx.prepare()?.commit()?;

pub fn remove<K, V>(&mut self, index_name: &str, k: K, v: Option<V>) -> PRes<()> where
    K: IndexType,
    V: IndexType
[src]

Remove a key and optionally a specific value from an index following the value mode strategy.

Example

let mut tx = persy.begin()?;
tx.create_index::<u8,u8>("my_new_index", ValueMode::CLUSTER)?;
tx.put::<u8,u8>("my_new_index",10,10)?;
tx.remove::<u8,u8>("my_new_index",10,Some(10))?;

pub fn get<K, V>(&mut self, index_name: &str, k: &K) -> PRes<Option<Value<V>>> where
    K: IndexType,
    V: IndexType
[src]

Get a value or a group of values from a key considering changes in transaction.

Example

tx.put::<u8,u8>("my_new_index",10,10)?;
let val = tx.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 range<'a, K, V, R>(
    &'a mut self,
    index_name: &str,
    range: R
) -> PRes<TxIndexIter<'a, K, V>> where
    K: IndexType,
    V: IndexType,
    R: RangeBounds<K>, 
[src]

Browse a range of keys and values from an index including the transaction changes

Example

let persy = Persy::open("./data.persy",Config::new())?;
let mut tx = persy.begin()?;
tx.put::<u8,u8>("my_new_index",10,10)?;
{
    let iter:TxIndexIter<u8,u8> = tx.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) => {
            },
        }
    }
}
tx.prepare()?.commit()?;

pub fn rollback(self) -> 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];
tx.insert("seg", &data)?;
tx.rollback()?;

pub fn prepare_commit(self) -> PRes<TransactionFinalize>[src]

👎 Deprecated:

replaced by Transaction::prepare

pub fn prepare(self) -> PRes<TransactionFinalize>[src]

Prepare to commit a transaction, when this method return all the validation checks are done and is guaranteed that the transaction can be committed successfully

it will lock all the records involved in the transaction till a commit or rollback is called.

Example

let mut tx = persy.begin()?;
//Do what ever operations on the records
let data = vec![1;20];
tx.insert("seg", &data)?;
tx.prepare()?;

pub fn list_segments(&self) -> PRes<Vec<(String, SegmentId)>>[src]

List all the existing segments, considering all the changes in transaction.

Example

let mut tx = persy.begin()?;
tx.create_segment("seg")?;
let segments = tx.list_segments()?;
let names = segments.into_iter().map(|(name,_id)|name).collect::<Vec<String>>();
assert!(names.contains(&"seg".to_string()));
tx.prepare()?.commit()?;

pub fn list_indexes(&self) -> PRes<Vec<(String, IndexInfo)>>[src]

List all the existing indexes, considering changes in the transaction.

Example

let mut tx = persy.begin()?;
tx.create_index::<u8, u8>("idx", ValueMode::REPLACE)?;
let indexes = tx.list_indexes()?;
let names = indexes.into_iter().map(|(name,_id)|name).collect::<Vec<String>>();
assert!(names.contains(&"idx".to_string()));
tx.prepare()?.commit()?;

Trait Implementations

impl Drop for Transaction[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,