Use libdrcr async API

This commit is contained in:
RunasSudo 2025-05-27 16:03:12 +10:00
parent af47021e4f
commit 4ff0ea46db
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 84 additions and 92 deletions

5
src-tauri/Cargo.lock generated
View File

@ -211,9 +211,9 @@ checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
[[package]]
name = "async-trait"
version = "0.1.83"
version = "0.1.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd"
checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5"
dependencies = [
"proc-macro2",
"quote",
@ -2179,6 +2179,7 @@ checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
name = "libdrcr"
version = "0.1.0"
dependencies = [
"async-trait",
"chrono",
"downcast-rs 2.0.1",
"dyn-clone",

View File

@ -28,7 +28,6 @@ use libdrcr::reporting::types::{
};
use tauri::State;
use tokio::sync::Mutex;
use tokio::task::spawn_blocking;
use crate::AppState;
@ -40,10 +39,9 @@ pub(crate) async fn get_balance_sheet(
let state = state.lock().await;
let db_filename = state.db_filename.clone().unwrap();
spawn_blocking(move || {
// Connect to database
let db_connection =
DbConnection::connect(format!("sqlite:{}", db_filename.as_str()).as_str());
DbConnection::new(format!("sqlite:{}", db_filename.as_str()).as_str()).await;
// Initialise ReportingContext
let eofy_date = db_connection.metadata().eofy_date;
@ -74,7 +72,7 @@ pub(crate) async fn get_balance_sheet(
];
// Run report
let products = generate_report(targets, &context).unwrap();
let products = generate_report(targets, &context).await.unwrap();
let result = products
.get_or_err(&ReportingProductId {
name: "BalanceSheet",
@ -86,9 +84,6 @@ pub(crate) async fn get_balance_sheet(
let balance_sheet = result.downcast_ref::<DynamicReport>().unwrap().to_json();
Ok(balance_sheet)
})
.await
.unwrap()
}
#[tauri::command]
@ -99,10 +94,9 @@ pub(crate) async fn get_income_statement(
let state = state.lock().await;
let db_filename = state.db_filename.clone().unwrap();
spawn_blocking(move || {
// Connect to database
let db_connection =
DbConnection::connect(format!("sqlite:{}", db_filename.as_str()).as_str());
DbConnection::new(format!("sqlite:{}", db_filename.as_str()).as_str()).await;
// Initialise ReportingContext
let eofy_date = db_connection.metadata().eofy_date;
@ -134,7 +128,7 @@ pub(crate) async fn get_income_statement(
];
// Run report
let products = generate_report(targets, &context).unwrap();
let products = generate_report(targets, &context).await.unwrap();
let result = products
.get_or_err(&ReportingProductId {
name: "IncomeStatement",
@ -146,7 +140,4 @@ pub(crate) async fn get_income_statement(
let income_statement = result.downcast_ref::<DynamicReport>().unwrap().to_json();
Ok(income_statement)
})
.await
.unwrap()
}