feat(sql): add autoCreate option to Database.load (#3702)

* feat(sql): add autoCreate option to Database.load

Add utoCreate option to Database.load allowing users to disable implicit database creation when loading a database.

Closes #299

* fix(sql): fix unused variable without a database feature

* refactor(sql): share the database existence check between drivers

* fix(sql): don't report a failed existence check as a missing database

* fix(sql): name the database as passed, without password, in the missing database error

* fix(sql): don't create the app config dir when autoCreate is false

* refactor(sql): use the LoadOptions default for missing options

* test(sql): cover autoCreate and password redaction

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
kxrn_guptaandLucas Nogueira authored and GitHub committed 2026-10-12 10:46:00 -03:00
1 parent 0374bec1e2
commit c91a9e6af5
7 files changed
+151 -19

No files matched your search

+15 -1
View File
@@ -9,14 +9,28 @@ use tauri::{AppHandle, Runtime, State, command};
use crate::{DbInstances, DbPool, Error, LastInsertId, Migrations};
#[derive(Debug, Clone, Copy, serde::Deserialize)]
#[serde(rename_all = "camelCase", default)]
pub(crate) struct LoadOptions {
pub auto_create: bool,
}
impl Default for LoadOptions {
fn default() -> Self {
Self { auto_create: true }
}
}
#[command]
pub(crate) async fn load<R: Runtime>(
app: AppHandle<R>,
db_instances: State<'_, DbInstances>,
migrations: State<'_, Migrations>,
db: String,
options: Option<LoadOptions>,
) -> Result<String, crate::Error> {
let pool = DbPool::connect(&db, &app).await?;
let options = options.unwrap_or_default();
let pool = DbPool::connect(&db, &app, options.auto_create).await?;
if let Some(migrations) = migrations.0.lock().await.remove(&db) {
let migrator = Migrator::new(migrations).await?;