pub type OptimisticTransactionDB<T = SingleThreaded> = DBCommon<T, OptimisticTransactionDBInner>;
Expand description
A type alias to RocksDB Optimistic Transaction DB.
Please read the official guide to learn more about RocksDB OptimisticTransactionDB.
The default thread mode for OptimisticTransactionDB
is SingleThreaded
if feature multi-threaded-cf
is not enabled.
See DBCommon
for full list of methods.
§Examples
use rust_rocksdb::{DB, Options, OptimisticTransactionDB, SingleThreaded};
let tempdir = tempfile::Builder::new()
.prefix("_path_for_optimistic_transaction_db")
.tempdir()
.expect("Failed to create temporary path for the _path_for_optimistic_transaction_db");
let path = tempdir.path();
{
let db: OptimisticTransactionDB = OptimisticTransactionDB::open_default(path).unwrap();
db.put(b"my key", b"my value").unwrap();
// create transaction
let txn = db.transaction();
txn.put(b"key2", b"value2");
txn.put(b"key3", b"value3");
txn.commit().unwrap();
}
let _ = DB::destroy(&Options::default(), path);
Aliased Type§
pub struct OptimisticTransactionDB<T = SingleThreaded> { /* private fields */ }
Implementations§
Source§impl<T: ThreadMode> OptimisticTransactionDB<T>
Methods of OptimisticTransactionDB
.
impl<T: ThreadMode> OptimisticTransactionDB<T>
Methods of OptimisticTransactionDB
.
Sourcepub fn open_default<P: AsRef<Path>>(path: P) -> Result<Self, Error>
pub fn open_default<P: AsRef<Path>>(path: P) -> Result<Self, Error>
Opens a database with default options.
Sourcepub fn open<P: AsRef<Path>>(opts: &Options, path: P) -> Result<Self, Error>
pub fn open<P: AsRef<Path>>(opts: &Options, path: P) -> Result<Self, Error>
Opens the database with the specified options.
Sourcepub fn open_cf<P, I, N>(opts: &Options, path: P, cfs: I) -> Result<Self, Error>
pub fn open_cf<P, I, N>(opts: &Options, path: P, cfs: I) -> Result<Self, Error>
Opens a database with the given database options and column family names.
Column families opened using this function will be created with default Options
.
NOTE: default
column family will be opened with the Options::default()
.
If you want to open default
column family with custom options, use open_cf_descriptors
and
provide a ColumnFamilyDescriptor
with the desired options.
Sourcepub fn open_cf_descriptors<P, I>(
opts: &Options,
path: P,
cfs: I,
) -> Result<Self, Error>
pub fn open_cf_descriptors<P, I>( opts: &Options, path: P, cfs: I, ) -> Result<Self, Error>
Opens a database with the given database options and column family descriptors.
Sourcepub fn transaction(&self) -> Transaction<'_, Self>
pub fn transaction(&self) -> Transaction<'_, Self>
Creates a transaction with default options.
Sourcepub fn transaction_opt(
&self,
writeopts: &WriteOptions,
otxn_opts: &OptimisticTransactionOptions,
) -> Transaction<'_, Self>
pub fn transaction_opt( &self, writeopts: &WriteOptions, otxn_opts: &OptimisticTransactionOptions, ) -> Transaction<'_, Self>
Creates a transaction with default options.
pub fn write_opt( &self, batch: WriteBatchWithTransaction<true>, writeopts: &WriteOptions, ) -> Result<(), Error>
pub fn write(&self, batch: WriteBatchWithTransaction<true>) -> Result<(), Error>
pub fn write_without_wal( &self, batch: WriteBatchWithTransaction<true>, ) -> Result<(), Error>
Sourcepub fn delete_range_cf_opt<K: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
from: K,
to: K,
writeopts: &WriteOptions,
) -> Result<(), Error>
pub fn delete_range_cf_opt<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, from: K, to: K, writeopts: &WriteOptions, ) -> Result<(), Error>
Removes the database entries in the range ["from", "to")
using given write options.
Sourcepub fn delete_range_cf<K: AsRef<[u8]>>(
&self,
cf: &impl AsColumnFamilyRef,
from: K,
to: K,
) -> Result<(), Error>
pub fn delete_range_cf<K: AsRef<[u8]>>( &self, cf: &impl AsColumnFamilyRef, from: K, to: K, ) -> Result<(), Error>
Removes the database entries in the range ["from", "to")
using default write options.