Skip to content

Commit

Permalink
fix: use owned Builder pattern for ConnectOptions (launchbadge#2132)
Browse files Browse the repository at this point in the history
* CHANGELOG: mention that users should upgrade CLI

* fix(sqlx-core): use owned builder pattern for ConnectOptions

---------

Co-authored-by: Austin Bonander <[email protected]>
  • Loading branch information
2 people authored and Aandreba committed Mar 31, 2023
1 parent 91a5110 commit 881063f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions sqlx-core/src/any/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ impl ConnectOptions for AnyConnectOptions {
Box::pin(AnyConnection::establish(self))
}

fn log_statements(&mut self, level: LevelFilter) -> &mut Self {
fn log_statements(mut self, level: LevelFilter) -> Self {
self.log_settings.statements_level = level;
self
}

fn log_slow_statements(&mut self, level: LevelFilter, duration: Duration) -> &mut Self {
fn log_slow_statements(mut self, level: LevelFilter, duration: Duration) -> Self {
self.log_settings.slow_statements_level = level;
self.log_settings.slow_statements_duration = duration;
self
Expand Down
6 changes: 3 additions & 3 deletions sqlx-core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ pub trait ConnectOptions: 'static + Send + Sync + FromStr<Err = Error> + Debug +
Self::Connection: Sized;

/// Log executed statements with the specified `level`
fn log_statements(&mut self, level: LevelFilter) -> &mut Self;
fn log_statements(self, level: LevelFilter) -> Self;

/// Log executed statements with a duration above the specified `duration`
/// at the specified `level`.
fn log_slow_statements(&mut self, level: LevelFilter, duration: Duration) -> &mut Self;
fn log_slow_statements(self, level: LevelFilter, duration: Duration) -> Self;

/// Entirely disables statement logging (both slow and regular).
fn disable_statement_logging(&mut self) -> &mut Self {
fn disable_statement_logging(self) -> Self {
self.log_statements(LevelFilter::Off)
.log_slow_statements(LevelFilter::Off, Duration::default())
}
Expand Down
4 changes: 2 additions & 2 deletions sqlx-mysql/src/options/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ impl ConnectOptions for MySqlConnectOptions {
})
}

fn log_statements(&mut self, level: LevelFilter) -> &mut Self {
fn log_statements(mut self, level: LevelFilter) -> Self {
self.log_settings.log_statements(level);
self
}

fn log_slow_statements(&mut self, level: LevelFilter, duration: Duration) -> &mut Self {
fn log_slow_statements(mut self, level: LevelFilter, duration: Duration) -> Self {
self.log_settings.log_slow_statements(level, duration);
self
}
Expand Down
4 changes: 2 additions & 2 deletions sqlx-postgres/src/options/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ impl ConnectOptions for PgConnectOptions {
Box::pin(PgConnection::establish(self))
}

fn log_statements(&mut self, level: LevelFilter) -> &mut Self {
fn log_statements(mut self, level: LevelFilter) -> Self {
self.log_settings.log_statements(level);
self
}

fn log_slow_statements(&mut self, level: LevelFilter, duration: Duration) -> &mut Self {
fn log_slow_statements(mut self, level: LevelFilter, duration: Duration) -> Self {
self.log_settings.log_slow_statements(level, duration);
self
}
Expand Down
4 changes: 2 additions & 2 deletions sqlx-sqlite/src/options/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ impl ConnectOptions for SqliteConnectOptions {
})
}

fn log_statements(&mut self, level: LevelFilter) -> &mut Self {
fn log_statements(mut self, level: LevelFilter) -> Self {
self.log_settings.log_statements(level);
self
}

fn log_slow_statements(&mut self, level: LevelFilter, duration: Duration) -> &mut Self {
fn log_slow_statements(mut self, level: LevelFilter, duration: Duration) -> Self {
self.log_settings.log_slow_statements(level, duration);
self
}
Expand Down

0 comments on commit 881063f

Please sign in to comment.