- Updated Cargo.toml to include necessary dependencies for SeaORM and database handling. - Implemented database connection establishment in `src-tauri/src/db/connection.rs`. - Created database entities for accounts, exchange rates, goals, transactions, and more using SeaORM. - Added migration handling in `src-tauri/src/db/migrations.rs`. - Introduced a database service layer in `src-tauri/src/db/service.rs` for managing database connections and migrations. - Updated the main library file to include the new database module.
27 lines
676 B
Rust
27 lines
676 B
Rust
use sea_orm::{DatabaseConnection, DbErr};
|
|
|
|
use super::connection;
|
|
|
|
pub struct DbService {
|
|
connection: DatabaseConnection,
|
|
}
|
|
|
|
impl DbService {
|
|
pub async fn new(app_handle: &tauri::AppHandle) -> Result<Self, DbErr> {
|
|
let connection = connection::establish_connection(app_handle).await?;
|
|
Ok(Self { connection })
|
|
}
|
|
|
|
pub fn get_connection(&self) -> &DatabaseConnection {
|
|
&self.connection
|
|
}
|
|
|
|
pub fn get_connection_mut(&mut self) -> &mut DatabaseConnection {
|
|
&mut self.connection
|
|
}
|
|
|
|
pub async fn run_migrations(&self) -> Result<(), DbErr> {
|
|
crate::db::migrations::run_migrations(&self.connection).await
|
|
}
|
|
}
|