Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c0686ef
Refactor: Improve type conversions and clippy lints
cursoragent Sep 16, 2025
9ca44d6
Fix: Improve SQLite type conversions and pool handling
cursoragent Sep 16, 2025
93237ec
Fix: Replace unwrap with expect for error handling
cursoragent Sep 16, 2025
c56e7b4
core: remove extraneous clippy allows in lib.rs
cursoragent Sep 16, 2025
3dbabb1
sqlite: remove clippy allows; switch columns Vec->slice; simplify wil…
cursoragent Sep 16, 2025
706523d
sqlite/mysql: fix clippy warnings (needless borrows, ptr_arg, casts, …
cursoragent Sep 16, 2025
198b125
postgres: fix clippy lints (casts, needless borrows, docs, len checks…
cursoragent Sep 16, 2025
cbfe331
sqlite: re-allow unsafe_code for FFI; fix Pg options path AsRef deref
cursoragent Sep 16, 2025
17c8274
api: fix multiple-bound-locations by separating lifetimes; rt-async-s…
cursoragent Sep 16, 2025
6893425
Fix: Add missing lifetime bounds to Executor trait
cursoragent Sep 16, 2025
55bd11a
Refactor: Improve sqlx internal code quality and consistency
cursoragent Sep 16, 2025
3920eb8
Checkpoint before follow-up message
cursoragent Sep 16, 2025
282f1dd
Refactor ConnectOptions to use FromStr and update auth plugin names
cursoragent Sep 16, 2025
76fe15e
Refactor: Improve sqlx-core and sqlx-macros code quality
cursoragent Sep 16, 2025
14309cb
Refactor: Add write method to PgStream and BufStream
cursoragent Sep 16, 2025
a54a568
feat: Add FromStr constraint for connection options
cursoragent Sep 16, 2025
e2f4996
Test: Improve f64 precision and bool assertions
cursoragent Sep 16, 2025
a341a01
Fix: Use CopyFail instead of message::CopyFail
cursoragent Sep 16, 2025
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
86 changes: 86 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Clippy

on:
push:
pull_request:

permissions:
contents: read
checks: write

env:
CARGO_TERM_COLOR: always

jobs:
clippy-rt:
name: clippy (sqlx-rt-oldapi) • ${{ matrix.rt }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rt:
- runtime-tokio-native-tls
- runtime-tokio-rustls
- runtime-async-std-native-tls
- runtime-async-std-rustls
steps:
- uses: actions/checkout@v4
- name: Install system deps
run: sudo apt-get update -y && sudo apt-get install -y pkg-config libssl-dev
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: true
- name: Run clippy (rt)
run: |
cargo clippy -p sqlx-rt-oldapi --no-default-features --features "${{ matrix.rt }}" --all-targets -- -D warnings

clippy-core:
name: clippy (sqlx-core-oldapi) • ${{ matrix.db }} • ${{ matrix.rt }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
db: [postgres, mysql, sqlite, mssql, any]
rt: [runtime-tokio-rustls]
steps:
- uses: actions/checkout@v4
- name: Install system deps
run: sudo apt-get update -y && sudo apt-get install -y pkg-config libssl-dev
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: true
- name: Run clippy (core)
run: |
cargo clippy -p sqlx-core-oldapi --no-default-features --features "${{ matrix.rt }},${{ matrix.db }}" --all-targets -- -D warnings

clippy-root:
name: clippy (sqlx-oldapi) • ${{ matrix.combo }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
combo:
- "runtime-tokio-rustls,postgres,macros"
- "runtime-tokio-rustls,sqlite,macros"
- "runtime-tokio-rustls,mysql,macros"
- "runtime-async-std-rustls,postgres,macros"
steps:
- uses: actions/checkout@v4
- name: Install system deps
run: sudo apt-get update -y && sudo apt-get install -y pkg-config libssl-dev
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: true
- name: Run clippy (root)
run: |
cargo clippy -p sqlx-oldapi --no-default-features --features "${{ matrix.combo }}" --all-targets -- -D warnings

1 change: 0 additions & 1 deletion examples/postgres/axum-social-with-tests/tests/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// This is imported by different tests that use different functions.
#![allow(dead_code)]

use axum::body::{Body, BoxBody, HttpBody};
use axum::http::header::CONTENT_TYPE;
Expand Down
15 changes: 8 additions & 7 deletions sqlx-core/src/any/connection/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ use futures_util::{StreamExt, TryStreamExt};
impl<'c> Executor<'c> for &'c mut AnyConnection {
type Database = Any;

fn fetch_many<'e, 'q: 'e, E: 'q>(
fn fetch_many<'e, 'q, E>(
self,
mut query: E,
) -> BoxStream<'e, Result<Either<AnyQueryResult, AnyRow>, Error>>
where
'c: 'e,
'q: 'e,
E: Execute<'q, Self::Database>,
{
let arguments = query.take_arguments();
Expand Down Expand Up @@ -52,12 +53,10 @@ impl<'c> Executor<'c> for &'c mut AnyConnection {
}
}

fn fetch_optional<'e, 'q: 'e, E: 'q>(
self,
mut query: E,
) -> BoxFuture<'e, Result<Option<AnyRow>, Error>>
fn fetch_optional<'e, 'q, E>(self, mut query: E) -> BoxFuture<'e, Result<Option<AnyRow>, Error>>
where
'c: 'e,
'q: 'e,
E: Execute<'q, Self::Database>,
{
let arguments = query.take_arguments();
Expand Down Expand Up @@ -92,13 +91,14 @@ impl<'c> Executor<'c> for &'c mut AnyConnection {
})
}

fn prepare_with<'e, 'q: 'e>(
fn prepare_with<'e, 'q>(
self,
sql: &'q str,
_parameters: &[AnyTypeInfo],
) -> BoxFuture<'e, Result<AnyStatement<'q>, Error>>
where
'c: 'e,
'q: 'e,
{
Box::pin(async move {
Ok(match &mut self.0 {
Expand All @@ -118,12 +118,13 @@ impl<'c> Executor<'c> for &'c mut AnyConnection {
})
}

fn describe<'e, 'q: 'e>(
fn describe<'e, 'q>(
self,
sql: &'q str,
) -> BoxFuture<'e, Result<Describe<Self::Database>, Error>>
where
'c: 'e,
'q: 'e,
{
Box::pin(async move {
Ok(match &mut self.0 {
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/any/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'q> Statement<'q> for AnyStatement<'q> {

fn parameters(&self) -> Option<Either<&[AnyTypeInfo], usize>> {
match &self.parameters {
Some(Either::Left(types)) => Some(Either::Left(&types)),
Some(Either::Left(types)) => Some(Either::Left(types)),
Some(Either::Right(count)) => Some(Either::Right(*count)),
None => None,
}
Expand All @@ -55,6 +55,6 @@ where
.column_names
.get(*self)
.ok_or_else(|| Error::ColumnNotFound((*self).into()))
.map(|v| *v)
.copied()
}
}
6 changes: 6 additions & 0 deletions sqlx-core/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
mod statement_cache;

pub(crate) use statement_cache::StatementCache;
#[cfg(feature = "sqlite")]
use std::fmt::{Debug, Formatter};
#[cfg(feature = "sqlite")]
use std::ops::{Deref, DerefMut};

/// A wrapper for `Fn`s that provides a debug impl that just says "Function"
#[cfg(feature = "sqlite")]
pub(crate) struct DebugFn<F: ?Sized>(pub F);

#[cfg(feature = "sqlite")]
impl<F: ?Sized> Deref for DebugFn<F> {
type Target = F;

Expand All @@ -15,12 +19,14 @@ impl<F: ?Sized> Deref for DebugFn<F> {
}
}

#[cfg(feature = "sqlite")]
impl<F: ?Sized> DerefMut for DebugFn<F> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

#[cfg(feature = "sqlite")]
impl<F: ?Sized> Debug for DebugFn<F> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("Function").finish()
Expand Down
38 changes: 23 additions & 15 deletions sqlx-core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ pub trait Connection: Send {
fn connect(url: &str) -> BoxFuture<'static, Result<Self, Error>>
where
Self: Sized,
Self::Options: FromStr<Err = Error>,
{
let options = url.parse();

Box::pin(async move { Ok(Self::connect_with(&options?).await?) })
Box::pin(async move { Self::connect_with(&options?).await })
}

/// Establish a new database connection with the provided options.
Expand Down Expand Up @@ -158,24 +159,31 @@ impl LogSettings {
}
}

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

/// Establish a new database connection with the options specified by `self`.
fn connect(&self) -> BoxFuture<'_, Result<Self::Connection, Error>>
fn from_url(url: &str) -> Result<Self, Error>
where
Self::Connection: Sized;
Self: std::str::FromStr<Err = Error>,
{
Self::from_str(url)
}

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

/// 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 connect_with(options: &Self) -> BoxFuture<'_, Result<Self::Connection, Error>> {
options.connect()
}

/// Entirely disables statement logging (both slow and regular).
fn disable_statement_logging(&mut self) -> &mut Self {
self.log_statements(LevelFilter::Off)
.log_slow_statements(LevelFilter::Off, Duration::default())
fn from_env() -> Result<Self, Error>
where
Self: std::str::FromStr<Err = Error>,
{
let url = std::env::var("DATABASE_URL").map_err(Error::config)?;
Self::from_str(&url)
}

fn log_statements(&mut self, level: LevelFilter) -> &mut Self;

fn log_slow_statements(&mut self, level: LevelFilter, duration: Duration) -> &mut Self;
}
Loading
Loading