[][src]Struct libdb::db::Db

pub struct Db { /* fields omitted */ }

Database is the handle for a single Berkeley DB database.

Examples

use libdb::Flags;

let ret = libdb::DatabaseBuilder::new()
    .flags(Flags::DB_CREATE)
    .open();
assert!(ret.is_ok())

Methods

impl Db[src]

pub fn get(
    &self,
    txn: Option<&Transaction>,
    key: &mut [u8],
    flags: Flags
) -> Result<Option<DBT>, Error>
[src]

Get a key/data pair from the database.

Examples

Record Found

use libdb::Flags;
// Note: BDB requires that the key be mutable.
let mut key   = String::from("key").into_bytes();
let mut value = String::from("value").into_bytes();
assert!(db.put(None, key.as_mut_slice(), value.as_mut_slice(), Flags::DB_NONE).is_ok());

let ret = db.get(None, key.as_mut_slice(), Flags::DB_NONE);
assert!(ret.is_ok());
assert_eq!("value", str::from_utf8(ret.ok().unwrap().unwrap().as_slice()).unwrap());

Record Not Found

use libdb::Flags;
// Note: BDB requires that the key be mutable.
let mut key = String::from("key2").into_bytes();
let ret = db.get(None, key.as_mut_slice(), Flags::DB_NONE);
println!("{:?}", ret);
assert!(ret.is_ok());
assert!(ret.unwrap().is_none());

pub fn put(
    &self,
    txn: Option<&Transaction>,
    key: &mut [u8],
    data: &mut [u8],
    flags: Flags
) -> Result<(), Error>
[src]

Store a key/data pair in the database.

Examples

use libdb::Flags;

// Note: BDB requires that the key and value be mutable.
let mut key   = String::from("key").into_bytes();
let mut value = String::from("value").into_bytes();
let ret = db.put(None, key.as_mut_slice(), value.as_mut_slice(), Flags::DB_NONE);
assert!(ret.is_ok());

pub fn cursor(&self) -> Result<Cursor, Error>[src]

Get a cursor on the database.

Examples

use libdb::Flags;
// Note: BDB requires that the key and value be mutable.
let mut key   = String::from("key").into_bytes();
let mut value = String::from("value").into_bytes();
let ret = db.put(None, key.as_mut_slice(), value.as_mut_slice(), Flags::DB_NONE);
assert!(ret.is_ok());

// get cursor and iterate
let mut cursor = db.cursor().expect("Failed to get cursor");

Trait Implementations

impl Drop for Db[src]

impl Send for Db[src]

impl Sync for Db[src]

Auto Trait Implementations

impl RefUnwindSafe for Db

impl Unpin for Db

impl UnwindSafe for Db

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.