Struct ckb_db::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
sourceimpl WriteBatch
impl WriteBatch
pub fn len(&self) -> usize
sourcepub fn size_in_bytes(&self) -> usize
pub fn size_in_bytes(&self) -> usize
Return WriteBatch serialized size (in bytes).
pub fn is_empty(&self) -> bool
sourcepub fn put<K, V>(&mut self, key: K, value: V) -> Result<(), Error> where
K: AsRef<[u8]>,
V: AsRef<[u8]>,
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.
pub fn put_cf<K, V>(
&mut self,
cf: &ColumnFamily,
key: K,
value: V
) -> Result<(), Error> where
K: AsRef<[u8]>,
V: AsRef<[u8]>,
pub fn merge<K, V>(&mut self, key: K, value: V) -> Result<(), Error> where
K: AsRef<[u8]>,
V: AsRef<[u8]>,
pub fn merge_cf<K, V>(
&mut self,
cf: &ColumnFamily,
key: K,
value: V
) -> Result<(), Error> where
K: AsRef<[u8]>,
V: AsRef<[u8]>,
sourcepub fn delete<K>(&mut self, key: K) -> Result<(), Error> where
K: AsRef<[u8]>,
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.
pub fn delete_cf<K>(&mut self, cf: &ColumnFamily, key: K) -> Result<(), Error> where
K: AsRef<[u8]>,
sourcepub fn delete_range<K>(&mut self, from: K, to: K) -> Result<(), Error> where
K: AsRef<[u8]>,
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”).
sourcepub fn delete_range_cf<K>(
&mut self,
cf: &ColumnFamily,
from: K,
to: K
) -> Result<(), Error> where
K: AsRef<[u8]>,
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”).
Trait Implementations
sourceimpl Default for WriteBatch
impl Default for WriteBatch
sourcefn default() -> WriteBatch
fn default() -> WriteBatch
Returns the “default value” for a type. Read more
sourceimpl Drop for WriteBatch
impl Drop for WriteBatch
Auto Trait Implementations
impl RefUnwindSafe for WriteBatch
impl !Send for WriteBatch
impl !Sync for WriteBatch
impl Unpin for WriteBatch
impl UnwindSafe for WriteBatch
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more