Skip to content

Commit 7218f16

Browse files
committed
Clippy
1 parent 494d1cc commit 7218f16

10 files changed

Lines changed: 61 additions & 31 deletions

File tree

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ trim-in-place = "0.1.7"
2424
serde = { version = "1.0", features = ["derive"] }
2525
strum_macros = "0.27"
2626
url = "2.5.4"
27+
saturating_cast = "0.1.0"
2728

2829
[features]
2930
default = [

benches/benchmark.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ fn bench_ast(c: &mut Criterion) {
5353
c.bench_function("Ast::parse_small", |b| {
5454
b.iter(|| {
5555
let _res = black_box(Ast::parse(QUERY_SMALL, &SETTINGS));
56-
})
56+
});
5757
});
5858
c.bench_function("Ast::parse_big", |b| {
5959
b.iter(|| {
6060
let _res = black_box(Ast::parse(QUERY_BIG, &SETTINGS));
61-
})
61+
});
6262
});
6363

6464
c.bench_function("Ast::render_big", |b| {
@@ -72,7 +72,7 @@ fn bench_ast(c: &mut Criterion) {
7272
]),
7373
&SETTINGS,
7474
));
75-
})
75+
});
7676
});
7777
}
7878

php-sqlx-cdylib/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dbms/mysql/query_result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! MySQL query result iterator.
1+
//! `MySQL` query result iterator.
22
33
crate::php_sqlx_impl_query_result!(
44
MySqlQueryResult,

src/dbms/postgres/query_result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! PostgreSQL query result iterator.
1+
//! `PostgreSQL` query result iterator.
22
33
crate::php_sqlx_impl_query_result!(
44
PgQueryResult,

src/driver.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ macro_rules! php_sqlx_impl_driver {
658658
self.driver_inner.query_all(query, parameters, None)
659659
}
660660

661-
/// Executes an SQL query and returns a lazy QueryResult iterator.
661+
/// Executes an SQL query and returns a lazy `QueryResult` iterator.
662662
///
663663
/// This method returns a `QueryResult` object that implements PHP's `Iterator`
664664
/// interface, streaming rows from the database as you iterate.
@@ -702,7 +702,7 @@ macro_rules! php_sqlx_impl_driver {
702702
Ok($query_result::new(receiver, assoc, batch_size))
703703
}
704704

705-
/// Executes an SQL query and returns a lazy QueryResult iterator with rows as associative arrays.
705+
/// Executes an SQL query and returns a lazy `QueryResult` iterator with rows as associative arrays.
706706
///
707707
/// Same as `query()`, but forces rows to be returned as associative arrays
708708
/// regardless of the driver's default configuration.
@@ -725,7 +725,7 @@ macro_rules! php_sqlx_impl_driver {
725725
Ok($query_result::new(receiver, true, batch_size))
726726
}
727727

728-
/// Executes an SQL query and returns a lazy QueryResult iterator with rows as objects.
728+
/// Executes an SQL query and returns a lazy `QueryResult` iterator with rows as objects.
729729
///
730730
/// Same as `query()`, but forces rows to be returned as PHP objects
731731
/// regardless of the driver's default configuration.

src/inner_driver.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ macro_rules! php_sqlx_impl_driver_inner {
141141
/// Type alias for the row stream used in lazy iteration.
142142
/// Rows are streamed through this channel from a background task.
143143
pub type RowReceiver = tokio::sync::mpsc::Receiver<
144-
Result<<$database as sqlx_oldapi::Database>::Row, $crate::error::Error>
144+
Result<<$database as sqlx_oldapi::Database>::Row, $crate::error::Error>,
145145
>;
146146

147147
impl $struct {
@@ -873,15 +873,18 @@ macro_rules! php_sqlx_impl_driver_inner {
873873
// the connection to stay in the current context
874874
if self.has_active_transaction() || self.has_pinned_connection() {
875875
// Fall back to fetching all rows in the current context
876-
let rows_result = if let Some(mut conn_tx) = self.retrieve_ongoing_transaction() {
876+
let rows_result = if let Some(mut conn_tx) = self.retrieve_ongoing_transaction()
877+
{
877878
let val = RUNTIME.block_on(
878-
bind_values(sqlx_oldapi::query(&rendered_query), &values)?.fetch_all(&mut *conn_tx),
879+
bind_values(sqlx_oldapi::query(&rendered_query), &values)?
880+
.fetch_all(&mut *conn_tx),
879881
);
880882
self.place_ongoing_transaction(conn_tx);
881883
val
882884
} else if let Some(mut conn) = self.retrieve_pinned_connection() {
883885
let val = RUNTIME.block_on(
884-
bind_values(sqlx_oldapi::query(&rendered_query), &values)?.fetch_all(&mut *conn),
886+
bind_values(sqlx_oldapi::query(&rendered_query), &values)?
887+
.fetch_all(&mut *conn),
885888
);
886889
self.return_pinned_connection(conn);
887890
val
@@ -899,7 +902,10 @@ macro_rules! php_sqlx_impl_driver_inner {
899902
}
900903
}
901904
Err(err) => {
902-
let _ = tx.blocking_send(Err(SqlxError::query_with_source(&rendered_query, err)));
905+
let _ = tx.blocking_send(Err(SqlxError::query_with_source(
906+
&rendered_query,
907+
err,
908+
)));
903909
}
904910
}
905911

@@ -913,13 +919,14 @@ macro_rules! php_sqlx_impl_driver_inner {
913919
// Spawn a background task that streams rows and sends through channel
914920
RUNTIME.spawn(async move {
915921
// Bind the query with values
916-
let bound_query = match bind_values(sqlx_oldapi::query(&rendered_query), &values) {
917-
Ok(q) => q,
918-
Err(e) => {
919-
let _ = tx.send(Err(e)).await;
920-
return;
921-
}
922-
};
922+
let bound_query =
923+
match bind_values(sqlx_oldapi::query(&rendered_query), &values) {
924+
Ok(q) => q,
925+
Err(e) => {
926+
let _ = tx.send(Err(e)).await;
927+
return;
928+
}
929+
};
923930

924931
// Create the stream from the pool
925932
let mut stream = bound_query.fetch(&pool);

src/query_builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,7 @@ macro_rules! php_sqlx_impl_query_builder {
27472747
.query_all(&self.query, merged_params, Some(false))
27482748
}
27492749

2750-
/// Executes the query and returns a lazy QueryResult iterator.
2750+
/// Executes the query and returns a lazy `QueryResult` iterator.
27512751
///
27522752
/// This method returns a `QueryResult` object that implements PHP's `Iterator`
27532753
/// interface, streaming rows from the database as you iterate.
@@ -2770,7 +2770,7 @@ macro_rules! php_sqlx_impl_query_builder {
27702770
Ok(super::query_result::$query_result::new(receiver, assoc, batch_size))
27712771
}
27722772

2773-
/// Executes the query and returns a lazy QueryResult iterator with rows as associative arrays.
2773+
/// Executes the query and returns a lazy `QueryResult` iterator with rows as associative arrays.
27742774
///
27752775
/// # Arguments
27762776
/// - `parameters`: Optional array of indexed/named parameters to bind.
@@ -2789,7 +2789,7 @@ macro_rules! php_sqlx_impl_query_builder {
27892789
Ok(super::query_result::$query_result::new(receiver, true, batch_size))
27902790
}
27912791

2792-
/// Executes the query and returns a lazy QueryResult iterator with rows as objects.
2792+
/// Executes the query and returns a lazy `QueryResult` iterator with rows as objects.
27932793
///
27942794
/// # Arguments
27952795
/// - `parameters`: Optional array of indexed/named parameters to bind.

src/query_result.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@
1010
/// Default batch size for lazy row fetching (channel buffer size).
1111
pub const DEFAULT_BATCH_SIZE: usize = 100;
1212

13-
/// Generates a database-specific QueryResult implementation with lazy streaming.
13+
/// Generates a database-specific `QueryResult` implementation with lazy streaming.
1414
///
15-
/// The generated QueryResult implements PHP's `Iterator` interface,
15+
/// The generated `QueryResult` implements PHP's `Iterator` interface,
1616
/// receiving rows from a background streaming task as iteration progresses.
1717
///
1818
/// # Arguments
1919
///
2020
/// - `$struct` - The Rust struct name for the query result (e.g., `PgQueryResult`)
2121
/// - `$class` - The PHP class name as a string literal (e.g., `"Sqlx\\PgQueryResult"`)
22-
/// - `$database` - The SQLx database type (e.g., `Postgres`)
22+
/// - `$database` - The `SQLx` database type (e.g., `Postgres`)
2323
/// - `$inner` - The inner driver type
2424
#[macro_export]
2525
macro_rules! php_sqlx_impl_query_result {
2626
( $struct:ident, $class:literal, $database:ident, $inner:ident ) => {
2727
use ext_php_rs::prelude::*;
2828
use ext_php_rs::types::Zval;
2929
use ext_php_rs::zend::ce;
30+
use saturating_cast::SaturatingCast;
3031

3132
/// A lazy query result iterator that streams rows on demand.
3233
///
@@ -48,7 +49,10 @@ macro_rules! php_sqlx_impl_query_result {
4849
pub struct $struct {
4950
/// Channel receiver for streaming rows from background task
5051
receiver: tokio::sync::mpsc::Receiver<
51-
Result<<sqlx_oldapi::$database as sqlx_oldapi::Database>::Row, $crate::error::Error>
52+
Result<
53+
<sqlx_oldapi::$database as sqlx_oldapi::Database>::Row,
54+
$crate::error::Error,
55+
>,
5256
>,
5357
/// Current row (converted to Zval)
5458
current: Option<Zval>,
@@ -69,11 +73,14 @@ macro_rules! php_sqlx_impl_query_result {
6973
}
7074

7175
impl $struct {
72-
/// Creates a new streaming QueryResult.
76+
/// Creates a new streaming `QueryResult`.
7377
#[allow(dead_code)]
7478
pub fn new(
7579
receiver: tokio::sync::mpsc::Receiver<
76-
Result<<sqlx_oldapi::$database as sqlx_oldapi::Database>::Row, $crate::error::Error>
80+
Result<
81+
<sqlx_oldapi::$database as sqlx_oldapi::Database>::Row,
82+
$crate::error::Error,
83+
>,
7784
>,
7885
associative_arrays: bool,
7986
buffer_size: usize,
@@ -178,7 +185,7 @@ macro_rules! php_sqlx_impl_query_result {
178185
/// Note: This returns the count of rows fetched, not the total
179186
/// result set size (which may not be known until iteration completes).
180187
pub fn count(&self) -> i64 {
181-
self.total_fetched as i64
188+
self.total_fetched.saturating_cast::<i64>()
182189
}
183190

184191
/// Returns true if the result set has been fully consumed.
@@ -188,13 +195,14 @@ macro_rules! php_sqlx_impl_query_result {
188195

189196
/// Returns the configured buffer size for streaming.
190197
pub fn get_batch_size(&self) -> i64 {
191-
self.buffer_size as i64
198+
self.buffer_size.saturating_cast::<i64>()
192199
}
193200

194201
/// Consumes all remaining rows and returns them as an array.
195202
///
196203
/// This will fetch all remaining rows from the stream.
197204
/// Use with caution on large result sets.
205+
#[allow(clippy::wrong_self_convention)]
198206
pub fn to_array(&mut self) -> $crate::error::Result<Vec<Zval>> {
199207
let mut all_rows = Vec::new();
200208

0 commit comments

Comments
 (0)