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 DupCursorTy<TX, T> = <TX as DbTx>::DupCursor<T>;
13
14pub type CursorMutTy<TX, T> = <TX as DbTxMut>::CursorMut<T>;
16
17pub type DupCursorMutTy<TX, T> = <TX as DbTxMut>::DupCursorMut<T>;
19
20pub trait DbTx: Debug + Send {
22 type Cursor<T: Table>: DbCursorRO<T> + Send;
24 type DupCursor<T: DupSort>: DbDupCursorRO<T> + DbCursorRO<T> + Send;
26
27 fn get<T: Table>(&self, key: T::Key) -> Result<Option<T::Value>, DatabaseError>;
29 fn get_by_encoded_key<T: Table>(
33 &self,
34 key: &<T::Key as Encode>::Encoded,
35 ) -> Result<Option<T::Value>, DatabaseError>;
36 fn commit(self) -> Result<(), DatabaseError>;
39 fn abort(self);
41 fn cursor_read<T: Table>(&self) -> Result<Self::Cursor<T>, DatabaseError>;
43 fn cursor_dup_read<T: DupSort>(&self) -> Result<Self::DupCursor<T>, DatabaseError>;
45 fn entries<T: Table>(&self) -> Result<usize, DatabaseError>;
47 fn disable_long_read_transaction_safety(&mut self);
49}
50
51pub trait DbTxMut: Send {
53 type CursorMut<T: Table>: DbCursorRW<T> + DbCursorRO<T> + Send;
55 type DupCursorMut<T: DupSort>: DbDupCursorRW<T>
57 + DbCursorRW<T>
58 + DbDupCursorRO<T>
59 + DbCursorRO<T>
60 + Send;
61
62 fn put<T: Table>(&self, key: T::Key, value: T::Value) -> Result<(), DatabaseError>;
64 fn append<T: Table>(&self, key: T::Key, value: T::Value) -> Result<(), DatabaseError> {
68 self.put::<T>(key, value)
69 }
70 fn delete<T: Table>(&self, key: T::Key, value: Option<T::Value>)
72 -> Result<bool, DatabaseError>;
73 fn clear<T: Table>(&self) -> Result<(), DatabaseError>;
75 fn cursor_write<T: Table>(&self) -> Result<Self::CursorMut<T>, DatabaseError>;
77 fn cursor_dup_write<T: DupSort>(&self) -> Result<Self::DupCursorMut<T>, DatabaseError>;
79}