Struct rocksdb::WriteBatchWithTransaction

pub struct WriteBatchWithTransaction<const TRANSACTION: bool> { /* private fields */ }
Expand description

An atomic batch of write operations.

delete_range is not supported in Transaction.

Making an atomic commit of several writes:

use rocksdb::{DB, Options, WriteBatchWithTransaction};

let path = "_path_for_rocksdb_storage1";
{
    let db = DB::open_default(path).unwrap();
    let mut batch = WriteBatchWithTransaction::<false>::default();
    batch.put(b"my key", b"my value");
    batch.put(b"key2", b"value2");
    batch.put(b"key3", b"value3");

    // delete_range is supported when use without transaction
    batch.delete_range(b"key2", b"key3");

    db.write(batch); // Atomically commits the batch
}
let _ = DB::destroy(&Options::default(), path);

Implementations§

§

impl<const TRANSACTION: bool> WriteBatchWithTransaction<TRANSACTION>

pub fn from_data(data: &[u8]) -> WriteBatchWithTransaction<TRANSACTION>

Construct with a reference to a byte array serialized by WriteBatch.

pub fn len(&self) -> usize

pub fn size_in_bytes(&self) -> usize

Return WriteBatch serialized size (in bytes).

pub fn data(&self) -> &[u8]

Return a reference to a byte array which represents a serialized version of the batch.

pub fn is_empty(&self) -> bool

pub fn iterate(&self, callbacks: &mut dyn WriteBatchIterator)

Iterate the put and delete operations within this write batch. Note that this does not return an Iterator but instead will invoke the put() and delete() member functions of the provided WriteBatchIterator trait implementation.

pub fn put<K, V>(&mut self, key: K, value: V)
where K: AsRef<[u8]>, V: AsRef<[u8]>,

Insert a value into the database under the given key.

pub fn put_cf<K, V>(&mut self, cf: &impl AsColumnFamilyRef, key: K, value: V)
where K: AsRef<[u8]>, V: AsRef<[u8]>,

pub fn merge<K, V>(&mut self, key: K, value: V)
where K: AsRef<[u8]>, V: AsRef<[u8]>,

pub fn merge_cf<K, V>(&mut self, cf: &impl AsColumnFamilyRef, key: K, value: V)
where K: AsRef<[u8]>, V: AsRef<[u8]>,

pub fn delete<K>(&mut self, key: K)
where K: AsRef<[u8]>,

Removes the database entry for key. Does nothing if the key was not found.

pub fn delete_cf<K>(&mut self, cf: &impl AsColumnFamilyRef, key: K)
where K: AsRef<[u8]>,

pub fn clear(&mut self)

Clear all updates buffered in this batch.

§

impl WriteBatchWithTransaction<false>

pub fn delete_range<K>(&mut self, from: K, to: K)
where K: AsRef<[u8]>,

Remove database entries from start key to end key.

Removes the database entries in the range [“begin_key”, “end_key”), i.e., including “begin_key” and excluding “end_key”. It is not an error if no keys exist in the range [“begin_key”, “end_key”).

pub fn delete_range_cf<K>( &mut self, cf: &impl AsColumnFamilyRef, from: K, to: K, )
where K: AsRef<[u8]>,

Remove database entries in column family from start key to end key.

Removes the database entries in the range [“begin_key”, “end_key”), i.e., including “begin_key” and excluding “end_key”. It is not an error if no keys exist in the range [“begin_key”, “end_key”).

Trait Implementations§

§

impl<const TRANSACTION: bool> Default for WriteBatchWithTransaction<TRANSACTION>

§

fn default() -> WriteBatchWithTransaction<TRANSACTION>

Returns the “default value” for a type. Read more
§

impl<const TRANSACTION: bool> Drop for WriteBatchWithTransaction<TRANSACTION>

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl<const TRANSACTION: bool> Send for WriteBatchWithTransaction<TRANSACTION>

Auto Trait Implementations§

§

impl<const TRANSACTION: bool> Freeze for WriteBatchWithTransaction<TRANSACTION>

§

impl<const TRANSACTION: bool> RefUnwindSafe for WriteBatchWithTransaction<TRANSACTION>

§

impl<const TRANSACTION: bool> !Sync for WriteBatchWithTransaction<TRANSACTION>

§

impl<const TRANSACTION: bool> Unpin for WriteBatchWithTransaction<TRANSACTION>

§

impl<const TRANSACTION: bool> UnwindSafe for WriteBatchWithTransaction<TRANSACTION>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.