Use libdrcr async API
This commit is contained in:
parent
af47021e4f
commit
4ff0ea46db
5
src-tauri/Cargo.lock
generated
5
src-tauri/Cargo.lock
generated
@ -211,9 +211,9 @@ checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-trait"
|
name = "async-trait"
|
||||||
version = "0.1.83"
|
version = "0.1.88"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd"
|
checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -2179,6 +2179,7 @@ checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
|
|||||||
name = "libdrcr"
|
name = "libdrcr"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
"downcast-rs 2.0.1",
|
"downcast-rs 2.0.1",
|
||||||
"dyn-clone",
|
"dyn-clone",
|
||||||
|
@ -28,7 +28,6 @@ use libdrcr::reporting::types::{
|
|||||||
};
|
};
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use tokio::task::spawn_blocking;
|
|
||||||
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
@ -40,10 +39,9 @@ pub(crate) async fn get_balance_sheet(
|
|||||||
let state = state.lock().await;
|
let state = state.lock().await;
|
||||||
let db_filename = state.db_filename.clone().unwrap();
|
let db_filename = state.db_filename.clone().unwrap();
|
||||||
|
|
||||||
spawn_blocking(move || {
|
|
||||||
// Connect to database
|
// Connect to database
|
||||||
let db_connection =
|
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
|
// Initialise ReportingContext
|
||||||
let eofy_date = db_connection.metadata().eofy_date;
|
let eofy_date = db_connection.metadata().eofy_date;
|
||||||
@ -74,7 +72,7 @@ pub(crate) async fn get_balance_sheet(
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Run report
|
// Run report
|
||||||
let products = generate_report(targets, &context).unwrap();
|
let products = generate_report(targets, &context).await.unwrap();
|
||||||
let result = products
|
let result = products
|
||||||
.get_or_err(&ReportingProductId {
|
.get_or_err(&ReportingProductId {
|
||||||
name: "BalanceSheet",
|
name: "BalanceSheet",
|
||||||
@ -86,9 +84,6 @@ pub(crate) async fn get_balance_sheet(
|
|||||||
let balance_sheet = result.downcast_ref::<DynamicReport>().unwrap().to_json();
|
let balance_sheet = result.downcast_ref::<DynamicReport>().unwrap().to_json();
|
||||||
|
|
||||||
Ok(balance_sheet)
|
Ok(balance_sheet)
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@ -99,10 +94,9 @@ pub(crate) async fn get_income_statement(
|
|||||||
let state = state.lock().await;
|
let state = state.lock().await;
|
||||||
let db_filename = state.db_filename.clone().unwrap();
|
let db_filename = state.db_filename.clone().unwrap();
|
||||||
|
|
||||||
spawn_blocking(move || {
|
|
||||||
// Connect to database
|
// Connect to database
|
||||||
let db_connection =
|
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
|
// Initialise ReportingContext
|
||||||
let eofy_date = db_connection.metadata().eofy_date;
|
let eofy_date = db_connection.metadata().eofy_date;
|
||||||
@ -134,7 +128,7 @@ pub(crate) async fn get_income_statement(
|
|||||||
];
|
];
|
||||||
|
|
||||||
// Run report
|
// Run report
|
||||||
let products = generate_report(targets, &context).unwrap();
|
let products = generate_report(targets, &context).await.unwrap();
|
||||||
let result = products
|
let result = products
|
||||||
.get_or_err(&ReportingProductId {
|
.get_or_err(&ReportingProductId {
|
||||||
name: "IncomeStatement",
|
name: "IncomeStatement",
|
||||||
@ -146,7 +140,4 @@ pub(crate) async fn get_income_statement(
|
|||||||
let income_statement = result.downcast_ref::<DynamicReport>().unwrap().to_json();
|
let income_statement = result.downcast_ref::<DynamicReport>().unwrap().to_json();
|
||||||
|
|
||||||
Ok(income_statement)
|
Ok(income_statement)
|
||||||
})
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user