[−][src]Struct persy::Persy
Main structure to operate persy storage files
Implementations
impl Persy
[src]
pub fn create<P: AsRef<Path>>(path: P) -> PRes<()>
[src]
pub fn create_from_file(file: File) -> PRes<()>
[src]
pub fn open<P: AsRef<Path>>(path: P, config: Config) -> PRes<Persy>
[src]
Open a database file.
The file should have been created with Persy::create
Errors
Fails if the file does not exist.
pub fn open_with_recover<P: AsRef<Path>, 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
Fails if the file does not exist.
pub fn recover<P: AsRef<Path>>(path: P, config: Config) -> PRes<Recover>
[src]
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.
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
Fails if the file does not exist.
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
Fails if the file does not exist.
pub fn open_or_create_with<P, F>(
path: P,
config: Config,
prepare: F
) -> PRes<Persy> where
P: AsRef<Path>,
F: FnOnce(&Persy) -> PRes<()>,
[src]
path: P,
config: Config,
prepare: F
) -> PRes<Persy> where
P: AsRef<Path>,
F: FnOnce(&Persy) -> PRes<()>,
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(()) })?;
pub fn begin(&self) -> PRes<Transaction>
[src]
Begin a new transaction.
The transaction isolation level is 'read_commited'.
for commit call prepare
and commit
Example
let mut tx = persy.begin()?; // ... tx.prepare()?.commit()?;
pub fn begin_id(&self, meta_id: TransactionId) -> PRes<Transaction>
[src]
replaced by 'begin_with'
Begin a new transaction specifying and id usable for crash recover.
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_id(tx_id)?; // ... tx.prepare()?.commit()?;
pub fn begin_with(&self, config: TransactionConfig) -> PRes<Transaction>
[src]
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()?;
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()?; 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) -> PRes<SegmentId>
[src]
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")?;
pub fn solve_index_id(&self, index: impl ToIndexId) -> PRes<IndexId>
[src]
Resolves the index to a IndexId
Example
let mut tx = persy.begin()?; tx.create_index::<u8,u8>("my_new_index", ValueMode::CLUSTER)?; let prepared = tx.prepare()?; prepared.commit()?; let segment_id = persy.solve_index_id("my_new_index")?;
pub fn read_record(
&self,
segment: impl ToSegmentId,
id: &PersyId
) -> PRes<Option<Vec<u8>>>
[src]
&self,
segment: impl ToSegmentId,
id: &PersyId
) -> PRes<Option<Vec<u8>>>
use Persy::read instead
pub fn read(
&self,
segment: impl ToSegmentId,
id: &PersyId
) -> PRes<Option<Vec<u8>>>
[src]
&self,
segment: impl ToSegmentId,
id: &PersyId
) -> PRes<Option<Vec<u8>>>
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);
pub fn scan(&self, segment: impl ToSegmentId) -> PRes<SegmentIter>
[src]
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);
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()?; tx.create_index::<u8,u8>("my_new_index", ValueMode::REPLACE)?; let prepared = tx.prepare()?; prepared.commit()?; assert!(persy.exists_index("my_new_index")?);
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 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 list_segments(&self) -> PRes<Vec<(String, SegmentId)>>
[src]
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()));
pub fn list_indexes(&self) -> PRes<Vec<(String, IndexInfo)>>
[src]
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(&"seg".to_string()));
pub fn snapshot(&self) -> PRes<Snapshot>
[src]
Create a read snapshot at the current data status.
let persy = Persy::open("./open.persy",Config::new())?; // ... More logic let snapshot = persy.snapshot()?; // .. Access data from the snapshot
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Persy
[src]
impl Send for Persy
[src]
impl Sync for Persy
[src]
impl Unpin for Persy
[src]
impl !UnwindSafe for Persy
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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.
pub 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.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,