fixed diff db
This commit is contained in:
parent
3951f91901
commit
b38d0cc149
2 changed files with 23 additions and 25 deletions
|
|
@ -6,8 +6,9 @@ use std::{
|
|||
};
|
||||
|
||||
use crate::{config::_get_client_id, get_basepath};
|
||||
use futures::FutureExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool};
|
||||
use sqlx::{migrate::MigrateDatabase, sqlite::SqliteConnectOptions, Sqlite, SqlitePool};
|
||||
use tauri::{ipc::RuntimeCapability, App, AssetResolver, Manager, Url};
|
||||
|
||||
struct DBFileEntry {
|
||||
|
|
@ -76,17 +77,18 @@ pub async fn initialize_database(app_handle: tauri::AppHandle) -> Result<(), DBE
|
|||
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)
|
||||
)
|
||||
;",
|
||||
)
|
||||
.execute(&db)
|
||||
.await
|
||||
.map_err(|e| DBError::DatabaseQueryError(e.to_string()))?;
|
||||
.unwrap();
|
||||
// .map_err(|e| DBError::DatabaseQueryError(e.to_string()))?;
|
||||
db.close().await;
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -195,6 +197,7 @@ pub async fn store_diff(
|
|||
// FOREIGN KEY (id)
|
||||
// REFERENCES files (file_id)
|
||||
// PRIMARY KEY (id, client_id)
|
||||
let file_id = get_file_id(app_handle, relative_file_path, file_name).await?;
|
||||
let _ = sqlx::query(&format!(
|
||||
"
|
||||
UPDATE file_diffs
|
||||
|
|
@ -210,23 +213,9 @@ pub async fn store_diff(
|
|||
let _ = sqlx::query(&format!(
|
||||
"
|
||||
INSERT INTO
|
||||
file_diffs (client_id, diff_text, current_diff, file_diffs, file_id)
|
||||
file_diffs (client_id, diff_text, current_diff, file_id)
|
||||
VALUES
|
||||
('{client_id}', '{diff}', 1, (
|
||||
SELECT id
|
||||
FROM file_diffs
|
||||
WHERE relative_path IS '{relative_file_path}'
|
||||
AND file_name IS '{file_name}'
|
||||
AND current_diff is 1
|
||||
LIMIT 1
|
||||
),
|
||||
(
|
||||
SELECT id
|
||||
FROM files
|
||||
WHERE relative_path IS '{relative_file_path}'
|
||||
AND file_name IS '{file_name}'
|
||||
LIMIT 1
|
||||
));"
|
||||
('{client_id}', '{diff}', 1, );"
|
||||
))
|
||||
.execute(&db)
|
||||
.await
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue