feat(sql): improved sqlite load path

pull/2487/head
w33d 5 months ago
parent 1ac32b8be9
commit 058df10590

@ -68,17 +68,11 @@ export default class Database {
* *
* # Sqlite * # Sqlite
* *
* The path is relative to `tauri::path::BaseDirectory::App` by default and must start with `sqlite:`. * The path is relative to `tauri::path::BaseDirectory::App` and must start with `sqlite:`.
* *
* @example * @example
* ```ts * ```ts
* // for relative path * const db = Database.get("sqlite:test.db");
* const db = await Database.get("sqlite:test.db");
* ```
* @example
* ```ts
* // for absolute path
* const db = await Database.get("sqlite:/home/ubuntu/test.db");
* ``` * ```
*/ */
static get(path: string): Database { static get(path: string): Database {

@ -4,7 +4,6 @@
#[cfg(feature = "sqlite")] #[cfg(feature = "sqlite")]
use std::fs::create_dir_all; use std::fs::create_dir_all;
use std::path::Path;
use indexmap::IndexMap; use indexmap::IndexMap;
use serde_json::Value as JsonValue; use serde_json::Value as JsonValue;
@ -77,7 +76,7 @@ impl DbPool {
{ {
#[cfg(feature = "sqlite")] #[cfg(feature = "sqlite")]
"sqlite" => { "sqlite" => {
let conn_url = if Path::new(conn_url).is_absolute() { let conn_url = if std::path::Path::new(conn_url).is_absolute() {
create_dir_all(conn_url).expect("Couldn't create dir"); create_dir_all(conn_url).expect("Couldn't create dir");
conn_url conn_url

Loading…
Cancel
Save