-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
956 additions
and
726 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use prisma_client_rust::migrations::DbPushError; | ||
use serde::{Serialize, Serializer}; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum CoreError { | ||
#[error("Prisma New Client Error")] | ||
PrismaNewClientError(#[from] prisma_client_rust::NewClientError), | ||
|
||
#[error("Prisma Query Error")] | ||
PrismaQueryError(#[from] prisma_client_rust::QueryError), | ||
|
||
#[error("Tokio IO Error")] | ||
TokioError(#[from] tokio::io::Error), | ||
|
||
#[error("Tokio Join Error")] | ||
TokioJoinError(#[from] tokio::task::JoinError), | ||
|
||
#[error("Db Push Error")] | ||
DbPushError(#[from] DbPushError), | ||
} | ||
|
||
impl Serialize for CoreError { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
serializer.serialize_str(self.to_string().as_ref()) | ||
} | ||
} | ||
|
||
pub type CommandResult<T, E = CoreError> = anyhow::Result<T, E>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use log::info; | ||
|
||
use crate::{ | ||
error::CoreError, | ||
prisma::{_prisma::PrismaClient, new_client_with_url}, | ||
util::get_app_dir, | ||
}; | ||
|
||
pub async fn new_client() -> Result<PrismaClient, CoreError> { | ||
let appdata_url = get_app_dir().join("app.db"); | ||
|
||
log::info!("Connecting to database at {}", appdata_url.display()); | ||
|
||
tokio::fs::create_dir_all(appdata_url.parent().unwrap()).await?; | ||
|
||
if !appdata_url.exists() { | ||
tokio::fs::File::create(appdata_url.clone()).await?; | ||
info!("Created database at {}", appdata_url.display()); | ||
} | ||
|
||
let client = | ||
new_client_with_url(&("file:".to_string() + appdata_url.to_str().unwrap())).await?; | ||
|
||
Ok(client) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::path::PathBuf; | ||
|
||
/// Get the accoubting config directory. | ||
/// This config directory has the following structure: | ||
/// - data.db | ||
/// - assets/ # All the images/videos/audios are stored here | ||
/// - config.toml | ||
pub fn get_app_dir() -> PathBuf { | ||
// get app dir with /accounting. use std libary | ||
let path = platform_dirs::AppDirs::new(Some("accounting"), true).unwrap(); | ||
let mut data_dir = path.data_dir; | ||
|
||
// check if in dev mode | ||
if cfg!(debug_assertions) { | ||
data_dir.push("dev"); | ||
} | ||
|
||
data_dir | ||
} |