Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move extra_float_digits parameter to PgConnectOptions #1746

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions sqlx-core/src/postgres/connection/establish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl PgConnection {
// Sets the time zone for displaying and interpreting time stamps.
("TimeZone", "UTC"),
// Adjust postgres to return precise values for floats
// NOTE: This is default in postgres 12+
("extra_float_digits", "3"),
("extra_float_digits", options.extra_float_digits.as_str()),
];

if let Some(ref application_name) = options.application_name {
Expand Down
17 changes: 17 additions & 0 deletions sqlx-core/src/postgres/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub struct PgConnectOptions {
pub(crate) application_name: Option<String>,
pub(crate) log_settings: LogSettings,
pub(crate) options: Option<String>,
pub(crate) extra_float_digits: String,
}

impl Default for PgConnectOptions {
Expand Down Expand Up @@ -149,6 +150,8 @@ impl PgConnectOptions {
application_name: var("PGAPPNAME").ok(),
log_settings: Default::default(),
options: var("PGOPTIONS").ok(),
// NOTE: This is default in postgres 12+
extra_float_digits: "3".to_owned(),
}
}

Expand Down Expand Up @@ -378,6 +381,20 @@ impl PgConnectOptions {
_ => None,
}
}

/// Sets the extra float digits. Defaults to 3
///
/// # Example
///
/// ```rust
/// # use sqlx_core::postgres::PgConnectOptions;
/// let options = PgConnectOptions::new()
/// .extra_float_digits("2");
/// ```
pub fn extra_float_digits(mut self, extra_float_digits: &str) -> Self {
self.extra_float_digits = extra_float_digits.to_owned();
self
}
}

fn default_host(port: u16) -> String {
Expand Down