From dcfb500a5f5910ba5351de19c94595bd56197ce5 Mon Sep 17 00:00:00 2001 From: Iaphetes Date: Sat, 15 Mar 2025 21:12:32 +0100 Subject: [PATCH] continued work on database --- src-tauri/src/database.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/database.rs b/src-tauri/src/database.rs index 4618e89..8a27ed1 100644 --- a/src-tauri/src/database.rs +++ b/src-tauri/src/database.rs @@ -1,6 +1,6 @@ use std::{ fs::File, - io::{Error, Read, Result}, + io::{Error, Read}, path::Path, }; @@ -9,12 +9,26 @@ use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool}; use tauri::{ipc::RuntimeCapability, App, AssetResolver, Manager, Url}; async fn populate_file_db(db: &SqlitePool) {} +fn get_database_path(app_handle: &tauri::AppHandle) -> Result { + if let Some(basepath) = get_basepath(app_handle.clone()) { + let db_path = Path::new("Documents") + .join(Path::new("Knowledgebase")) + .join("db.sqlite"); + + let resolved_db_path = match app_handle + .path() + .resolve(db_path, tauri::path::BaseDirectory::Home) + { + Ok(resolved_knowledgebase_path) => resolved_knowledgebase_path, + + Err(_) => return Err(()), + }; + let unicode_db_path = &resolved_db_path.to_string_lossy().to_owned(); + } + Err(()) +} #[tauri::command] -pub async fn initialize_database( - app_handle: tauri::AppHandle, - basepath: String, - pathtemplate: String, -) { +pub async fn initialize_database(app_handle: tauri::AppHandle) { if let Some(basepath) = get_basepath(app_handle.clone()) { let db_path = Path::new("Documents") .join(Path::new("Knowledgebase")) @@ -57,6 +71,7 @@ pub async fn initialize_database( id INTEGER NOT NULL, client_id INTEGER NOT NULL, diff_text TEXT NOT NULL, + working_diff BOOLEAN, FOREIGN KEY (id) REFERENCES files (file_id) PRIMARY KEY (id, client_id) @@ -70,6 +85,6 @@ pub async fn initialize_database( } #[tauri::command] -async fn store_diff(diff: String) {} +async fn store_diff(file_path: String, file_name: String, diff: String) {} async fn add_file(file_path: String, file_name: String) {}