[−][src]Struct libdb::db::Db
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]
&self,
txn: Option<&Transaction>,
key: &mut [u8],
flags: Flags
) -> Result<Option<DBT>, Error>
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]
&self,
txn: Option<&Transaction>,
key: &mut [u8],
data: &mut [u8],
flags: Flags
) -> Result<(), Error>
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
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,