Struct lmdb_zero::WriteAccessor
[−]
[src]
pub struct WriteAccessor<'txn>(_);
A read-write data accessor obtained from a WriteTransaction.
All operations that can be performed on ConstAccessor can also be
performed on WriteAccessor.
Methods
impl<'txn> WriteAccessor<'txn>[src]
fn put<K: AsLmdbBytes + ?Sized, V: AsLmdbBytes + ?Sized>(&mut self, db: &Database, key: &K, value: &V, flags: Flags) -> Result<()>
Store items into a database.
This function stores key/data pairs in the database. The default
behavior is to enter the new key/data pair, replacing any previously
existing key if duplicates are disallowed, or adding a duplicate data
item if duplicates are allowed (DUPSORT).
fn put_reserve<K: AsLmdbBytes + ?Sized, V: FromReservedLmdbBytes + Sized>(&mut self, db: &Database, key: &K, flags: Flags) -> Result<&mut V>
Store items into a database.
This function stores key/data pairs in the database. The default
behavior is to enter the new key/data pair, replacing any previously
existing key if duplicates are disallowed, or adding a duplicate data
item if duplicates are allowed (DUPSORT).
Unlike put(), this does not take a value. Instead, it reserves space
for the value (equal to the size of V) and then returns a mutable
reference to it. Be aware that the FromReservedLmdbBytes conversion
will be invoked on whatever memory happens to be at the destination
location.
Example
#[repr(C, packed)] #[derive(Clone,Copy,Debug,PartialEq,Eq)] struct MyStruct { x: i32, y: i32, } unsafe impl lmdb::traits::LmdbRaw for MyStruct { } let txn = lmdb::WriteTransaction::new(&env).unwrap(); { let mut access = txn.access(); { let dst: &mut MyStruct = access.put_reserve( &db, "foo", lmdb::put::Flags::empty()).unwrap(); // Writing to `dst` actually writes directly into the database. dst.x = 42; dst.y = 56; // Drop `dst` so we can use `access` again } assert_eq!(&MyStruct { x: 42, y: 56 }, access.get(&db, "foo").unwrap()); } txn.commit().unwrap();
fn put_reserve_array<K: AsLmdbBytes + ?Sized, V: LmdbRaw>(&mut self, db: &Database, key: &K, count: usize, flags: Flags) -> Result<&mut [V]>
Store items into a database.
This function stores key/data pairs in the database. The default
behavior is to enter the new key/data pair, replacing any previously
existing key if duplicates are disallowed, or adding a duplicate data
item if duplicates are allowed (DUPSORT).
Unlike put(), this does not take a value. Instead, it reserves space
for the value (equal to an array of count objects of size V) and
then returns a mutable reference to it. Be aware that the content of
the returned slice is simply whatever happens to be in the destination
memory at the time of this call.
Example
let txn = lmdb::WriteTransaction::new(&env).unwrap(); { let mut access = txn.access(); { let bytes: &mut [u8] = access.put_reserve_array( &db, "foo", 4, lmdb::put::Flags::empty()).unwrap(); // More realistically, one could zero-copy data from a file/socket // into `bytes`, for example. bytes[0] = b'b'; bytes[1] = b'y'; bytes[2] = b't'; bytes[3] = b'e'; } assert_eq!("byte", access.get::<str,str>(&db, "foo").unwrap()); } txn.commit().unwrap();
unsafe fn put_reserve_unsized<K: AsLmdbBytes + ?Sized, V: FromReservedLmdbBytes + ?Sized>(&mut self, db: &Database, key: &K, size: usize, flags: Flags) -> Result<&mut V>
Store items into a database.
This function stores key/data pairs in the database. The default
behavior is to enter the new key/data pair, replacing any previously
existing key if duplicates are disallowed, or adding a duplicate data
item if duplicates are allowed (DUPSORT).
Unlike put(), this does not take a value. Instead, it reserves space
equal to size bytes for the value and then returns a mutable
reference to it. Be aware that the FromReservedLmdbBytes conversion
will be invoked on whatever memory happens to be at the destination
location.
Unsafety
The caller must ensure that size is a valid size for V.
fn del_key<K: AsLmdbBytes + ?Sized>(&mut self, db: &Database, key: &K) -> Result<()>
Delete items from a database by key.
This function removes key/data pairs from the database. All values
whose key matches key are deleted, including in the case of
DUPSORT. This function will return NOTFOUND if the specified
key is not in the database.
Example
let db = lmdb::Database::open( &env, Some("example"), &lmdb::DatabaseOptions::create_multimap_unsized::<str,str>()) .unwrap(); let txn = lmdb::WriteTransaction::new(&env).unwrap(); { let mut access = txn.access(); access.put(&db, "Fruit", "Apple", lmdb::put::Flags::empty()).unwrap(); access.put(&db, "Fruit", "Orange", lmdb::put::Flags::empty()).unwrap(); assert_eq!("Apple", access.get::<str,str>(&db, "Fruit").unwrap()); access.del_key(&db, "Fruit").unwrap(); assert!(access.get::<str,str>(&db, "Fruit").is_err()); } txn.commit().unwrap();
fn del_item<K: AsLmdbBytes + ?Sized, V: AsLmdbBytes + ?Sized>(&mut self, db: &Database, key: &K, val: &V) -> Result<()>
Delete items from a database by key and value.
This function removes key/data pairs from the database. If the database
does not support sorted duplicate data items (DUPSORT) the val
parameter is ignored and this call behaves like del(). Otherwise, if
the data item matching both key and val will be deleted. This
function will return NOTFOUND if the specified key/data pair is not
in the database.
Example
let db = lmdb::Database::open( &env, Some("example"), &lmdb::DatabaseOptions::create_multimap_unsized::<str,str>()) .unwrap(); let txn = lmdb::WriteTransaction::new(&env).unwrap(); { let mut access = txn.access(); access.put(&db, "Fruit", "Apple", lmdb::put::Flags::empty()).unwrap(); access.put(&db, "Fruit", "Orange", lmdb::put::Flags::empty()).unwrap(); assert_eq!("Apple", access.get::<str,str>(&db, "Fruit").unwrap()); access.del_item(&db, "Fruit", "Apple").unwrap(); assert_eq!("Orange", access.get::<str,str>(&db, "Fruit").unwrap()); } txn.commit().unwrap();
fn clear_db(&mut self, db: &Database) -> Result<()>
Completely clears the content of the given database.
Example
let txn = lmdb::WriteTransaction::new(&env).unwrap(); { let mut access = txn.access(); let f = lmdb::put::Flags::empty(); access.put(&db, "Germany", "Berlin", f).unwrap(); access.put(&db, "France", "Paris", f).unwrap(); access.put(&db, "Latvia", "Rīga", f).unwrap(); assert_eq!(3, txn.db_stat(&db).unwrap().entries); access.clear_db(&db).unwrap(); assert_eq!(0, txn.db_stat(&db).unwrap().entries); } txn.commit().unwrap();
Methods from Deref<Target=ConstAccessor<'txn>>
fn get<K: AsLmdbBytes + ?Sized, V: FromLmdbBytes + ?Sized>(&self, db: &Database, key: &K) -> Result<&V>
Get items from a database.
This function retrieves key/data pairs from the database. A reference
to the data associated with the given key is returned. If the database
supports duplicate keys (DUPSORT) then the first data item for the
key will be returned. Retrieval of other items requires the use of
cursoring.
The returned memory is valid until the next mutation through the transaction or the end of the transaction (both are enforced through the borrow checker).
Trait Implementations
impl<'txn> Debug for WriteAccessor<'txn>[src]
impl<'txn> Deref for WriteAccessor<'txn>[src]
type Target = ConstAccessor<'txn>
The resulting type after dereferencing
fn deref(&self) -> &ConstAccessor<'txn>
The method called to dereference a value