zwischenstand

This commit is contained in:
2025-07-10 10:07:29 +02:00
parent 63f6e2d32f
commit 41472e02ad
28 changed files with 818 additions and 209 deletions

View File

@ -6,8 +6,8 @@ use rusqlite::{
Connection, OpenFlags, ToSql,
};
use serde_json::Value as JsonValue;
use std::fs;
use std::path::Path;
use std::{fs, path::PathBuf};
use tauri::State;
// --- Hilfsfunktion: Konvertiert JSON Value zu etwas, das rusqlite versteht ---
// Diese Funktion ist etwas knifflig wegen Ownership und Lifetimes.
@ -168,7 +168,13 @@ pub fn open_and_init_db(path: &str, key: &str, create: bool) -> Result<Connectio
OpenFlags::SQLITE_OPEN_READ_WRITE
};
let conn = Connection::open_with_flags(path, flags).map_err(|e| e.to_string())?;
let conn = Connection::open_with_flags(path, flags).map_err(|e| {
format!(
"Dateiii gibt es nicht: {}. Habe nach {} gesucht",
e.to_string(),
path
)
})?;
conn.pragma_update(None, "key", key)
.map_err(|e| e.to_string())?;

View File

@ -3,6 +3,7 @@ pub mod core;
use rusqlite::Connection;
use serde_json::Value as JsonValue;
use std::fs;
use std::path::{Path, PathBuf};
use std::str::FromStr;
@ -58,9 +59,14 @@ pub fn create_encrypted_database(
app_handle.path().resource_dir()
);
/* let resource_path = app_handle
.path()
.resolve("database/vault.db", BaseDirectory::Resource)
.map_err(|e| format!("Fehler beim Auflösen des Ressourcenpfads: {}", e))?; */
let resource_path = app_handle
.path()
.resolve("database/vault.db", BaseDirectory::Resource)
.resolve("temp_vault.db", BaseDirectory::AppLocalData)
.map_err(|e| format!("Fehler beim Auflösen des Ressourcenpfads: {}", e))?;
// Prüfen, ob die Ressourcendatei existiert
@ -72,12 +78,16 @@ pub fn create_encrypted_database(
}
// Sicherstellen, dass das Zielverzeichnis existiert
if let Some(parent) = Path::new(&path).parent() {
/* if let Some(parent) = Path::new(&path).parent() {
if !parent.exists() {
std::fs::create_dir_all(parent)
.map_err(|e| format!("Fehler beim Erstellen des Zielverzeichnisses: {}", e))?;
std::fs::create_dir_all(parent).map_err(|e| {
format!(
"Fehler beim Erstellen des Zielverzeichnisses: {}\n mit Fehler {}",
path, e
)
})?;
}
}
} */
let target = Path::new(&path);
if target.exists() & target.is_file() {
@ -167,14 +177,23 @@ pub fn create_encrypted_database(
Ok(format!("Verschlüsselte CRDT-Datenbank erstellt",))
}
use tauri_plugin_dialog::{Dialog, DialogExt, MessageDialogKind};
#[tauri::command]
pub fn open_encrypted_database(
app_handle: AppHandle,
path: String,
key: String,
state: State<'_, DbConnection>,
) -> Result<String, String> {
/* let vault_path = app_handle
.path()
.resolve(format!("vaults/{}", path), BaseDirectory::AppLocalData)
.map_err(|e| format!("Fehler {}", e))?
.into_os_string()
.into_string()
.unwrap(); */
if !std::path::Path::new(&path).exists() {
return Err("File not found ".into());
return Err(format!("File not found {}", path).into());
}
let conn =

View File

@ -1,63 +0,0 @@
// src-tauri/src/sql_proxy.rs
use rusqlite::Connection;
use sqlparser::ast::Statement;
use sqlparser::dialect::SQLiteDialect;
use sqlparser::parser::Parser;
use std::sync::{Arc, Mutex};
// Der Schema-Cache wird später benötigt, um zu wissen, welche Tabellen eine 'tombstone'-Spalte haben.
// Für den Anfang lassen wir ihn leer.
pub struct SchemaCache {
// TODO: z.B. HashMap<String, Vec<String>> für Tabellen und ihre Spalten
}
impl SchemaCache {
pub fn new() -> Self {
Self {}
}
// TODO: Methoden zum Befüllen und Abfragen des Caches
}
// Die Hauptstruktur unseres Proxys
pub struct SqlProxy {
// Wir benötigen eine threadsichere Referenz auf den Schema-Cache
schema_cache: Arc<Mutex<SchemaCache>>,
}
impl SqlProxy {
pub fn new(schema_cache: Arc<Mutex<SchemaCache>>) -> Self {
Self { schema_cache }
}
// Die zentrale Ausführungsfunktion
pub fn execute(&self, sql: &str, conn: &Connection) -> Result<(), String> {
// 1. Parsen des SQL-Strings in einen AST
let dialect = SQLiteDialect {};
let mut ast =
Parser::parse_sql(&dialect, sql).map_err(|e| format!("SQL-Parse-Fehler: {}", e))?;
// Sicherstellen, dass wir nur eine Anweisung haben
if ast.len() != 1 {
return Err("Nur einzelne SQL-Anweisungen werden unterstützt.".to_string());
}
let statement = &mut ast;
// 2. Umschreiben des AST (Logik folgt in Abschnitt 2)
self.transform_statement(statement)?;
// 3. Ausführen der (möglicherweise modifizierten) Anweisung
let final_sql = statement.to_string();
conn.execute(&final_sql)
.map_err(|e| format!("DB-Ausführungsfehler: {}", e))?;
Ok(())
}
// Platzhalter für die Transformationslogik
fn transform_statement(&self, statement: &mut Statement) -> Result<(), String> {
// HIER KOMMT DIE MAGIE HIN
// TODO: Implementierung der `CREATE TABLE`, `DELETE` und `SELECT` Transformationen
Ok(())
}
}