Skip to main content

LMDBer

Struct LMDBer 

Source
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: BaseFiler

Base Filer instance

§env: Option<Arc<Env>>

LMDB environment

§readonly: bool

Whether the database is opened in readonly mode

Implementations§

Source§

impl LMDBer

Source§

impl LMDBer

Source

pub fn name(&self) -> String

Source

pub fn base(&self) -> String

Source

pub fn opened(&self) -> bool

Source

pub fn temp(&self) -> bool

Source

pub fn env(&self) -> Option<&Arc<Env>>

Source

pub fn path(&self) -> Option<PathBuf>

Source§

impl LMDBer

Source

pub const MAX_NAMED_DBS: u32 = 96

Source

pub const MAP_SIZE: usize = 104857600

Source

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>
where S1: Into<String>, S2: Into<String>,

Create a new LMDBer instance

Source

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

Source

pub fn version(&self) -> Option<&str>

Get the version of the database

Source

pub fn set_version(&mut self, version: String)

Set the version of the database

Source

pub fn close(&mut self, clear: bool) -> Result<bool, DBError>

Source

pub fn create_database( &self, name: Option<&str>, dup_sort: Option<bool>, ) -> Result<BytesDatabase, DBError>

Source

pub fn open_database( &self, name: Option<&str>, ) -> Result<Option<BytesDatabase>, DBError>

Source

pub fn len(&self, db: &BytesDatabase) -> Result<u64, DBError>

Source

pub fn put_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], ) -> Result<bool, DBError>

Source

pub fn set_val( &self, db: &BytesDatabase, key: &[u8], val: &[u8], ) -> Result<bool, DBError>

Source

pub fn get_val( &self, db: &BytesDatabase, key: &[u8], ) -> Result<Option<Vec<u8>>, DBError>

Source

pub fn get_val_last( &self, db: &BytesDatabase, key: &[u8], ) -> Result<Option<Vec<u8>>, DBError>

Returns the last of the duplicated values associated with a key for databases with dupsort=true,

§Parameters
  • db: The database to search
  • key: The key to look up
§Returns
  • Ok(Some(Vec<u8>)): The last value if found
  • Ok(None): If no value exists at the key
  • Err(DBError): If a database error occurs
Source

pub fn del_val(&self, db: &BytesDatabase, key: &[u8]) -> Result<bool, DBError>

Source

pub fn cnt(&self, db: &BytesDatabase) -> Result<usize, DBError>

Source

pub fn get_top_items_iter<F>( &self, db: &BytesDatabase, prefix: &[u8], cb: F, ) -> Result<usize, DBError>
where F: FnMut(&[u8], &[u8]) -> Result<bool, DBError>,

Get items with a given prefix and process them with a callback function

§Parameters
  • db: The database to search in
  • prefix: The prefix to match keys against
  • cb: Callback function that takes key-value pairs
§Returns
  • Ok(count): Number of items processed
  • Err(DBError): If a database error occurs
Source

pub fn del_top_val( &self, db: &BytesDatabase, prefix: &[u8], ) -> Result<bool, DBError>

Source

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 LMDB
  • key: Key within sub db’s keyspace
  • on: Ordinal number at which to write
  • val: Bytes to be written at onkey
  • sep: Separator byte for constructing the composite key
§Returns
  • Ok(true): If successful write (i.e., onkey not already in db)
  • Ok(false): Otherwise
  • Err(DBError): If a database error occurs
Source

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 LMDB
  • key: Key within sub db’s keyspace
  • val: Bytes to be written at onkey
  • sep: Separator byte for constructing the composite key
§Returns
  • Ok(on): Ordinal number of newly appended val
  • Err(DBError): If a database error occurs
Source

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
Source

pub fn get_on_val( &self, db: &BytesDatabase, key: &[u8], on: u32, sep: Option<[u8; 1]>, ) -> Result<Option<Vec<u8>>, DBError>

Gets value at onkey consisting of key + sep + serialized on in db.

§Returns
  • Result<Option<Vec>, DBError>: entry at onkey or None if no entry at key
§Parameters
  • db: named sub db of lmdb
  • key: key within sub db’s keyspace
  • on: ordinal number at which to retrieve
  • sep: separator bytes for split
Source

pub fn del_on_val( &self, db: &BytesDatabase, key: &[u8], on: u32, sep: Option<[u8; 1]>, ) -> Result<bool, DBError>

Deletes value at onkey consisting of key + sep + serialized on in db.

§Returns
  • Result<bool, DBError>: True if key exists in database Else False
§Parameters
  • db: named sub db of lmdb
  • key: key within sub db’s keyspace
  • on: ordinal number at which to delete
  • sep: separator bytes for split
Source

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
Source

pub fn get_on_item_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
where F: FnMut(Vec<u8>, u64, Vec<u8>) -> Result<bool, DBError>,

  • txn: the read transaction to use
Source

pub fn get_on_val_iter<F>( &self, db: &BytesDatabase, key: Option<&[u8]>, on: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
where F: FnMut(Vec<u8>) -> Result<bool, DBError>,

  • txn: the read transaction to use
Source

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==False
  • key: Apparent effective key
  • vals: Serialized values to add to set of vals at key
  • sep: Optional separator byte (defaults to ‘.’)
§Returns
  • Ok(bool): True if added to set, false if already in set
  • Err(DBError): If a database error occurs
Source

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==False
  • key: Apparent effective key
  • ion: starting ordinal value, default 0
  • sep: Optional separator byte (defaults to ‘.’)
§Returns
  • Ok(Vec<Vec<u8>>): The ordered list of values at this key
  • Err(DBError): If a database error occurs
Source

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==False
  • key: Apparent effective key
  • val: Serialized value to add
  • sep: Optional separator byte (defaults to ‘.’)
§Returns
  • Ok(bool): True if added to set, false if already in set
  • Err(DBError): If a database error occurs
Source

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==False
  • key: Apparent effective key
  • sep: Optional separator byte (defaults to ‘.’)
§Returns
  • Ok(bool): True if values were deleted at key, False if no values at key
  • Err(DBError): If a database error occurs
Source

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==False
  • key: Apparent effective key
  • val: value to delete
  • sep: Optional separator byte (defaults to ‘.’)
§Returns
  • Ok(bool): True if val was deleted at key, False if val not found at key
  • Err(DBError): If a database error occurs
Source

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==False
  • key: Apparent effective key
  • vals: Serialized values to add to set of vals at key
  • sep: Optional separator byte (defaults to ‘.’)
§Returns
  • Ok(bool): True if values were added to set
  • Err(DBError): If a database error occurs
Source

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==False
  • key: Apparent effective key
  • sep: Optional separator byte (defaults to ‘.’)
§Returns
  • Ok(usize): Count of values in set at apparent effective key
  • Err(DBError): If a database error occurs
Source

pub fn get_io_set_vals_iter<F>( &self, db: &BytesDatabase, key: &[u8], ion: Option<u64>, sep: Option<[u8; 1]>, callback: F, ) -> Result<(), DBError>
where F: FnMut(&[u8]) -> Result<bool, 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==False
  • key: Apparent effective key
  • ion: Optional starting ordinal value, default 0
  • sep: Optional separator byte (defaults to ‘.’)
  • callback: Function to call for each value found
§Returns
  • Ok(()): If iteration completed successfully
  • Err(DBError): If a database error occurs
Source

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==False
  • key: Apparent effective key
  • sep: Optional separator byte (defaults to ‘.’)
§Returns
  • Ok(Option<Vec<u8>>): The last value if found, None otherwise
  • Err(DBError): If a database error occurs
Source

pub fn get_top_io_set_items_iter<F>( &self, db: &BytesDatabase, top: &[u8], sep: Option<[u8; 1]>, cb: F, ) -> Result<usize, DBError>
where F: FnMut(&[u8], &[u8]) -> Result<bool, 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 in
  • top: The prefix to match keys against (empty for all items)
  • cb: Callback function that takes apparent key (with suffix removed) and value pairs
  • sep: Optional separator byte (defaults to ‘.’)
§Returns
  • Ok(count): Number of items processed
  • Err(DBError): If a database error occurs
Source

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=True
  • key - bytes of key within sub db’s keyspace
  • val - bytes of value to be written
Source

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=True
  • key - bytes of key within sub db’s keyspace
  • vals - list of values to be written
Source

pub fn get_vals_iter<F>( &self, db: &BytesDatabase, key: &[u8], callback: F, ) -> Result<(), DBError>
where F: FnMut(&[u8]) -> Result<bool, 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=True
  • key - bytes of key within sub db’s keyspace
  • callback - function that processes each value
Source

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=True
  • key - bytes of key within sub db’s keyspace
Source

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=True
  • key - bytes of key within sub db’s keyspace
  • val - bytes of duplicate value at key to delete (empty means delete all duplicates)
Source

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=True
  • key: bytes of key within sub db’s keyspace
§Returns
  • Ok(Vec<Vec<u8>>): List of values with proem removed
  • Err(DBError): If a database error occurs
Source

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=True
  • key: bytes of key within sub db’s keyspace
  • vals: list of bytes of values to be written
§Returns
  • Ok(bool): True if at least one value was added, false otherwise
  • Err(DBError): If a database error occurs
Source

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=True
  • key: bytes of key within sub db’s keyspace
  • val: bytes of value to be written
§Returns
  • Ok(bool): True if written, false if val is already a dup
  • Err(DBError): If a database error occurs
Source

pub fn get_io_dup_vals_iter<F>( &self, db: &BytesDatabase, key: &[u8], callback: F, ) -> Result<(), DBError>
where F: FnMut(&[u8]) -> Result<bool, DBError>,

Source

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=True
  • key: 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
Source

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=True
  • key: bytes of key within sub db’s keyspace
§Returns
  • Ok(bool): True if key existed and was deleted, false otherwise
  • Err(DBError): If a database error occurs
Source

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=False
  • key: bytes of key within sub db’s keyspace
  • val: bytes of value to be deleted without insertion ordering proem
§Returns
  • Ok(bool): True if deleted, false if val not present
  • Err(DBError): If a database error occurs
Source

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=True
  • key: bytes of key within sub db’s keyspace
§Returns
  • Ok(Option<Vec<u8>>): Last value with proem removed, or None if no entry exists
  • Err(DBError): If a database error occurs
Source

pub fn get_top_io_dup_item_iter<F>( &self, db: &BytesDatabase, top: &[u8], cb: F, ) -> Result<usize, DBError>
where F: FnMut(&[u8], &[u8]) -> Result<bool, 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=True
  • top: 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 database
  • cb: Callback function that processes key-value pairs with proem stripped from value
§Returns
  • Ok(count): Number of items processed
  • Err(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.

Source

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=True
  • key: Key within sub db’s keyspace
  • on: Ordinal number for the key (default: 0)
  • val: Value to add at onkey as dup
  • sep: Separator character for split (default: b’.’)
§Returns
  • Ok(bool): True if duplicate val added at onkey, false if duplicate val preexists
  • Err(DBError): If a database error occurs
Source

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 lmdb
  • key: Key within sub db’s keyspace
  • val: Value to append
  • sep: Separator character for split (default: b’.’)
§Returns
  • Ok(u64): Ordinal number of newly appended val
  • Err(DBError): If a database error occurs
Source

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=True
  • key: Key within sub db’s keyspace
  • on: 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 present
  • Err(DBError): If a database error occurs
Source

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=True
  • key: Key within sub db’s keyspace
  • on: Ordinal number for the key (default: 0)
  • val: Value to delete at onkey
  • sep: Separator character for split (default: b’.’)
§Returns
  • Ok(bool): True if duplicate val found and deleted False if duplicate val does not exist at onkey
  • Err(DBError): If a database error occurs
Source

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>
where F: FnMut(Vec<u8>, u64, Vec<u8>) -> Result<bool, 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 lmdb
  • key: Key within sub db’s keyspace - when key is empty (None) then retrieves whole db
  • on: 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 successfully
  • Err(DBError): If a database error occurs
Source

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>
where F: FnMut(Vec<u8>) -> Result<bool, 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 lmdb
  • key: Key within sub db’s keyspace - when key is empty then retrieves whole db
  • on: 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 successfully
  • Err(DBError): If a database error occurs
Source

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>
where F: FnMut(Vec<u8>, u64, Vec<u8>) -> Result<bool, 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 lmdb
  • key - key within sub db’s keyspace plus trailing part on (when empty, retrieves whole db)
  • on - ordinal number at which to initiate retrieval
  • sep - separator character for split
  • callback - function that processes each (key, on, val) triple, returns bool to continue or stop
Source

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>
where F: FnMut(Vec<u8>, u64, Vec<u8>) -> Result<bool, 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 lmdb
  • key: Key within sub db’s keyspace - when key is empty (None) then retrieves whole db
  • on: Ordinal number at which to initiate retrieval
  • sep: Separator character for split (default: b’.’)
  • callback: Function to call for each (key, on, val) triple found
§Returns
  • Ok(()): If iteration completes successfully
  • Err(DBError): If a database error occurs
Source

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>
where F: FnMut(Vec<u8>) -> Result<bool, 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 lmdb
  • key - key within sub db’s keyspace plus trailing part on when key is empty then retrieves whole db
  • on - ordinal number at which to initiate retrieval
  • sep - separator character for split
§Returns

Callback invoked for each last dup val at each onkey

Source

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>
where F: FnMut(Vec<u8>) -> Result<bool, 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 lmdb
  • key - key within sub db’s keyspace plus trailing part on when key is empty then retrieves whole db
  • on - ordinal number at which to initiate retrieval
  • sep - separator character for split
§Returns

Callback invoked for each val in backwards order

Trait Implementations§

Source§

impl Drop for LMDBer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Filer for LMDBer

Source§

const TAIL_DIR_PATH: &'static str = "keri/db"

Default relative directory path tail when using head
Source§

const CLEAN_TAIL_DIR_PATH: &'static str = "keri/clean/db"

Default relative directory path tail when creating clean
Source§

const ALT_TAIL_DIR_PATH: &'static str = ".keri/db"

Default alternative relative directory path tail as fallback
Source§

const ALT_CLEAN_TAIL_DIR_PATH: &'static str = ".keri/clean/db"

Default alternative relative path tail when creating clean
Source§

const TEMP_PREFIX: &'static str = "keri_lmdb_"

Default relative directory path prefix when using temp head
Source§

fn defaults() -> FilerDefaults

Source§

const HEAD_DIR_PATH: &'static str = "/usr/local/var"

Default absolute directory path head such as “/usr/local/var”
Source§

const TEMP_HEAD_DIR: &'static str = "/tmp"

Default relative directory path prefix when using temp head
Source§

const PERM: u32 = 0o1700

Explicit default octal permissions such as 0o1700
Source§

const MODE: &'static str = "r+"

Open mode such as “r+”
Source§

const FEXT: &'static str = "text"

Default file extension such as “text” for “fname.text”

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more