pub struct DatabaseOptions {
    pub flags: Flags,
    /* private fields */
}
Expand description

Describes the options used for creating or opening a database.

Fields

flags: Flags

The integer flags to pass to LMDB

Implementations

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

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.

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();

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.

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.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Clone this value, and then immediately put it into a Box behind a trait object of this trait. Read more

Returns the address of self. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Clone this value, and then immediately put it into a Box behind a trait object of this trait. Read more

Returns the address of self. Read more

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. Read more

The resulting type after obtaining ownership.

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

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.