account total
This commit is contained in:
@@ -77,6 +77,18 @@ pub fn get_account(con: &Connection, id: i64) -> Account {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_account_total(id: i64, con: &Connection) -> f64 {
|
||||
let query = "SELECT SUM(amount) as total FROM Transactions WHERE account_id = ?";
|
||||
let mut statement = con.prepare(query).unwrap();
|
||||
statement.bind((1, id)).unwrap();
|
||||
|
||||
if let Ok(State::Row) = statement.next() {
|
||||
return statement.read::<f64, _>("total").unwrap();
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_accounts(con: &Connection) -> Vec<Account> {
|
||||
let query = "SELECT * FROM Accounts";
|
||||
let mut statement = con.prepare(query).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user