Skip to content

Commit 7ca825d

Browse files
committed
Add set_options()
1 parent 49d9a38 commit 7ca825d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

plugins/sql/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ fn run_async_command<F: std::future::Future>(cmd: F) -> F::Output {
118118
#[derive(Default)]
119119
pub struct Builder {
120120
migrations: Option<HashMap<String, MigrationList>>,
121+
options: Option<HashMap<String, ConnectionOptions>>,
121122
}
122123

123124
impl Builder {
@@ -137,6 +138,15 @@ impl Builder {
137138
self
138139
}
139140

141+
/// Set database options.
142+
#[must_use]
143+
pub fn set_options(mut self, db_url: &str, connection_options: ConnectionOptions) -> Self {
144+
self.options
145+
.get_or_insert(Default::default())
146+
.insert(db_url.to_string(), connection_options);
147+
self
148+
}
149+
140150
pub fn build<R: Runtime>(mut self) -> TauriPlugin<R, Option<PluginConfig>> {
141151
PluginBuilder::<R, Option<PluginConfig>>::new("sql")
142152
.invoke_handler(tauri::generate_handler![
@@ -153,7 +163,7 @@ impl Builder {
153163
let mut lock = instances.0.write().await;
154164

155165
for db in config.preload {
156-
let pool = DbPool::connect(&db, app, None).await?;
166+
let pool = DbPool::connect(&db, app, self.options.as_mut().and_then(|mm| mm.remove(&db))).await?;
157167

158168
if let Some(migrations) =
159169
self.migrations.as_mut().and_then(|mm| mm.remove(&db))

plugins/sql/src/wrapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use serde_json::Value as JsonValue;
1212
#[cfg(feature = "sqlite")]
1313
use sqlx::sqlite::SqliteConnectOptions;
1414
#[cfg(any(feature = "sqlite", feature = "mysql", feature = "postgres"))]
15-
use sqlx::{migrate::MigrateDatabase, Column, Executor, Pool, Row};
15+
use sqlx::{Column, Executor, Pool, Row};
1616
#[cfg(any(feature = "sqlite", feature = "mysql", feature = "postgres"))]
1717
use tauri::Manager;
1818
use tauri::{AppHandle, Runtime};

0 commit comments

Comments
 (0)