fuck off, I call that a day.
This commit is contained in:
1 parent
04d4d1b7a9
commit
cb5805a829
12 files changed
+229
-86
No files matched your search
+2
-27
@@ -1,39 +1,14 @@
|
||||
use rusqlite::{Params, Row, Transaction};
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
SqlError(rusqlite::Error),
|
||||
DoubleBooking(String),
|
||||
InvalidDrawer(String),
|
||||
InvalidAmount(String),
|
||||
InvalidPayee(String),
|
||||
DoubleSpendingError(String),
|
||||
IOError(io::Error),
|
||||
Testing(String),
|
||||
}
|
||||
|
||||
pub type CustomResult<T, E = Error> = Result<T, E>;
|
||||
|
||||
pub struct TransactionHelper<'a> {
|
||||
tx: &'a Transaction<'a>,
|
||||
}
|
||||
|
||||
impl TransactionHelper<'_> {
|
||||
pub fn new<'a>(tx: &'a Transaction) -> TransactionHelper<'a> {
|
||||
TransactionHelper { tx }
|
||||
}
|
||||
|
||||
pub fn execute<P: Params>(&self, sql: &str, params: P) -> CustomResult<usize> {
|
||||
self.tx.execute(sql, params).map_err(Error::SqlError)
|
||||
}
|
||||
|
||||
pub fn query_row<T, P, F>(&self, sql: &str, params: P, f: F) -> CustomResult<T>
|
||||
where
|
||||
P: Params,
|
||||
F: FnOnce(&Row<'_>) -> rusqlite::Result<T>, {
|
||||
self.tx.query_row(sql, params, f).map_err(Error::SqlError)
|
||||
}
|
||||
//
|
||||
// pub fn commit(&self) -> CustomResult<()> {
|
||||
// self.tx.commit().map_err(Error::SqlError)
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user