database connection working
This commit is contained in:
parent
c14cd954a2
commit
3a98a86d46
8 changed files with 394 additions and 455 deletions
|
|
@ -1,11 +1,41 @@
|
|||
use std::{
|
||||
fs::File,
|
||||
io::{Error, Read, Result},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use sqlx::{migrate::MigrateDatabase, Sqlite};
|
||||
use tauri::{ipc::RuntimeCapability, App, AssetResolver, Manager, Url};
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn initialize_database(basepath: String) {
|
||||
let db_url: &str = &format!("sqlite://{}/sqlite.db", basepath);
|
||||
if !Sqlite::database_exists(db_url).await.unwrap_or(false) {
|
||||
println!("Creating database {}", db_url);
|
||||
match Sqlite::create_database(db_url).await {
|
||||
pub async fn initialize_database(
|
||||
app_handle: tauri::AppHandle,
|
||||
basepath: String,
|
||||
pathtemplate: String,
|
||||
) {
|
||||
println!("hello");
|
||||
let db_path = Path::new("Documents")
|
||||
.join(Path::new("Knowledgebase"))
|
||||
.join("db.sqlite");
|
||||
|
||||
let resolved_db_path = match app_handle
|
||||
.path()
|
||||
.resolve(db_path, tauri::path::BaseDirectory::Home)
|
||||
{
|
||||
Ok(resolved_knowledgebase_path) => resolved_knowledgebase_path,
|
||||
|
||||
Err(_) => return,
|
||||
};
|
||||
|
||||
if !Sqlite::database_exists(&resolved_db_path.to_string_lossy().to_owned())
|
||||
.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 {
|
||||
Ok(_) => println!("Create db success"),
|
||||
Err(error) => panic!("error: {}", error),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue