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 authored Feb 11, 2023
1 parent 5e8fff1 commit 5f26e72
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [[#2057]]: Make begin,commit,rollback cancel-safe in sqlite [[@madadam]]
* [[#2058]]: fix typo in documentation [[@lovasoa]]
* [[#2067]]: fix(docs): close code block in query_builder.rs [[@abonander]]
* [[#2069]]: Fix `prepare` race condition in workspaces [[@cycraig]]
* [[#2069]]: Fix `prepare` race condition in workspaces [[@cycraig]]\
* NOTE: this changes the directory structure under `target/` that `cargo sqlx prepare` depends on.
If you use offline mode in your workflow, please rerun `cargo install sqlx-cli` to upgrade.
* [[#2072]]: SqliteConnectOptions typo [[@fasterthanlime]]
* [[#2074]]: fix: mssql uses unsigned for tinyint instead of signed [[@he4d]]
* [[#2081]]: close unnamed portal after each executed extended query [[@DXist]]
Expand Down
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 5f26e72

Please sign in to comment.