Struct persy::Snapshot[][src]

pub struct Snapshot { /* fields omitted */ }

Read snapshot at a specific point in time.

All the changes from transactions committed at the specific point in time were the snapshot was create are readable from this snapshot, all subsequent transactions are ignored.

Copy of the data old data is kept on the disc, with indexing access from in memory structures, on drop of the Snapshot, if there are no older snapshot all the data old by this snapshot not existing anymore in the final state will be cleaned up.

Implementations

impl Snapshot[src]

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

👎 Deprecated:

replaced by Snapshot::read

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

Read the record content at the point of time the snapshot was taken ignoring all following committed transactions

Example

let mut tx = persy.begin()?;
let data = vec![1;20];
let id = tx.insert("seg", &data)?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
let read = snapshot.read("seg", &id)?.expect("record exists");
assert_eq!(data,read);

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

Scan for records existing at the moment of snapshot creation, ignoring all the following committed transactions.

Example

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

pub fn get<K, V>(&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 at the point the snapshot was taken ignoring all following committed transactions.

Example

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

Browse a range of keys and values from an index at the pointing that the snapshot was created ignoring all the following committed transactions.

Example

let persy = Persy::open("./data.persy",Config::new())?;
let mut tx = persy.begin()?;
tx.put::<u8,u8>("my_new_index",10,10)?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
let iter:IndexIter<u8,u8> = snapshot.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 list_segments(&self) -> PRes<Vec<(String, SegmentId)>>[src]

List all the existing segments, at the pointing that the snapshot was created ignoring all the following committed transactions.

Example

let mut tx = persy.begin()?;
tx.create_segment("seg")?;
tx.prepare()?.commit()?;
let snapshot = persy.snapshot()?;
let segments = snapshot.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 indexes, at the pointing that the snapshot was created ignoring all the following committed transactions.

Example

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

Trait Implementations

impl Clone for Snapshot[src]

fn clone(&self) -> Snapshot[src]

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl !RefUnwindSafe for Snapshot

impl Send for Snapshot

impl Sync for Snapshot

impl Unpin for Snapshot

impl !UnwindSafe for Snapshot

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

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

pub fn vzip(self) -> V