Skip to content

Commit

Permalink
better way to override search_path
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <cywolf@gmail.com>
  • Loading branch information
andrewwhitehead committed Sep 14, 2023
1 parent 67db269 commit c24d491
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions askar-storage/src/backend/postgres/provision.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::borrow::Cow;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;

use sqlx::{
Expand Down Expand Up @@ -126,28 +125,18 @@ impl PostgresStoreOptions {
{
conn_opts = conn_opts
.log_statements(log::LevelFilter::Debug)
.log_slow_statements(log::LevelFilter::Debug, Default::default())
.log_slow_statements(log::LevelFilter::Debug, Default::default());
}
let set_params = self
.schema
.as_ref()
if let Some(s) = self.schema.as_ref() {
// NB: schema is a validated identifier
.map(|s| Arc::new(format!(r#"SET search_path = "{}""#, s)));
conn_opts = conn_opts.options([("search_path", s)]);
}
PgPoolOptions::default()
.acquire_timeout(self.connect_timeout)
.idle_timeout(self.idle_timeout)
.max_connections(self.max_connections)
.min_connections(self.min_connections)
.test_before_acquire(false)
.after_connect(move |conn, _meta| {
let set_params = set_params.clone();
Box::pin(async move {
if let Some(stmt) = set_params.as_ref() {
conn.execute(stmt.as_str()).await?;
}
Ok(())
})
})
.connect_with(conn_opts)
.await
}
Expand Down

0 comments on commit c24d491

Please sign in to comment.