use nimiq_database_value::IntoDatabaseValue;
use super::{
DupReadCursor, DupTable, DupWriteCursor, ReadCursor, RegularTable, Table, WriteCursor,
};
pub trait ReadTransaction<'db>: Sized {
type Cursor<'txn, T: Table>: ReadCursor<'txn, T>
where
Self: 'txn;
type DupCursor<'txn, T: DupTable>: ReadCursor<'txn, T> + DupReadCursor<'txn, T>
where
Self: 'txn;
fn close(self) {}
fn get<T: Table>(&self, table: &T, key: &T::Key) -> Option<T::Value>;
fn cursor<'txn, T: RegularTable>(&'txn self, table: &T) -> Self::Cursor<'txn, T>;
fn dup_cursor<'txn, T: DupTable>(&'txn self, table: &T) -> Self::DupCursor<'txn, T>;
}
pub trait WriteTransaction<'db>: ReadTransaction<'db> + Sized {
type WriteCursor<'txn, T: Table>: WriteCursor<'txn, T>
where
Self: 'txn;
type DupWriteCursor<'txn, T: DupTable>: DupWriteCursor<'txn, T>
where
Self: 'txn;
fn put_reserve<T: RegularTable>(&mut self, table: &T, key: &T::Key, value: &T::Value)
where
T::Value: IntoDatabaseValue;
fn put<T: Table>(&mut self, table: &T, key: &T::Key, value: &T::Value);
fn append<T: Table>(&mut self, table: &T, key: &T::Key, value: &T::Value);
fn remove<T: Table>(&mut self, table: &T, key: &T::Key);
fn remove_item<T: Table>(&mut self, table: &T, key: &T::Key, value: &T::Value);
fn commit(self);
fn abort(self) {}
fn cursor<'txn, T: RegularTable>(&'txn self, table: &T) -> Self::WriteCursor<'txn, T>;
fn dup_cursor<'txn, T: DupTable>(&'txn self, table: &T) -> Self::DupWriteCursor<'txn, T>;
fn clear_table<T: Table>(&mut self, table: &T);
}