pub struct LMDBer {
pub filer: BaseFiler,
pub env: Option<Arc<Env>>,
pub readonly: bool,
/* private fields */
}Expand description
LMDBer is a wrapper around LMDB database providing an interface similar to Filer
Fields§
§filer: BaseFilerBase Filer instance
env: Option<Arc<Env>>LMDB environment
readonly: boolWhether the database is opened in readonly mode
Implementations§
Source§impl LMDBer
impl LMDBer
pub const MAX_NAMED_DBS: u32 = 96
pub const MAP_SIZE: usize = 104857600
Sourcepub fn new<S1, S2>(
name: S1,
base: S2,
temp: bool,
head_dir_path: Option<PathBuf>,
perm: Option<u32>,
reopen: bool,
clear: bool,
reuse: bool,
clean: bool,
filed: bool,
extensioned: bool,
mode: Option<String>,
fext: Option<String>,
readonly: bool,
) -> Result<Self, DBError>
pub fn new<S1, S2>( name: S1, base: S2, temp: bool, head_dir_path: Option<PathBuf>, perm: Option<u32>, reopen: bool, clear: bool, reuse: bool, clean: bool, filed: bool, extensioned: bool, mode: Option<String>, fext: Option<String>, readonly: bool, ) -> Result<Self, DBError>
Create a new LMDBer instance
Sourcepub fn reopen(
&mut self,
temp: Option<bool>,
head_dir_path: Option<PathBuf>,
perm: Option<u32>,
clear: bool,
reuse: bool,
clean: bool,
mode: Option<String>,
fext: Option<String>,
) -> Result<bool, DBError>
pub fn reopen( &mut self, temp: Option<bool>, head_dir_path: Option<PathBuf>, perm: Option<u32>, clear: bool, reuse: bool, clean: bool, mode: Option<String>, fext: Option<String>, ) -> Result<bool, DBError>
Reopen the LMDB database
Sourcepub fn set_version(&mut self, version: String)
pub fn set_version(&mut self, version: String)
Set the version of the database
pub fn close(&mut self, clear: bool) -> Result<bool, DBError>
pub fn create_database( &self, name: Option<&str>, dup_sort: Option<bool>, ) -> Result<BytesDatabase, DBError>
pub fn open_database( &self, name: Option<&str>, ) -> Result<Option<BytesDatabase>, DBError>
pub fn len(&self, db: &BytesDatabase) -> Result<u64, DBError>
pub fn put_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], ) -> Result<bool, DBError>
pub fn set_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], ) -> Result<bool, DBError>
pub fn get_val( &self, db: &BytesDatabase, key: &[u8], ) -> Result<Option<Vec<u8>>, DBError>
Sourcepub fn get_val_last(
&self,
db: &BytesDatabase,
key: &[u8],
) -> Result<Option<Vec<u8>>, DBError>
pub fn get_val_last( &self, db: &BytesDatabase, key: &[u8], ) -> Result<Option<Vec<u8>>, DBError>
pub fn del_val(&self, db: &BytesDatabase, key: &[u8]) -> Result<bool, DBError>
pub fn cnt(&self, db: &BytesDatabase) -> Result<usize, DBError>
Sourcepub fn get_top_items_iter<F>(
&self,
db: &BytesDatabase,
prefix: &[u8],
cb: F,
) -> Result<usize, DBError>
pub fn get_top_items_iter<F>( &self, db: &BytesDatabase, prefix: &[u8], cb: F, ) -> Result<usize, DBError>
pub fn del_top_val( &self, db: &BytesDatabase, prefix: &[u8], ) -> Result<bool, DBError>
Sourcepub fn set_on_val(
&self,
db: &BytesDatabase,
key: &[u8],
on: Option<u64>,
val: &[u8],
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn set_on_val( &self, db: &BytesDatabase, key: &[u8], on: Option<u64>, val: &[u8], sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Write serialized bytes val to location at onkey consisting of key + sep + serialized on in db. Overwrites pre-existing value at onkey if any.
§Parameters
db: Named sub database in LMDBkey: Key within sub db’s keyspaceon: Ordinal number at which to writeval: Bytes to be written at onkeysep: Separator byte for constructing the composite key
§Returns
Ok(true): If successful write (i.e., onkey not already in db)Ok(false): OtherwiseErr(DBError): If a database error occurs
Sourcepub fn append_on_val(
&self,
db: &BytesDatabase,
key: &[u8],
val: &[u8],
sep: Option<[u8; 1]>,
) -> Result<u64, DBError>
pub fn append_on_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], sep: Option<[u8; 1]>, ) -> Result<u64, DBError>
Appends val in order after last previous onkey in db where onkey has same given key prefix but with different serialized on suffix attached with sep.
Returns ordinal number on, of appended entry. Appended on is 1 greater than previous latest on at key.
Works with either dupsort==True or False since always creates new full key.
§Parameters
db: Named sub database in LMDBkey: Key within sub db’s keyspaceval: Bytes to be written at onkeysep: Separator byte for constructing the composite key
§Returns
Ok(on): Ordinal number of newly appended valErr(DBError): If a database error occurs
Sourcepub fn put_on_val(
&self,
db: &BytesDatabase,
key: &[u8],
on: u32,
val: &[u8],
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn put_on_val( &self, db: &BytesDatabase, key: &[u8], on: u32, val: &[u8], sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Write serialized bytes val to location at onkey consisting of key + sep + serialized on in db. Does not overwrite.
§Returns
- Result<bool, DBError>: True if successful write i.e onkey not already in db, False otherwise
§Parameters
- db: named sub db of lmdb
- key: key within sub db’s keyspace plus trailing part on
- on: ordinal number at which write
- val: to be written at onkey
- sep: separator bytes for split
Sourcepub fn get_on_val(
&self,
db: &BytesDatabase,
key: &[u8],
on: u32,
sep: Option<[u8; 1]>,
) -> Result<Option<Vec<u8>>, DBError>
pub fn get_on_val( &self, db: &BytesDatabase, key: &[u8], on: u32, sep: Option<[u8; 1]>, ) -> Result<Option<Vec<u8>>, DBError>
Sourcepub fn del_on_val(
&self,
db: &BytesDatabase,
key: &[u8],
on: u32,
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn del_on_val( &self, db: &BytesDatabase, key: &[u8], on: u32, sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Sourcepub fn cnt_on_vals(
&self,
db: &BytesDatabase,
key: Option<&[u8]>,
on: Option<u64>,
sep: Option<[u8; 1]>,
) -> Result<usize, DBError>
pub fn cnt_on_vals( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, ) -> Result<usize, DBError>
Returns count of all ordinal keyed vals with key but different on tail in db starting at ordinal number on of key.
§Returns
- Result<usize, DBError>: count of matching entries
§Parameters
- db: named sub db of lmdb
- key: key within sub db’s keyspace (when empty, counts whole db)
- on: ordinal number at which to initiate count
- sep: separator bytes for split
Sourcepub fn get_on_item_iter<F>(
&self,
db: &BytesDatabase,
key: Option<&[u8]>,
on: Option<u64>,
sep: Option<[u8; 1]>,
callback: F,
) -> Result<(), DBError>
pub fn get_on_item_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
- txn: the read transaction to use
Sourcepub fn get_on_val_iter<F>(
&self,
db: &BytesDatabase,
key: Option<&[u8]>,
on: Option<u64>,
sep: Option<[u8; 1]>,
callback: F,
) -> Result<(), DBError>
pub fn get_on_val_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
- txn: the read transaction to use
Sourcepub fn put_io_set_vals(
&self,
db: &BytesDatabase,
key: &[u8],
vals: &[&[u8]],
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn put_io_set_vals( &self, db: &BytesDatabase, key: &[u8], vals: &[&[u8]], sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Add each val in vals to insertion ordered set of values all with the same apparent effective key for each val that is not already in set of vals at key. Uses hidden ordinal key suffix for insertion ordering. The suffix is appended and stripped transparently.
§Parameters
db: Instance of named sub db with dupsort==Falsekey: Apparent effective keyvals: Serialized values to add to set of vals at keysep: Optional separator byte (defaults to ‘.’)
§Returns
Ok(bool): True if added to set, false if already in setErr(DBError): If a database error occurs
Sourcepub fn get_io_set_vals(
&self,
db: &BytesDatabase,
key: &[u8],
ion: Option<u64>,
sep: Option<[u8; 1]>,
) -> Result<Vec<Vec<u8>>, DBError>
pub fn get_io_set_vals( &self, db: &BytesDatabase, key: &[u8], ion: Option<u64>, sep: Option<[u8; 1]>, ) -> Result<Vec<Vec<u8>>, DBError>
Returns the insertion ordered set of values at the same apparent effective key. Uses hidden ordinal key suffix for insertion ordering. The suffix is appended and stripped transparently.
§Parameters
db: Instance of named sub db with dupsort==Falsekey: Apparent effective keyion: starting ordinal value, default 0sep: Optional separator byte (defaults to ‘.’)
§Returns
Ok(Vec<Vec<u8>>): The ordered list of values at this keyErr(DBError): If a database error occurs
Sourcepub fn add_io_set_val(
&self,
db: &BytesDatabase,
key: &[u8],
val: &[u8],
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn add_io_set_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Add val idempotently to insertion ordered set of values all with the same apparent effective key if val not already in set of vals at key. Uses hidden ordinal key suffix for insertion ordering. The suffix is appended and stripped transparently.
§Parameters
db: Instance of named sub db with dupsort==Falsekey: Apparent effective keyval: Serialized value to addsep: Optional separator byte (defaults to ‘.’)
§Returns
Ok(bool): True if added to set, false if already in setErr(DBError): If a database error occurs
Sourcepub fn del_io_set_vals(
&self,
db: &BytesDatabase,
key: &[u8],
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn del_io_set_vals( &self, db: &BytesDatabase, key: &[u8], sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Deletes all values at apparent effective key. Uses hidden ordinal key suffix for insertion ordering. The suffix is appended and stripped transparently.
§Parameters
db: Instance of named sub db with dupsort==Falsekey: Apparent effective keysep: Optional separator byte (defaults to ‘.’)
§Returns
Ok(bool): True if values were deleted at key, False if no values at keyErr(DBError): If a database error occurs
Sourcepub fn del_io_set_val(
&self,
db: &BytesDatabase,
key: &[u8],
val: &[u8],
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn del_io_set_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Deletes val at apparent effective key if exists. Uses hidden ordinal key suffix for insertion ordering. The suffix is appended and stripped transparently.
Because the insertion order of val is not provided must perform a linear search over set of values.
Another problem is that vals may get added and deleted in any order so the max suffix ion may creep up over time. The suffix ordinal max > 2**16 is an impossibly large number, however, so the suffix will not max out practically. But it’s not the most elegant solution.
§Parameters
db: Instance of named sub db with dupsort==Falsekey: Apparent effective keyval: value to deletesep: Optional separator byte (defaults to ‘.’)
§Returns
Ok(bool): True if val was deleted at key, False if val not found at keyErr(DBError): If a database error occurs
Sourcepub fn set_io_set_vals(
&self,
db: &BytesDatabase,
key: &[u8],
vals: &[impl AsRef<[u8]>],
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn set_io_set_vals( &self, db: &BytesDatabase, key: &[u8], vals: &[impl AsRef<[u8]>], sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Erase all vals at key and then add unique vals as insertion ordered set of values all with the same apparent effective key. Uses hidden ordinal key suffix for insertion ordering. The suffix is appended and stripped transparently.
§Parameters
db: Instance of named sub db with dupsort==Falsekey: Apparent effective keyvals: Serialized values to add to set of vals at keysep: Optional separator byte (defaults to ‘.’)
§Returns
Ok(bool): True if values were added to setErr(DBError): If a database error occurs
Sourcepub fn cnt_io_set_vals(
&self,
db: &BytesDatabase,
key: &[u8],
sep: Option<[u8; 1]>,
) -> Result<usize, DBError>
pub fn cnt_io_set_vals( &self, db: &BytesDatabase, key: &[u8], sep: Option<[u8; 1]>, ) -> Result<usize, DBError>
Count all values with the same apparent effective key. Uses hidden ordinal key suffix for insertion ordering. The suffix is appended and stripped transparently.
§Parameters
db: Instance of named sub db with dupsort==Falsekey: Apparent effective keysep: Optional separator byte (defaults to ‘.’)
§Returns
Ok(usize): Count of values in set at apparent effective keyErr(DBError): If a database error occurs
Sourcepub fn get_io_set_vals_iter<F>(
&self,
db: &BytesDatabase,
key: &[u8],
ion: Option<u64>,
sep: Option<[u8; 1]>,
callback: F,
) -> Result<(), DBError>
pub fn get_io_set_vals_iter<F>( &self, db: &BytesDatabase, key: &[u8], ion: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
Returns an iterator over insertion ordered set of values at same apparent effective key. Uses hidden ordinal key suffix for insertion ordering. The suffix is appended and stripped transparently.
§Parameters
db: Instance of named sub db with dupsort==Falsekey: Apparent effective keyion: Optional starting ordinal value, default 0sep: Optional separator byte (defaults to ‘.’)callback: Function to call for each value found
§Returns
Ok(()): If iteration completed successfullyErr(DBError): If a database error occurs
Sourcepub fn get_io_set_val_last(
&self,
db: &BytesDatabase,
key: &[u8],
sep: Option<[u8; 1]>,
) -> Result<Option<Vec<u8>>, DBError>
pub fn get_io_set_val_last( &self, db: &BytesDatabase, key: &[u8], sep: Option<[u8; 1]>, ) -> Result<Option<Vec<u8>>, DBError>
Returns the last added value at the apparent effective key if any, otherwise None if no entry.
Uses hidden ordinal key suffix for insertion ordering. The suffix is appended and stripped transparently.
§Parameters
db: Instance of named sub db with dupsort==Falsekey: Apparent effective keysep: Optional separator byte (defaults to ‘.’)
§Returns
Ok(Option<Vec<u8>>): The last value if found, None otherwiseErr(DBError): If a database error occurs
Sourcepub fn get_top_io_set_items_iter<F>(
&self,
db: &BytesDatabase,
top: &[u8],
sep: Option<[u8; 1]>,
cb: F,
) -> Result<usize, DBError>
pub fn get_top_io_set_items_iter<F>( &self, db: &BytesDatabase, top: &[u8], sep: Option<[u8; 1]>, cb: F, ) -> Result<usize, DBError>
Get items with a given prefix from an IO set and process them with a callback function, stripping the insertion order suffix from keys before passing to the callback.
§Parameters
db: The database to search intop: The prefix to match keys against (empty for all items)cb: Callback function that takes apparent key (with suffix removed) and value pairssep: Optional separator byte (defaults to ‘.’)
§Returns
Ok(count): Number of items processedErr(DBError): If a database error occurs
Sourcepub fn add_val(
&self,
db: &BytesDatabase,
key: &[u8],
val: &[u8],
) -> Result<bool, DBError>
pub fn add_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], ) -> Result<bool, DBError>
Add value bytes as duplicate to key in database Adds to existing values at key if any Returns true if written else false if duplicate value already exists
Duplicates are inserted in lexicographic order not insertion order. LMDB does not insert a duplicate unless it is a unique value for that key.
Does inclusion test to detect if duplicate already exists Uses a HashSet for the duplicate inclusion test. Set inclusion scales with O(1) whereas list inclusion scales with O(n).
§Parameters
db- opened named sub database with dupsort=Truekey- bytes of key within sub db’s keyspaceval- bytes of value to be written
Sourcepub fn put_vals(
&self,
db: &BytesDatabase,
key: &[u8],
vals: &[impl AsRef<[u8]>],
) -> Result<bool, DBError>
pub fn put_vals( &self, db: &BytesDatabase, key: &[u8], vals: &[impl AsRef<[u8]>], ) -> Result<bool, DBError>
Put each entry from a list of values to the given key in the database Adds to existing values at key if any Returns true if successful
Duplicates are inserted in lexicographic order not insertion order. LMDB does not insert a duplicate unless it is a unique value for that key.
§Parameters
db- opened named sub database with dupsort=Truekey- bytes of key within sub db’s keyspacevals- list of values to be written
Sourcepub fn get_vals_iter<F>(
&self,
db: &BytesDatabase,
key: &[u8],
callback: F,
) -> Result<(), DBError>
pub fn get_vals_iter<F>( &self, db: &BytesDatabase, key: &[u8], callback: F, ) -> Result<(), DBError>
Return iterator of all duplicate values at key in database Uses a callback function to handle each value
Duplicates are retrieved in lexicographic order not insertion order.
§Parameters
db- opened named sub database with dupsort=Truekey- bytes of key within sub db’s keyspacecallback- function that processes each value
Sourcepub fn cnt_vals(&self, db: &BytesDatabase, key: &[u8]) -> Result<usize, DBError>
pub fn cnt_vals(&self, db: &BytesDatabase, key: &[u8]) -> Result<usize, DBError>
Return count of duplicate values at key in database, or zero otherwise
§Parameters
db- opened named sub database with dupsort=Truekey- bytes of key within sub db’s keyspace
Sourcepub fn del_vals(
&self,
db: &BytesDatabase,
key: &[u8],
val: Option<&[u8]>,
) -> Result<bool, DBError>
pub fn del_vals( &self, db: &BytesDatabase, key: &[u8], val: Option<&[u8]>, ) -> Result<bool, DBError>
Deletes all values at key in database if val is empty, otherwise deletes the duplicate that equals val
Returns true if key (and val if not empty) exists in database, otherwise false
§Parameters
db- opened named sub database with dupsort=Truekey- bytes of key within sub db’s keyspaceval- bytes of duplicate value at key to delete (empty means delete all duplicates)
Sourcepub fn get_io_dup_vals(
&self,
db: &BytesDatabase,
key: &[u8],
) -> Result<Vec<Vec<u8>>, DBError>
pub fn get_io_dup_vals( &self, db: &BytesDatabase, key: &[u8], ) -> Result<Vec<Vec<u8>>, DBError>
Return list of duplicate values at key in db in insertion order Returns empty vector if no entry at key Removes prepended proem ordinal from each val before returning Assumes DB opened with dupsort=True
Duplicates at a given key preserve insertion order of duplicate. Because lmdb is lexocographic an insertion ordering proem is prepended to all values that makes lexocographic order that same as insertion order.
Duplicates are ordered as a pair of key plus value so prepending proem to each value changes duplicate ordering. Proem is 33 characters long. With 32 character hex string followed by ‘.’ for essentially unlimited number of values which will be limited by memory.
§Parameters
db: Opened named sub db with dupsort=Truekey: bytes of key within sub db’s keyspace
§Returns
Ok(Vec<Vec<u8>>): List of values with proem removedErr(DBError): If a database error occurs
Sourcepub fn put_io_dup_vals(
&self,
db: &BytesDatabase,
key: &[u8],
vals: &[impl AsRef<[u8]>],
) -> Result<bool, DBError>
pub fn put_io_dup_vals( &self, db: &BytesDatabase, key: &[u8], vals: &[impl AsRef<[u8]>], ) -> Result<bool, DBError>
Write each entry from list of bytes vals to key in db in insertion order Adds to existing values at key if any Returns true if at least one of vals is added as dup, false otherwise Assumes DB opened with dupsort=True
Duplicates at a given key preserve insertion order of duplicate. Because lmdb is lexocographic an insertion ordering proem is prepended to all values that makes lexocographic order that same as insertion order.
Duplicates are ordered as a pair of key plus value so prepending proem to each value changes duplicate ordering. Proem is 33 characters long. With 32 character hex string followed by ‘.’ for essentially unlimited number of values which will be limited by memory.
§Parameters
db: Opened named sub db with dupsort=Truekey: bytes of key within sub db’s keyspacevals: list of bytes of values to be written
§Returns
Ok(bool): True if at least one value was added, false otherwiseErr(DBError): If a database error occurs
Sourcepub fn add_io_dup_val(
&self,
db: &BytesDatabase,
key: &[u8],
val: &[u8],
) -> Result<bool, DBError>
pub fn add_io_dup_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], ) -> Result<bool, DBError>
Add val bytes as dup in insertion order to key in db Adds to existing values at key if any Returns True if written else False if val is already a dup Actual value written include prepended proem ordinal Assumes DB opened with dupsort=True
Duplicates at a given key preserve insertion order of duplicate. Because lmdb is lexocographic an insertion ordering proem is prepended to all values that makes lexocographic order that same as insertion order.
Duplicates are ordered as a pair of key plus value so prepending proem to each value changes duplicate ordering. Proem is 33 characters long. With 32 character hex string followed by ‘.’ for essentially unlimited number of values which will be limited by memory.
§Parameters
db: Opened named sub db with dupsort=Truekey: bytes of key within sub db’s keyspaceval: bytes of value to be written
§Returns
Ok(bool): True if written, false if val is already a dupErr(DBError): If a database error occurs
pub fn get_io_dup_vals_iter<F>( &self, db: &BytesDatabase, key: &[u8], callback: F, ) -> Result<(), DBError>
Sourcepub fn cnt_io_dup_vals(
&self,
db: &BytesDatabase,
key: &[u8],
) -> Result<usize, DBError>
pub fn cnt_io_dup_vals( &self, db: &BytesDatabase, key: &[u8], ) -> Result<usize, DBError>
Return count of dup values at key in db, or zero otherwise Assumes DB opened with dupsort=True
Duplicates at a given key preserve insertion order of duplicate. Because lmdb is lexocographic an insertion ordering proem is prepended to all values that makes lexocographic order that same as insertion order.
Duplicates are ordered as a pair of key plus value so prepending proem to each value changes duplicate ordering. Proem is 33 characters long. With 32 character hex string followed by ‘.’ for essentially unlimited number of values which will be limited by memory.
§Parameters
db: Opened named sub db with dupsort=Truekey: bytes of key within sub db’s keyspace
§Returns
Ok(usize): Count of duplicate values at key (0 if key doesn’t exist)Err(DBError): If a database error occurs
Sourcepub fn del_io_dup_vals(
&self,
db: &BytesDatabase,
key: &[u8],
) -> Result<bool, DBError>
pub fn del_io_dup_vals( &self, db: &BytesDatabase, key: &[u8], ) -> Result<bool, DBError>
Deletes all values at key in db if key present. Returns true if key exists and was deleted, false otherwise
Duplicates at a given key preserve insertion order of duplicate. Because lmdb is lexocographic an insertion ordering proem is prepended to all values that makes lexocographic order that same as insertion order.
Duplicates are ordered as a pair of key plus value so prepending proem to each value changes duplicate ordering. Proem is 33 characters long. With 32 character hex string followed by ‘.’ for essentially unlimited number of values which will be limited by memory.
§Parameters
db: Opened named sub db with dupsort=Truekey: bytes of key within sub db’s keyspace
§Returns
Ok(bool): True if key existed and was deleted, false otherwiseErr(DBError): If a database error occurs
Sourcepub fn del_io_dup_val(
&self,
db: &BytesDatabase,
key: &[u8],
val: &[u8],
) -> Result<bool, DBError>
pub fn del_io_dup_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], ) -> Result<bool, DBError>
Deletes dup io val at key in db. Performs strip search to find match. Strips proems and then searches. Returns True if delete else False if val not present Assumes DB opened with dupsort=True
Duplicates at a given key preserve insertion order of duplicate. Because lmdb is lexocographic an insertion ordering proem is prepended to all values that makes lexocographic order that same as insertion order Duplicates are ordered as a pair of key plus value so prepending proem to each value changes duplicate ordering. Proem is 33 characters long. With 32 character hex string followed by ‘.’ for essentially unlimited number of values which will be limited by memory.
Does a linear search so not very efficient when not deleting from the front. This is hack for supporting escrow which needs to delete individual dup. The problem is that escrow is not fixed buts stuffs gets added and deleted which just adds to the value of the proem. 2**16 is an impossibly large number so the proem will not max out practically. But its not an elegant solution.
§Parameters
db: Opened named sub db with dupsort=Falsekey: bytes of key within sub db’s keyspaceval: bytes of value to be deleted without insertion ordering proem
§Returns
Ok(bool): True if deleted, false if val not presentErr(DBError): If a database error occurs
Sourcepub fn get_io_dup_val_last(
&self,
db: &BytesDatabase,
key: &[u8],
) -> Result<Option<Vec<u8>>, DBError>
pub fn get_io_dup_val_last( &self, db: &BytesDatabase, key: &[u8], ) -> Result<Option<Vec<u8>>, DBError>
Return last added dup value at key in db in insertion order Returns None if no entry at key Removes prepended proem ordinal from val before returning Assumes DB opened with dupsort=True
Duplicates at a given key preserve insertion order of duplicate. Because lmdb is lexocographic an insertion ordering proem is prepended to all values that makes lexocographic order that same as insertion order.
Duplicates are ordered as a pair of key plus value so prepending proem to each value changes duplicate ordering. Proem is 33 characters long. With 32 character hex string followed by ‘.’ for essentially unlimited number of values which will be limited by memory.
§Parameters
db: Opened named sub db with dupsort=Truekey: bytes of key within sub db’s keyspace
§Returns
Ok(Option<Vec<u8>>): Last value with proem removed, or None if no entry existsErr(DBError): If a database error occurs
Sourcepub fn get_top_io_dup_item_iter<F>(
&self,
db: &BytesDatabase,
top: &[u8],
cb: F,
) -> Result<usize, DBError>
pub fn get_top_io_dup_item_iter<F>( &self, db: &BytesDatabase, top: &[u8], cb: F, ) -> Result<usize, DBError>
Iterates over top branch of db given by key of IoDup items where each value has 33 byte insertion ordinal number proem (prefixed) with separator. Automagically removes (strips) proem before returning items.
Assumes DB opened with dupsort=True
Because cursor.iternext() advances cursor after returning item its safe to delete the item within the iteration loop. Works for both dupsort==False and dupsort==True
§Parameters
db: Opened named sub db with dupsort=Truetop: truncated top key, a key space prefix to get all the items from multiple branches of the key space. If top key is empty then gets all items in databasecb: Callback function that processes key-value pairs with proem stripped from value
§Returns
Ok(count): Number of items processedErr(DBError): If a database error occurs
Duplicates at a given key preserve insertion order of duplicate. Because lmdb is lexocographic an insertion ordering proem is prepended to all values that makes lexocographic order that same as insertion order.
Duplicates are ordered as a pair of key plus value so prepending proem to each value changes duplicate ordering. Proem is 33 characters long. With 32 character hex string followed by ‘.’ for essentially unlimited number of values which will be limited by memory.
Sourcepub fn add_on_io_dup_val(
&self,
db: &BytesDatabase,
key: &[u8],
on: Option<u64>,
val: &[u8],
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn add_on_io_dup_val( &self, db: &BytesDatabase, key: &[u8], on: Option<u64>, val: &[u8], sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Add val bytes as dup at onkey consisting of key + sep + serialized on in db. Adds to existing values at key if any. Returns true if written else false if dup val already exists.
Duplicates are inserted in lexicographic order not insertion order. LMDB does not insert a duplicate unless it is a unique value for that key.
Does inclusion test to detect if duplicate already exists.
§Parameters
db: Opened named sub db with dupsort=Truekey: Key within sub db’s keyspaceon: Ordinal number for the key (default: 0)val: Value to add at onkey as dupsep: Separator character for split (default: b’.’)
§Returns
Ok(bool): True if duplicate val added at onkey, false if duplicate val preexistsErr(DBError): If a database error occurs
Sourcepub fn append_on_io_dup_val(
&self,
db: &BytesDatabase,
key: &[u8],
val: &[u8],
sep: Option<[u8; 1]>,
) -> Result<u64, DBError>
pub fn append_on_io_dup_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], sep: Option<[u8; 1]>, ) -> Result<u64, DBError>
Appends val in order after last previous key with same prefix in db where full key has key prefix and serialized on suffix attached with sep and value has ordinal proem prefixed.
Returns ordinal number (on) of appended entry. Appended on is 1 greater than previous latest on at the prefix.
Works with either dupsort==True or False since always creates new full key.
§Parameters
db: Named sub db in lmdbkey: Key within sub db’s keyspaceval: Value to appendsep: Separator character for split (default: b’.’)
§Returns
Ok(u64): Ordinal number of newly appended valErr(DBError): If a database error occurs
Sourcepub fn del_on_io_dup_vals(
&self,
db: &BytesDatabase,
key: &[u8],
on: Option<u64>,
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn del_on_io_dup_vals( &self, db: &BytesDatabase, key: &[u8], on: Option<u64>, sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Deletes all dup iovals at onkey consisting of key + sep + serialized on in db.
Assumes DB opened with dupsort=True
§Parameters
db: Opened named sub db with dupsort=Truekey: Key within sub db’s keyspaceon: Ordinal number for the key (default: 0)sep: Separator character for split (default: b’.’)
§Returns
Ok(bool): True if onkey present so all dups at onkey deleted False if onkey not presentErr(DBError): If a database error occurs
Sourcepub fn del_on_io_dup_val(
&self,
db: &BytesDatabase,
key: &[u8],
on: Option<u64>,
val: &[u8],
sep: Option<[u8; 1]>,
) -> Result<bool, DBError>
pub fn del_on_io_dup_val( &self, db: &BytesDatabase, key: &[u8], on: Option<u64>, val: &[u8], sep: Option<[u8; 1]>, ) -> Result<bool, DBError>
Deletes a specific dup ioval at key onkey consisting of key + sep + serialized on in db.
Returns True if deleted else False if dup val not present. Assumes DB opened with dupsort=True.
§Parameters
db: Opened named sub db with dupsort=Truekey: Key within sub db’s keyspaceon: Ordinal number for the key (default: 0)val: Value to delete at onkeysep: Separator character for split (default: b’.’)
§Returns
Ok(bool): True if duplicate val found and deleted False if duplicate val does not exist at onkeyErr(DBError): If a database error occurs
Sourcepub fn get_on_io_dup_item_iter<F>(
&self,
db: &BytesDatabase,
key: Option<&[u8]>,
on: Option<u64>,
sep: Option<[u8; 1]>,
callback: F,
) -> Result<(), DBError>
pub fn get_on_io_dup_item_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
Returns iterator of triples (key, on, val), at each key over all ordinal numbered keys with same key + sep + on in db.
Values are sorted by onKey(key, on) where on is ordinal number int and key is prefix without the ordinal suffix. Values duplicates are sorted internally by hidden prefixed insertion order proem ordinal.
Uses callback pattern instead of Python’s yield/iterator for each triple of (key, on, val). When key is empty then retrieves the whole db.
§Parameters
db: Named sub db in lmdbkey: Key within sub db’s keyspace - when key is empty (None) then retrieves whole dbon: Ordinal number at which to initiate retrieval (default: 0)sep: Separator character for split (default: b’.’)callback: Function to call for each (key, on, val) triple found
§Returns
Ok(()): If iteration completes successfullyErr(DBError): If a database error occurs
Sourcepub fn get_on_io_dup_val_iter<F>(
&self,
db: &BytesDatabase,
key: Option<&[u8]>,
on: Option<u64>,
sep: Option<[u8; 1]>,
callback: F,
) -> Result<(), DBError>
pub fn get_on_io_dup_val_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
Returns iterator over values at each key with same key + sep + on in db.
Values are associated with keys formed by onKey(key, on) where on is an ordinal number int and key is prefix without the ordinal. Values duplicates are sorted internally by hidden prefixed insertion order proem ordinal.
Uses callback pattern instead of Python’s yield/iterator.
§Parameters
db: Named sub db in lmdbkey: Key within sub db’s keyspace - when key is empty then retrieves whole dbon: Ordinal number at which to initiate retrieval (default: 0)sep: Separator character for split (default: b’.’)callback: Function to call for each value found
§Returns
Ok(()): If iteration completes successfullyErr(DBError): If a database error occurs
Sourcepub fn get_on_io_dup_last_item_iter<F>(
&self,
db: &BytesDatabase,
key: Option<&[u8]>,
on: Option<u64>,
sep: Option<[u8; 1]>,
callback: F,
) -> Result<(), DBError>
pub fn get_on_io_dup_last_item_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
Returns iterator-like access to triples (key, on, val) of last insertion ordered duplicate at each key over all ordinal numbered keys with same full key of key + sep + on in db. Values are sorted by on_key(key, on) where on is ordinal number int and key is prefix sans on. Values duplicates are sorted internally by hidden prefixed insertion order proem ordinal Callback receives triples of (key, on, val)
When key is empty then retrieves whole db
§Parameters
db- named sub db in lmdbkey- key within sub db’s keyspace plus trailing part on (when empty, retrieves whole db)on- ordinal number at which to initiate retrievalsep- separator character for splitcallback- function that processes each (key, on, val) triple, returns bool to continue or stop
Sourcepub fn get_on_io_dup_item_back_iter<F>(
&self,
db: &BytesDatabase,
key: Option<&[u8]>,
on: Option<u64>,
sep: Option<[u8; 1]>,
callback: F,
) -> Result<(), DBError>
pub fn get_on_io_dup_item_back_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
Returns iterator going backwards of triples (key, on, val), of insertion ordered item at each key over all ordinal numbered keys with same full key of key + sep + on in db.
Values are sorted by onKey(key, on) where on is ordinal number int and key is prefix sans on. Values duplicates are sorted internally by hidden prefixed insertion order proem ordinal.
Backwards means decreasing numerical value of duplicate proem, for each on, decreasing numerical value on for each key and decreasing lexicographic order of each key prefix.
Uses callback pattern instead of Python’s yield/iterator for each triple of (key, on, val). When key is empty then retrieves the whole db.
§Parameters
db: Named sub db in lmdbkey: Key within sub db’s keyspace - when key is empty (None) then retrieves whole dbon: Ordinal number at which to initiate retrievalsep: Separator character for split (default: b’.’)callback: Function to call for each (key, on, val) triple found
§Returns
Ok(()): If iteration completes successfullyErr(DBError): If a database error occurs
Sourcepub fn get_on_io_dup_last_val_iter<F>(
&self,
db: &BytesDatabase,
key: Option<&[u8]>,
on: Option<u64>,
sep: Option<[u8; 1]>,
callback: F,
) -> Result<(), DBError>
pub fn get_on_io_dup_last_val_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
Returns iterator of val of last insertion ordered duplicate at each key over all ordinal numbered keys with same full key of key + sep + on in db. Values are sorted by onKey(key, on) where on is ordinal number int and key is prefix sans on. Values duplicates are sorted internally by hidden prefixed insertion order proem ordinal
when key is empty then retrieves whole db
§Arguments
db- named sub db in lmdbkey- key within sub db’s keyspace plus trailing part on when key is empty then retrieves whole dbon- ordinal number at which to initiate retrievalsep- separator character for split
§Returns
Callback invoked for each last dup val at each onkey
Sourcepub fn get_on_io_dup_val_back_iter<F>(
&self,
db: &BytesDatabase,
key: Option<&[u8]>,
on: Option<u64>,
sep: Option<[u8; 1]>,
callback: F,
) -> Result<(), DBError>
pub fn get_on_io_dup_val_back_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
Returns iterator going backwards of values, of insertion ordered item at each key over all ordinal numbered keys with same full key of key + sep + on in db. Values are sorted by onKey(key, on) where on is ordinal number int and key is prefix sans on. Values duplicates are sorted internally by hidden prefixed insertion order proem ordinal Backwards means decreasing numerical value of duplicate proem, for each on, decreasing numerical value on for each key and decreasing lexicographic order of each key prefix.
when key is empty then retrieves whole db
§Arguments
db- named sub db in lmdbkey- key within sub db’s keyspace plus trailing part on when key is empty then retrieves whole dbon- ordinal number at which to initiate retrievalsep- separator character for split
§Returns
Callback invoked for each val in backwards order