Skip to content

Commit

Permalink
fix: use owned Builder pattern for ConnectOptions (#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 <austin.bonander@gmail.com>
  • Loading branch information
ar3s3ru and abonander committed Feb 21, 2023
1 parent c095328 commit b72a52b
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 b72a52b

Please sign in to comment.