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,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use sqlx::{migrate::MigrateDatabase, Sqlite};
|
use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool};
|
||||||
use tauri::{ipc::RuntimeCapability, App, AssetResolver, Manager, Url};
|
use tauri::{ipc::RuntimeCapability, App, AssetResolver, Manager, Url};
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
|
@ -26,22 +26,46 @@ pub async fn initialize_database(
|
||||||
|
|
||||||
Err(_) => return,
|
Err(_) => return,
|
||||||
};
|
};
|
||||||
|
let unicode_db_path = &resolved_db_path.to_string_lossy().to_owned();
|
||||||
if !Sqlite::database_exists(&resolved_db_path.to_string_lossy().to_owned())
|
if !Sqlite::database_exists(&unicode_db_path)
|
||||||
.await
|
.await
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
println!(
|
println!("Creating database {}", unicode_db_path);
|
||||||
"Creating database {}",
|
match Sqlite::create_database(&unicode_db_path).await {
|
||||||
resolved_db_path.to_string_lossy().to_owned()
|
|
||||||
);
|
|
||||||
match Sqlite::create_database(&resolved_db_path.to_string_lossy().to_owned()).await {
|
|
||||||
Ok(_) => println!("Create db success"),
|
Ok(_) => println!("Create db success"),
|
||||||
Err(error) => panic!("error: {}", error),
|
Err(error) => panic!("error: {}", error),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("Database already exists");
|
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]
|
#[tauri::command]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue