made db work on relative paths

This commit is contained in:
Iaphetes 2025-05-22 21:32:36 +02:00
parent b38d0cc149
commit 5ef9f17436
8 changed files with 74 additions and 23 deletions

View file

@ -187,17 +187,28 @@ pub async fn store_diff(
// 1 insert into file_diffs with parent
// 2 make last diff not currennt diff
//
// id INTEGER NOT NULL,
// client_id TEXT NOT NULL,
// diff_text TEXT NOT NULL,
// current_diff BOOLEAN,
// FOREIGN KEY (id)
// REFERENCES file_diffs (parent_diff_id)
// FOREIGN KEY (id)
// REFERENCES files (file_id)
// parent_diff_id INTEGER,
// file_id INTEGER,
// FOREIGN KEY (parent_diff_id) REFERENCES file_diffs(id),
// FOREIGN KEY (file_id) REFERENCES files(id),
// PRIMARY KEY (id, client_id)
let file_id = get_file_id(app_handle, relative_file_path, file_name).await?;
let parent_diff_id: i32 = sqlx::query_scalar(&format!(
"
SELECT id from file_diffs
WHERE relative_path IS '{relative_file_path}'
AND file_name IS '{file_name}'
AND working_diff is 1
"
))
.fetch_one(&db)
.await
.unwrap_or(0);
let _ = sqlx::query(&format!(
"
UPDATE file_diffs
@ -209,13 +220,13 @@ pub async fn store_diff(
))
.execute(&db)
.await
.map_err(|e| DBError::DatabaseQueryError(e.to_string()))?;
.map_err(|e| DBError::DatabaseQueryError(e.to_string()));
let _ = sqlx::query(&format!(
"
INSERT INTO
file_diffs (client_id, diff_text, current_diff, file_id)
VALUES
('{client_id}', '{diff}', 1, );"
('{client_id}', '{diff}', 1, {parent_diff_id});"
))
.execute(&db)
.await