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

fix: use owned Builder pattern for ConnectOptions #2132

Merged
merged 4 commits into from
Feb 11, 2023
Merged
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
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