Skip to content

Commit

Permalink
feat: record highlight is styled, every view has a layout
Browse files Browse the repository at this point in the history
  • Loading branch information
szattila98 committed Mar 23, 2024
1 parent 1b28777 commit 2c40cde
Show file tree
Hide file tree
Showing 25 changed files with 554 additions and 227 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"dependencies": {
"@tauri-apps/api": "1.5.3",
"dayjs": "1.11.10",
"svelte-icons": "2.1.0"
"svelte-icons": "2.1.0",
"ts-toolbelt": "^9.6.0"
},
"devDependencies": {
"@playwright/test": "1.42.1",
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 12 additions & 28 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ edition = "2021"
tauri-build = { version = "1.5", features = [] }

[dependencies]
dirs = "5.0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
specta = { version = "=2.0.0-rc.7", features = ["functions", "export", "time"] }
Expand All @@ -23,11 +22,20 @@ sqlx = { version = "0.7.3", features = [
"time",
] }
strum = { version = "0.26.2", features = ["derive"] }
tauri = { version = "1.6", features = [ "process-exit", "shell-open"] }
tap = "1.0.1"
tauri = { version = "1.6", features = [
"process-exit",
"shell-open",
"tracing",
] }
tauri-specta = { version = "=2.0.0-rc.4", features = ["typescript"] }
time = { version = "0.3.29", features = ["serde"] }
tokio = { version = "1.36.0", features = ["full"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"

[dev-dependencies]
tauri = { version = "1.6", features = ["test"] }

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
43 changes: 24 additions & 19 deletions src-tauri/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,42 @@ use sqlx::sqlite::SqlitePoolOptions;
use sqlx::SqlitePool;
use std::fs;
use std::path::Path;
use tap::Tap;
use tracing::info;

use tauri::PathResolver;

pub struct DbWrapper {
pub pool: SqlitePool,
}

pub fn init() {
if !db_file_exists() {
create_db_file();
pub fn init(path_resolver: &PathResolver) -> String {
let db_path = get_db_path(path_resolver);
if !db_file_exists(&db_path) {
create_db_file(&db_path).tap(|_| info!("created sqlite db file on path: '{db_path}'"));
}
db_path
}

pub async fn establish_connection() -> SqlitePool {
pub async fn establish_connection(db_path: String) -> SqlitePool {
let pool = SqlitePoolOptions::new()
.max_connections(100)
.connect(&get_db_path())
.connect(&db_path)
.await
.expect("Unable to connect to Postgres");
.expect("error while connecting to sqlite database")
.tap(|_| info!("connected to sqlite db on path: '{db_path}'"));
sqlx::migrate!()
.run(&pool)
.await
.expect("error while running embedded migrations");
pool
}

fn db_file_exists() -> bool {
let db_path = get_db_path();
Path::new(&db_path).exists()
fn db_file_exists(db_path: &str) -> bool {
Path::new(db_path).exists()
}

fn create_db_file() {
let db_path = get_db_path();
fn create_db_file(db_path: &str) {
let db_dir = Path::new(&db_path)
.parent()
.expect("cannot get sqlite parent directory");
Expand All @@ -44,12 +49,12 @@ fn create_db_file() {
fs::File::create(db_path).expect("cannot create sqlite file");
}

fn get_db_path() -> String {
let home_dir = dirs::home_dir().expect("cannot get user home directory");
format!(
"{}/.config/ups-and-downs/database.sqlite",
home_dir
.to_str()
.expect("cannot convert user home directory to string")
)
fn get_db_path(path_resolver: &PathResolver) -> String {
path_resolver
.app_data_dir()
.expect("could not resolve app data directory")
.join("database.sqlite")
.to_str()
.expect("could not convert database path to string")
.to_string()
}
Loading

0 comments on commit 2c40cde

Please sign in to comment.