table init for diffs done
This commit is contained in:
parent
3a98a86d46
commit
75d172fc3f
1 changed files with 32 additions and 8 deletions
|
|
@ -4,7 +4,7 @@ use std::{
|
|||
path::Path,
|
||||
};
|
||||
|
||||
use sqlx::{migrate::MigrateDatabase, Sqlite};
|
||||
use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool};
|
||||
use tauri::{ipc::RuntimeCapability, App, AssetResolver, Manager, Url};
|
||||
|
||||
#[tauri::command]
|
||||
|
|
@ -26,22 +26,46 @@ pub async fn initialize_database(
|
|||
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
if !Sqlite::database_exists(&resolved_db_path.to_string_lossy().to_owned())
|
||||
let unicode_db_path = &resolved_db_path.to_string_lossy().to_owned();
|
||||
if !Sqlite::database_exists(&unicode_db_path)
|
||||
.await
|
||||
.unwrap_or(false)
|
||||
{
|
||||
println!(
|
||||
"Creating database {}",
|
||||
resolved_db_path.to_string_lossy().to_owned()
|
||||
);
|
||||
match Sqlite::create_database(&resolved_db_path.to_string_lossy().to_owned()).await {
|
||||
println!("Creating database {}", unicode_db_path);
|
||||
match Sqlite::create_database(&unicode_db_path).await {
|
||||
Ok(_) => println!("Create db success"),
|
||||
Err(error) => panic!("error: {}", error),
|
||||
}
|
||||
} else {
|
||||
println!("Database already exists");
|
||||
}
|
||||
let db = SqlitePool::connect(unicode_db_path).await.unwrap();
|
||||
let result = sqlx::query(
|
||||
"CREATE TABLE IF NOT EXISTS files
|
||||
(
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
relative_path TEXT NOT NULL
|
||||
);",
|
||||
)
|
||||
.execute(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("Create file table result: {:?}", result);
|
||||
let result = sqlx::query(
|
||||
"CREATE TABLE IF NOT EXISTS file_diffs
|
||||
(
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
diff_text TEXT NOT NULL,
|
||||
FOREIGN KEY (id)
|
||||
REFERENCES files (file_id)
|
||||
)
|
||||
;",
|
||||
)
|
||||
.execute(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
println!("Create diff table result: {:?}", result);
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue