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 rust_rocksdb::{DB, Options, WriteBatchWithTransaction};
let tempdir = tempfile::Builder::new()
.prefix("_path_for_rocksdb_storage1")
.tempdir()
.expect("Failed to create temporary path for the _path_for_rocksdb_storage1");
let path = tempdir.path();
{
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 with_capacity_bytes(capacity_bytes: usize) -> Self
pub fn with_capacity_bytes(capacity_bytes: usize) -> Self
Creates WriteBatch with the specified capacity in bytes. Allocates immediately.
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<T: WriteBatchIterator>(&self, callbacks: &mut T)
pub fn iterate<T: WriteBatchIterator>(&self, callbacks: &mut T)
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 iterate_cf<T: WriteBatchIteratorCf>(&self, callbacks: &mut T)
pub fn iterate_cf<T: WriteBatchIteratorCf>(&self, callbacks: &mut T)
Iterate the put, delete, and merge operations within this write batch with column family
information. Note that this does not return an Iterator but instead will invoke the
put_cf(), delete_cf(), and merge_cf() member functions of the provided
WriteBatchIteratorCf trait implementation.
§Notes
- For operations on the default column family (“default”), the
cf_idparameter passed to the callbacks will be 0
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.
Sourcepub fn put_vectored(
&mut self,
key: &[IoSlice<'_>],
value: &[IoSlice<'_>],
) -> Result<(), Error>
pub fn put_vectored( &mut self, key: &[IoSlice<'_>], value: &[IoSlice<'_>], ) -> Result<(), Error>
Inserts one key and value assembled from multiple byte slices.
This avoids concatenating the parts in Rust. RocksDB copies the key and value parts into the write batch during this call, so the slices do not need to outlive the method.
Sourcepub fn put_cf<K, V>(&mut self, cf: &impl AsColumnFamilyRef, key: K, value: V)
pub fn put_cf<K, V>(&mut self, cf: &impl AsColumnFamilyRef, key: K, value: V)
Insert a value into the specific column family of the database under the given key.
Sourcepub fn put_cf_vectored(
&mut self,
cf: &impl AsColumnFamilyRef,
key: &[IoSlice<'_>],
value: &[IoSlice<'_>],
) -> Result<(), Error>
pub fn put_cf_vectored( &mut self, cf: &impl AsColumnFamilyRef, key: &[IoSlice<'_>], value: &[IoSlice<'_>], ) -> Result<(), Error>
Inserts one key and value assembled from multiple byte slices into a column family.
This avoids concatenating the parts in Rust. RocksDB copies the key and value parts into the write batch during this call, so the slices do not need to outlive the method.
Sourcepub fn put_cf_with_ts<K, V, S>(
&mut self,
cf: &impl AsColumnFamilyRef,
key: K,
ts: S,
value: V,
)
pub fn put_cf_with_ts<K, V, S>( &mut self, cf: &impl AsColumnFamilyRef, key: K, ts: S, value: V, )
Insert a value into the specific column family of the database under the given key with timestamp.
pub fn merge<K, V>(&mut self, key: K, value: V)
Sourcepub fn merge_vectored(
&mut self,
key: &[IoSlice<'_>],
value: &[IoSlice<'_>],
) -> Result<(), Error>
pub fn merge_vectored( &mut self, key: &[IoSlice<'_>], value: &[IoSlice<'_>], ) -> Result<(), Error>
Merges one key and value assembled from multiple byte slices.
This avoids concatenating the parts in Rust. RocksDB copies the key and value parts into the write batch during this call, so the slices do not need to outlive the method.
pub fn merge_cf<K, V>(&mut self, cf: &impl AsColumnFamilyRef, key: K, value: V)
Sourcepub fn merge_cf_vectored(
&mut self,
cf: &impl AsColumnFamilyRef,
key: &[IoSlice<'_>],
value: &[IoSlice<'_>],
) -> Result<(), Error>
pub fn merge_cf_vectored( &mut self, cf: &impl AsColumnFamilyRef, key: &[IoSlice<'_>], value: &[IoSlice<'_>], ) -> Result<(), Error>
Merges one key and value assembled from multiple byte slices in a column family.
This avoids concatenating the parts in Rust. RocksDB copies the key and value parts into the write batch during this call, so the slices do not need to outlive the method.
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.
Sourcepub fn delete_vectored(&mut self, key: &[IoSlice<'_>]) -> Result<(), Error>
pub fn delete_vectored(&mut self, key: &[IoSlice<'_>]) -> Result<(), Error>
Removes the entry for one key assembled from multiple byte slices.
This avoids concatenating the parts in Rust. RocksDB copies the key parts into the write batch during this call, so the slices do not need to outlive the method.
Sourcepub fn delete_cf<K: AsRef<[u8]>>(&mut self, cf: &impl AsColumnFamilyRef, key: K)
pub fn delete_cf<K: AsRef<[u8]>>(&mut self, cf: &impl AsColumnFamilyRef, key: K)
Removes the database entry in the specific column family for key. Does nothing if the key was not found.
Sourcepub fn delete_cf_vectored(
&mut self,
cf: &impl AsColumnFamilyRef,
key: &[IoSlice<'_>],
) -> Result<(), Error>
pub fn delete_cf_vectored( &mut self, cf: &impl AsColumnFamilyRef, key: &[IoSlice<'_>], ) -> Result<(), Error>
Removes the entry for one key assembled from multiple byte slices in a column family.
This avoids concatenating the parts in Rust. RocksDB copies the key parts into the write batch during this call, so the slices do not need to outlive the method.
Sourcepub fn delete_cf_with_ts<K: AsRef<[u8]>, S: AsRef<[u8]>>(
&mut self,
cf: &impl AsColumnFamilyRef,
key: K,
ts: S,
)
pub fn delete_cf_with_ts<K: AsRef<[u8]>, S: AsRef<[u8]>>( &mut self, cf: &impl AsColumnFamilyRef, key: K, ts: S, )
Removes the database entry in the specific column family with timestamp for key. Does nothing if the key was not found.
pub fn put_log_data<V: AsRef<[u8]>>(&mut self, log_data: V)
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_vectored(
&mut self,
from: &[IoSlice<'_>],
to: &[IoSlice<'_>],
) -> Result<(), Error>
pub fn delete_range_vectored( &mut self, from: &[IoSlice<'_>], to: &[IoSlice<'_>], ) -> Result<(), Error>
Removes entries in a range whose bounds are assembled from byte slices.
The range includes from and excludes to. Both bounds must be split
into the same number of parts: the System backend forwards them to
rocksdb_writebatch_delete_rangev, which takes one part count for the
pair. Split them differently and this returns an error.
RocksDB copies both bounds into the write batch during this call, so the slices do not need to outlive the method.
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”).
Sourcepub fn delete_range_cf_vectored(
&mut self,
cf: &impl AsColumnFamilyRef,
from: &[IoSlice<'_>],
to: &[IoSlice<'_>],
) -> Result<(), Error>
pub fn delete_range_cf_vectored( &mut self, cf: &impl AsColumnFamilyRef, from: &[IoSlice<'_>], to: &[IoSlice<'_>], ) -> Result<(), Error>
Removes entries in a column family range whose bounds are assembled from byte slices.
The range includes from and excludes to, and both bounds must be
split into the same number of parts. See
delete_range_vectored.
RocksDB copies both bounds into the write batch during this call, so the slices do not need to outlive the method.