Skip to content

Commit 3920eb8

Browse files
cursoragentlovasoa
andcommitted
Checkpoint before follow-up message
Co-authored-by: contact <[email protected]>
1 parent 55bd11a commit 3920eb8

File tree

6 files changed

+26
-31
lines changed

6 files changed

+26
-31
lines changed

sqlx-core/src/connection.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub trait Connection: Send {
119119
{
120120
let options = url.parse();
121121

122-
Box::pin(async move { Ok(Self::connect_with(&options?).await?) })
122+
Box::pin(async move { Self::connect_with(&options?).await })
123123
}
124124

125125
/// Establish a new database connection with the provided options.
@@ -158,24 +158,22 @@ impl LogSettings {
158158
}
159159
}
160160

161-
pub trait ConnectOptions: 'static + Send + Sync + FromStr<Err = Error> + Debug + Clone {
162-
type Connection: Connection + ?Sized;
161+
pub trait ConnectOptions: Sized + Send + Sync + 'static {
162+
type Connection: Connection;
163163

164-
/// Establish a new database connection with the options specified by `self`.
165-
fn connect(&self) -> BoxFuture<'_, Result<Self::Connection, Error>>
166-
where
167-
Self::Connection: Sized;
164+
fn from_url(url: &str) -> Result<Self, Error>;
168165

169-
/// Log executed statements with the specified `level`
170-
fn log_statements(&mut self, level: LevelFilter) -> &mut Self;
166+
fn connect(&self) -> BoxFuture<'_, Result<Self::Connection, Error>>;
171167

172-
/// Log executed statements with a duration above the specified `duration`
173-
/// at the specified `level`.
174-
fn log_slow_statements(&mut self, level: LevelFilter, duration: Duration) -> &mut Self;
168+
fn connect_with(options: &Self) -> BoxFuture<'_, Result<Self::Connection, Error>>;
175169

176-
/// Entirely disables statement logging (both slow and regular).
177-
fn disable_statement_logging(&mut self) -> &mut Self {
178-
self.log_statements(LevelFilter::Off)
179-
.log_slow_statements(LevelFilter::Off, Duration::default())
170+
fn from_env() -> Result<Self, Error> {
171+
let options = Self::from_url(&std::env::var("DATABASE_URL")?)?;
172+
Box::pin(async move { Self::connect_with(&options?).await })
180173
}
174+
175+
fn create_pool(
176+
&self,
177+
options: crate::pool::PoolOptions<Self::Connection>,
178+
) -> Result<crate::pool::Pool<Self::Connection>, Error>;
181179
}

sqlx-core/src/logger.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,13 @@ impl<'q, O: Debug + Hash + Eq, R: Debug, P: Debug> QueryPlanLogger<'q, O, R, P>
9999
}
100100

101101
pub(crate) fn log_enabled(&self) -> bool {
102-
if let Some(_lvl) = self
103-
.settings
104-
.statements_level
105-
.to_level()
106-
.filter(|lvl| log::log_enabled!(target: "sqlx::explain", *lvl))
107-
{
108-
true
109-
} else {
110-
false
111-
}
102+
matches!(
103+
self.settings
104+
.statements_level
105+
.to_level()
106+
.filter(|lvl| log::log_enabled!(target: "sqlx::explain", *lvl)),
107+
Some(_)
108+
)
112109
}
113110

114111
pub(crate) fn add_result(&mut self, result: R) {

sqlx-core/src/mssql/connection/establish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl MssqlConnection {
7272
server_name: &options.server_name,
7373
client_interface_name: &options.client_interface_name,
7474
language: &options.language,
75-
database: &*options.database,
75+
database: &options.database,
7676
client_id: [0; 6],
7777
};
7878

sqlx-core/src/mssql/connection/prepare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) async fn prepare(
2828

2929
for m in PARAMS_RE.captures_iter(sql) {
3030
if !params.is_empty() {
31-
params.push_str(",");
31+
params.push(',');
3232
}
3333

3434
params.push_str(&m[0]);

sqlx-core/src/pool/inner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,14 @@ impl<DB: Database> Drop for PoolInner<DB> {
406406
fn is_beyond_max_lifetime<DB: Database>(live: &Live<DB>, options: &PoolOptions<DB>) -> bool {
407407
options
408408
.max_lifetime
409-
.map_or(false, |max| live.created_at.elapsed() > max)
409+
.is_some_and(|max| live.created_at.elapsed() > max)
410410
}
411411

412412
/// Returns `true` if the connection has exceeded `options.idle_timeout` if set, `false` otherwise.
413413
fn is_beyond_idle_timeout<DB: Database>(idle: &Idle<DB>, options: &PoolOptions<DB>) -> bool {
414414
options
415415
.idle_timeout
416-
.map_or(false, |timeout| idle.idle_since.elapsed() > timeout)
416+
.is_some_and(|timeout| idle.idle_since.elapsed() > timeout)
417417
}
418418

419419
async fn check_idle_conn<DB: Database>(

sqlx-core/src/pool/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl<DB: Database> Pool<DB> {
353353

354354
/// Retrieves a connection and immediately begins a new transaction.
355355
pub async fn begin(&self) -> Result<Transaction<'static, DB>, Error> {
356-
Ok(Transaction::begin(MaybePoolConnection::PoolConnection(self.acquire().await?)).await?)
356+
Transaction::begin(MaybePoolConnection::PoolConnection(self.acquire().await?)).await
357357
}
358358

359359
/// Attempts to retrieve a connection and immediately begins a new transaction if successful.

0 commit comments

Comments
 (0)