Skip to content

Commit

Permalink
Merge pull request prisma#1 from prisma/feat/search-path-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky authored Apr 5, 2023
2 parents 74f0847 + 614e66c commit 00d4815
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tokio-postgres/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pub struct Config {
pub(crate) target_session_attrs: TargetSessionAttrs,
pub(crate) channel_binding: ChannelBinding,
pub(crate) pgbouncer_mode: bool,
pub(crate) search_path: Option<String>,
}

impl Default for Config {
Expand Down Expand Up @@ -196,6 +197,7 @@ impl Config {
target_session_attrs: TargetSessionAttrs::Any,
channel_binding: ChannelBinding::Prefer,
pgbouncer_mode: false,
search_path: None,
}
}

Expand Down Expand Up @@ -441,6 +443,17 @@ impl Config {
self.pgbouncer_mode
}

/// Sets the search_path.
pub fn search_path(&mut self, search_path: String) -> &mut Config {
self.search_path = Some(search_path);
self
}

/// Gets the search path.
pub fn get_search_path(&self) -> Option<&String> {
self.search_path.as_ref()
}

fn param(&mut self, key: &str, value: &str) -> Result<(), Error> {
match key {
"user" => {
Expand Down
4 changes: 4 additions & 0 deletions tokio-postgres/src/connect_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ where
params.push(("application_name", &**application_name));
}

if let Some(schema_path) = &config.search_path {
params.push(("search_path", &**schema_path));
}

let mut buf = BytesMut::new();
frontend::startup_message(params, &mut buf).map_err(Error::encode)?;

Expand Down

0 comments on commit 00d4815

Please sign in to comment.