Struct rocksdb::TransactionDB
pub struct TransactionDB<T = SingleThreaded>where
T: ThreadMode,{ /* private fields */ }
Expand description
RocksDB TransactionDB.
Please read the official guide to learn more about RocksDB TransactionDB.
The default thread mode for TransactionDB
is SingleThreaded
if feature multi-threaded-cf
is not enabled.
use rocksdb::{DB, Options, TransactionDB, SingleThreaded};
let path = "_path_for_transaction_db";
{
let db: TransactionDB = TransactionDB::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);
Implementations§
§impl<T> TransactionDB<T>where
T: ThreadMode,
impl<T> TransactionDB<T>where
T: ThreadMode,
pub fn open_default<P>(path: P) -> Result<TransactionDB<T>, Error>
pub fn open_default<P>(path: P) -> Result<TransactionDB<T>, Error>
Opens a database with default options.
pub fn open<P>(
opts: &Options,
txn_db_opts: &TransactionDBOptions,
path: P,
) -> Result<TransactionDB<T>, Error>
pub fn open<P>( opts: &Options, txn_db_opts: &TransactionDBOptions, path: P, ) -> Result<TransactionDB<T>, Error>
Opens the database with the specified options.
pub fn open_cf<P, I, N>(
opts: &Options,
txn_db_opts: &TransactionDBOptions,
path: P,
cfs: I,
) -> Result<TransactionDB<T>, Error>
pub fn open_cf<P, I, N>( opts: &Options, txn_db_opts: &TransactionDBOptions, path: P, cfs: I, ) -> Result<TransactionDB<T>, 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
.
pub fn open_cf_descriptors<P, I>(
opts: &Options,
txn_db_opts: &TransactionDBOptions,
path: P,
cfs: I,
) -> Result<TransactionDB<T>, Error>
pub fn open_cf_descriptors<P, I>( opts: &Options, txn_db_opts: &TransactionDBOptions, path: P, cfs: I, ) -> Result<TransactionDB<T>, Error>
Opens a database with the given database options and column family descriptors.
pub fn list_cf<P>(opts: &Options, path: P) -> Result<Vec<String>, Error>
pub fn destroy<P>(opts: &Options, path: P) -> Result<(), Error>
pub fn repair<P>(opts: &Options, path: P) -> Result<(), Error>
pub fn path(&self) -> &Path
pub fn transaction(&self) -> Transaction<'_, TransactionDB<T>>
pub fn transaction(&self) -> Transaction<'_, TransactionDB<T>>
Creates a transaction with default options.
pub fn transaction_opt<'a>(
&'a self,
write_opts: &WriteOptions,
txn_opts: &TransactionOptions,
) -> Transaction<'a, TransactionDB<T>>
pub fn transaction_opt<'a>( &'a self, write_opts: &WriteOptions, txn_opts: &TransactionOptions, ) -> Transaction<'a, TransactionDB<T>>
Creates a transaction with options.
pub fn prepared_transactions(&self) -> Vec<Transaction<'_, TransactionDB<T>>>
pub fn prepared_transactions(&self) -> Vec<Transaction<'_, TransactionDB<T>>>
Get all prepared transactions for recovery.
This function is expected to call once after open database. User should commit or rollback all transactions before start other transactions.
pub fn get<K>(&self, key: K) -> Result<Option<Vec<u8>>, Error>
pub fn get<K>(&self, key: K) -> Result<Option<Vec<u8>>, Error>
Returns the bytes associated with a key value.
pub fn get_cf<K>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
) -> Result<Option<Vec<u8>>, Error>
pub fn get_cf<K>( &self, cf: &impl AsColumnFamilyRef, key: K, ) -> Result<Option<Vec<u8>>, Error>
Returns the bytes associated with a key value and the given column family.
pub fn get_opt<K>(
&self,
key: K,
readopts: &ReadOptions,
) -> Result<Option<Vec<u8>>, Error>
pub fn get_opt<K>( &self, key: K, readopts: &ReadOptions, ) -> Result<Option<Vec<u8>>, Error>
Returns the bytes associated with a key value with read options.
pub fn get_cf_opt<K>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
readopts: &ReadOptions,
) -> Result<Option<Vec<u8>>, Error>
pub fn get_cf_opt<K>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions, ) -> Result<Option<Vec<u8>>, Error>
Returns the bytes associated with a key value and the given column family with read options.
pub fn get_pinned<K>( &self, key: K, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
pub fn get_pinned_cf<K>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
) -> Result<Option<DBPinnableSlice<'_>>, Error>
pub fn get_pinned_cf<K>( &self, cf: &impl AsColumnFamilyRef, key: K, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
Returns the bytes associated with a key value and the given column family.
pub fn get_pinned_opt<K>(
&self,
key: K,
readopts: &ReadOptions,
) -> Result<Option<DBPinnableSlice<'_>>, Error>
pub fn get_pinned_opt<K>( &self, key: K, readopts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
Returns the bytes associated with a key value with read options.
pub fn get_pinned_cf_opt<K>(
&self,
cf: &impl AsColumnFamilyRef,
key: K,
readopts: &ReadOptions,
) -> Result<Option<DBPinnableSlice<'_>>, Error>
pub fn get_pinned_cf_opt<K>( &self, cf: &impl AsColumnFamilyRef, key: K, readopts: &ReadOptions, ) -> Result<Option<DBPinnableSlice<'_>>, Error>
Returns the bytes associated with a key value and the given column family with read options.
pub fn multi_get<K, I>(&self, keys: I) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get<K, I>(&self, keys: I) -> Vec<Result<Option<Vec<u8>>, Error>>
Return the values associated with the given keys.
pub fn multi_get_opt<K, I>(
&self,
keys: I,
readopts: &ReadOptions,
) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get_opt<K, I>( &self, keys: I, readopts: &ReadOptions, ) -> Vec<Result<Option<Vec<u8>>, Error>>
Return the values associated with the given keys using read options.
pub fn multi_get_cf<'a, 'b, K, I, W>(
&'a self,
keys: I,
) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get_cf<'a, 'b, K, I, W>( &'a self, keys: I, ) -> Vec<Result<Option<Vec<u8>>, Error>>
Return the values associated with the given keys and column families.
pub fn multi_get_cf_opt<'a, 'b, K, I, W>(
&'a self,
keys: I,
readopts: &ReadOptions,
) -> Vec<Result<Option<Vec<u8>>, Error>>
pub fn multi_get_cf_opt<'a, 'b, K, I, W>( &'a self, keys: I, readopts: &ReadOptions, ) -> Vec<Result<Option<Vec<u8>>, Error>>
Return the values associated with the given keys and column families using read options.
pub fn put<K, V>(&self, key: K, value: V) -> Result<(), Error>
pub fn put_cf<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V, ) -> Result<(), Error>
pub fn put_opt<K, V>( &self, key: K, value: V, writeopts: &WriteOptions, ) -> Result<(), Error>
pub fn put_cf_opt<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V, writeopts: &WriteOptions, ) -> Result<(), Error>
pub fn write(&self, batch: WriteBatchWithTransaction<true>) -> Result<(), Error>
pub fn write_opt( &self, batch: WriteBatchWithTransaction<true>, writeopts: &WriteOptions, ) -> Result<(), Error>
pub fn merge<K, V>(&self, key: K, value: V) -> Result<(), Error>
pub fn merge_cf<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V, ) -> Result<(), Error>
pub fn merge_opt<K, V>( &self, key: K, value: V, writeopts: &WriteOptions, ) -> Result<(), Error>
pub fn merge_cf_opt<K, V>( &self, cf: &impl AsColumnFamilyRef, key: K, value: V, writeopts: &WriteOptions, ) -> Result<(), Error>
pub fn delete<K>(&self, key: K) -> Result<(), Error>
pub fn delete_cf<K>( &self, cf: &impl AsColumnFamilyRef, key: K, ) -> Result<(), Error>
pub fn delete_opt<K>( &self, key: K, writeopts: &WriteOptions, ) -> Result<(), Error>
pub fn delete_cf_opt<K>( &self, cf: &impl AsColumnFamilyRef, key: K, writeopts: &WriteOptions, ) -> Result<(), Error>
pub fn iterator<'a, 'b>(
&'a self,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'b, TransactionDB<T>> ⓘwhere
'a: 'b,
pub fn iterator_opt<'a, 'b>(
&'a self,
mode: IteratorMode<'_>,
readopts: ReadOptions,
) -> DBIteratorWithThreadMode<'b, TransactionDB<T>> ⓘwhere
'a: 'b,
pub fn iterator_cf_opt<'a, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
readopts: ReadOptions,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'b, TransactionDB<T>> ⓘwhere
'a: 'b,
pub fn iterator_cf_opt<'a, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
readopts: ReadOptions,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'b, TransactionDB<T>> ⓘwhere
'a: 'b,
Opens an iterator using the provided ReadOptions. This is used when you want to iterate over a specific ColumnFamily with a modified ReadOptions
pub fn full_iterator<'a, 'b>(
&'a self,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'b, TransactionDB<T>> ⓘwhere
'a: 'b,
pub fn full_iterator<'a, 'b>(
&'a self,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'b, TransactionDB<T>> ⓘwhere
'a: 'b,
Opens an iterator with set_total_order_seek
enabled.
This must be used to iterate across prefixes when set_memtable_factory
has been called
with a Hash-based implementation.
pub fn prefix_iterator<'a, 'b, P>( &'a self, prefix: P, ) -> DBIteratorWithThreadMode<'b, TransactionDB<T>> ⓘ
pub fn iterator_cf<'a, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'b, TransactionDB<T>> ⓘwhere
'a: 'b,
pub fn full_iterator_cf<'a, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
mode: IteratorMode<'_>,
) -> DBIteratorWithThreadMode<'b, TransactionDB<T>> ⓘwhere
'a: 'b,
pub fn prefix_iterator_cf<'a, P>( &'a self, cf_handle: &impl AsColumnFamilyRef, prefix: P, ) -> DBIteratorWithThreadMode<'a, TransactionDB<T>> ⓘ
pub fn raw_iterator<'a, 'b>(
&'a self,
) -> DBRawIteratorWithThreadMode<'b, TransactionDB<T>>where
'a: 'b,
pub fn raw_iterator<'a, 'b>(
&'a self,
) -> DBRawIteratorWithThreadMode<'b, TransactionDB<T>>where
'a: 'b,
Opens a raw iterator over the database, using the default read options
pub fn raw_iterator_cf<'a, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
) -> DBRawIteratorWithThreadMode<'b, TransactionDB<T>>where
'a: 'b,
pub fn raw_iterator_cf<'a, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
) -> DBRawIteratorWithThreadMode<'b, TransactionDB<T>>where
'a: 'b,
Opens a raw iterator over the given column family, using the default read options
pub fn raw_iterator_opt<'a, 'b>(
&'a self,
readopts: ReadOptions,
) -> DBRawIteratorWithThreadMode<'b, TransactionDB<T>>where
'a: 'b,
pub fn raw_iterator_opt<'a, 'b>(
&'a self,
readopts: ReadOptions,
) -> DBRawIteratorWithThreadMode<'b, TransactionDB<T>>where
'a: 'b,
Opens a raw iterator over the database, using the given read options
pub fn raw_iterator_cf_opt<'a, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
readopts: ReadOptions,
) -> DBRawIteratorWithThreadMode<'b, TransactionDB<T>>where
'a: 'b,
pub fn raw_iterator_cf_opt<'a, 'b>(
&'a self,
cf_handle: &impl AsColumnFamilyRef,
readopts: ReadOptions,
) -> DBRawIteratorWithThreadMode<'b, TransactionDB<T>>where
'a: 'b,
Opens a raw iterator over the given column family, using the given read options