database connection working
This commit is contained in:
parent
c14cd954a2
commit
3a98a86d46
8 changed files with 394 additions and 455 deletions
766
src-tauri/Cargo.lock
generated
766
src-tauri/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -28,4 +28,4 @@ tauri-plugin-log = "2"
|
|||
shellexpand = "3.1.0"
|
||||
html_tag = "0.1.3"
|
||||
fuzzy-matcher = "0.3"
|
||||
sqlx = { version = "0.8", features = ["sqlite"] }
|
||||
sqlx = { version = "0.6.2", features = ["runtime-tokio-native-tls", "sqlite"] }
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@ mod file_tree;
|
|||
mod markdown_parser;
|
||||
mod search;
|
||||
use std::env;
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_fs::FsExt;
|
||||
|
||||
use database::initialize_database;
|
||||
use file_tree::dir_tree_html;
|
||||
use markdown_parser::parse_markdown;
|
||||
use search::search_files;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use comrak::{format_html, nodes::NodeValue, parse_document, Arena, Options};
|
||||
use std::{
|
||||
env,
|
||||
|
||||
path::{absolute, Path},
|
||||
};
|
||||
#[tauri::command]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue