Struct rocksdb::WriteBatchWithTransaction
source · 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§
source§impl<const TRANSACTION: bool> WriteBatchWithTransaction<TRANSACTION>
impl<const TRANSACTION: bool> WriteBatchWithTransaction<TRANSACTION>
sourcepub fn from_data(data: &[u8]) -> Self
pub fn from_data(data: &[u8]) -> Self
Construct with a reference to a byte array serialized by 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).
sourcepub fn data(&self) -> &[u8] ⓘ
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
sourcepub fn iterate(&self, callbacks: &mut dyn WriteBatchIterator)
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.
sourcepub fn put<K, V>(&mut self, key: K, value: V)
pub fn put<K, V>(&mut self, key: K, value: V)
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)
pub fn merge<K, V>(&mut self, key: K, value: V)
pub fn merge_cf<K, V>(&mut self, cf: &impl AsColumnFamilyRef, key: K, value: V)
sourcepub fn delete<K: AsRef<[u8]>>(&mut self, key: K)
pub fn delete<K: AsRef<[u8]>>(&mut self, key: K)
Removes the database entry for key. Does nothing if the key was not found.
pub fn delete_cf<K: AsRef<[u8]>>(&mut self, cf: &impl AsColumnFamilyRef, key: K)
source§impl WriteBatchWithTransaction<false>
impl WriteBatchWithTransaction<false>
sourcepub fn delete_range<K: AsRef<[u8]>>(&mut self, from: K, to: K)
pub fn delete_range<K: AsRef<[u8]>>(&mut self, from: K, to: K)
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: AsRef<[u8]>>(
&mut self,
cf: &impl AsColumnFamilyRef,
from: K,
to: K,
)
pub fn delete_range_cf<K: AsRef<[u8]>>( &mut self, cf: &impl AsColumnFamilyRef, from: K, to: K, )
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”).