ckb_db

Struct WriteBatch

Source
pub struct WriteBatch { /* private fields */ }
Expand description

An atomic batch of write operations.

Making an atomic commit of several writes:

use ckb_rocksdb::{prelude::*, WriteBatch};

let path = "_path_for_rocksdb_storage1";

let db = DB::open_default(&path).unwrap();

let mut batch = WriteBatch::default();
batch.put(b"my key", b"my value");
batch.put(b"key2", b"value2");
batch.put(b"key3", b"value3");

db.write(&batch); // Atomically commits the batch

Implementations§

Source§

impl WriteBatch

Source

pub fn len(&self) -> usize

Source

pub fn size_in_bytes(&self) -> usize

Return WriteBatch serialized size (in bytes).

Source

pub fn is_empty(&self) -> bool

Source

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

Insert a value into the database under the given key.

Source

pub fn put_cf<K, V>( &mut self, cf: &ColumnFamily, key: K, value: V, ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

Source

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

Source

pub fn merge_cf<K, V>( &mut self, cf: &ColumnFamily, key: K, value: V, ) -> Result<(), Error>
where K: AsRef<[u8]>, V: AsRef<[u8]>,

Source

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

Remove the database entry for key.

Returns an error if the key was not found.

Source

pub fn delete_cf<K>(&mut self, cf: &ColumnFamily, key: K) -> Result<(), Error>
where K: AsRef<[u8]>,

Source

pub fn delete_range<K>(&mut self, from: K, to: K) -> Result<(), Error>
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”).

Source

pub fn delete_range_cf<K>( &mut self, cf: &ColumnFamily, from: K, to: K, ) -> Result<(), Error>
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”).

Source

pub fn clear(&mut self) -> Result<(), Error>

Clear all updates buffered in this batch.

Trait Implementations§

Source§

impl Default for WriteBatch

Source§

fn default() -> WriteBatch

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

impl Drop for WriteBatch

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Handle<rocksdb_writebatch_t> for WriteBatch

Auto Trait Implementations§

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Cast to trait Any
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T