reth_db_api/
transaction.rs1use crate::{
2 cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW},
3 table::{DupSort, Encode, Table},
4 DatabaseError,
5};
6use std::fmt::Debug;
7
8pub type CursorTy<TX, T> = <TX as DbTx>::Cursor<T>;
10
11pub type CursorMutTy<TX, T> = <TX as DbTxMut>::CursorMut<T>;
13
14pub trait DbTx: Debug + Send + Sync {
16 type Cursor<T: Table>: DbCursorRO<T> + Send + Sync;
18 type DupCursor<T: DupSort>: DbDupCursorRO<T> + DbCursorRO<T> + Send + Sync;
20
21 fn get<T: Table>(&self, key: T::Key) -> Result<Option<T::Value>, DatabaseError>;
23 fn get_by_encoded_key<T: Table>(
27 &self,
28 key: &<T::Key as Encode>::Encoded,
29 ) -> Result<Option<T::Value>, DatabaseError>;
30 fn commit(self) -> Result<bool, DatabaseError>;
33 fn abort(self);
35 fn cursor_read<T: Table>(&self) -> Result<Self::Cursor<T>, DatabaseError>;
37 fn cursor_dup_read<T: DupSort>(&self) -> Result<Self::DupCursor<T>, DatabaseError>;
39 fn entries<T: Table>(&self) -> Result<usize, DatabaseError>;
41 fn disable_long_read_transaction_safety(&mut self);
43}
44
45pub trait DbTxMut: Send + Sync {
47 type CursorMut<T: Table>: DbCursorRW<T> + DbCursorRO<T> + Send + Sync;
49 type DupCursorMut<T: DupSort>: DbDupCursorRW<T>
51 + DbCursorRW<T>
52 + DbDupCursorRO<T>
53 + DbCursorRO<T>
54 + Send
55 + Sync;
56
57 fn put<T: Table>(&self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>;
59 fn append<T: Table>(&self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> {
63 self.put::<T>(key, value)
64 }
65 fn delete<T: Table>(&self, key: T::Key, value: Option<T::Value>)
67 -> Result<bool, DatabaseError>;
68 fn clear<T: Table>(&self) -> Result<(), DatabaseError>;
70 fn cursor_write<T: Table>(&self) -> Result<Self::CursorMut<T>, DatabaseError>;
72 fn cursor_dup_write<T: DupSort>(&self) -> Result<Self::DupCursorMut<T>, DatabaseError>;
74}