Struct lmdb_zero::DatabaseOptions [] [src]

pub struct DatabaseOptions {
    pub flags: Flags,
    // some fields omitted
}

Describes the options used for creating or opening a database.

Fields

flags: Flags

The integer flags to pass to LMDB

Methods

impl DatabaseOptions
[src]

fn new(flags: Flags) -> DatabaseOptions

Creates a new DatabaseOptions with the given flags, using natural key and value ordering.

fn defaults() -> DatabaseOptions

Synonym for DatabaseOptions::new(db::Flags::empty()).

Note that this does not even have db::CREATE set. This is most useful when opening the anonymous default database.

fn sort_keys_as<K: LmdbOrdKey + ?Sized>(&mut self)

Sorts keys in the database by interpreting them as K and using their comparison order. Keys which fail to convert are considered equal.

The comparison function is called whenever it is necessary to compare a key specified by the application with a key currently stored in the database. If no comparison function is specified, and no special key flags were specified in the options, the keys are compared lexically, with shorter keys collating before longer keys.

Warning

This function must be called before any data access functions are used, otherwise data corruption may occur. The same comparison function must be used by every program accessing the database, every time the database is used.

Example

#[repr(C, packed)]
#[derive(Clone,Copy,Debug,PartialEq,Eq,PartialOrd,Ord)]
struct MyStruct {
  x: i32,
  y: i32,
}
unsafe impl lmdb::traits::LmdbRaw for MyStruct { }
unsafe impl lmdb::traits::LmdbOrdKey for MyStruct { }

fn my(x: i32, y: i32) -> MyStruct {
  MyStruct { x: x, y: y }
}

let mut opts = lmdb::DatabaseOptions::new(lmdb::db::CREATE);
opts.sort_keys_as::<MyStruct>();
let db = lmdb::Database::open(&env, Some("example"), &opts).unwrap();
let txn = lmdb::WriteTransaction::new(&env).unwrap();
{
  let mut access = txn.access();
  let f = lmdb::put::Flags::empty();
  access.put(&db, &my(0, 0), "origin", f).unwrap();
  access.put(&db, &my(-1, 0), "x=-1", f).unwrap();
  access.put(&db, &my(1, 0), "x=+1", f).unwrap();
  access.put(&db, &my(0, -1), "y=-1", f).unwrap();

  let mut cursor = txn.cursor(&db).unwrap();
  // The keys are sorted by the Rust-derived comparison. The default
  // byte-string comparison would have resulted in (0,0), (0,-1),
  // (1,0), (-1,0).
  assert_eq!((&my(-1, 0), "x=-1"), cursor.first(&access).unwrap());
  assert_eq!((&my(0, -1), "y=-1"), cursor.next(&access).unwrap());
  assert_eq!((&my(0, 0), "origin"), cursor.next(&access).unwrap());
  assert_eq!((&my(1, 0), "x=+1"), cursor.next(&access).unwrap());
}
txn.commit().unwrap();

fn sort_values_as<V: LmdbOrdKey + ?Sized>(&mut self)

Sorts duplicate values in the database by interpreting them as V and using their comparison order. Values which fail to convert are considered equal.

This comparison function is called whenever it is necessary to compare a data item specified by the application with a data item currently stored in the database. This function only takes effect if the database iss opened with the DUPSORT flag. If no comparison function is specified, and no special key flags were specified in the flags of these options, the data items are compared lexically, with shorter items collating before longer items.

Warning

This function must be called before any data access functions are used, otherwise data corruption may occur. The same comparison function must be used by every program accessing the database, every time the database is used.

fn create_map<K: LmdbOrdKey + ?Sized>() -> Self

Concisely creates a DatabaseOptions to configure a database to have a 1:1 mapping using the given key type.

The flags always have db::CREATE set. If K is understood by LMDB as an integer, db::INTEGERKEY is set. Otherwise, unless K sorts properly via byte-string comparison, sort_keys_as is called to configure the database to use K's Ord implementation.

fn create_multimap_unsized<K: LmdbOrdKey + ?Sized, V: LmdbOrdKey + ?Sized>() -> Self

Concisely creates a DatabaseOptions to configure a database to have a 1:M mapping using the given key and unsized value types.

The flags are configured as described with create_map with db::DUPSORT added. If V is understood by LMDB as an integer, INTEGERDUP is set. Otherwise, if V is not byte-string comparable, sort_values_as is used to order values by V's Ord implementation.

fn create_multimap<K: LmdbOrdKey + ?Sized, V: LmdbOrdKey + Sized>() -> Self

Concisely creates a DatabaseOptions to configure a database to have a 1:M mapping using the given key and fixed-size value types.

This is the same as create_multimap_unsized, except that DUPFIXED is additionally set unconditionally.

Trait Implementations

impl Debug for DatabaseOptions
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Clone for DatabaseOptions
[src]

fn clone(&self) -> DatabaseOptions

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more