Fix clippy warnings

This commit is contained in:
Billy Chan 2021-12-17 11:39:53 +08:00
parent 4072e74284
commit 006d35313b
No known key found for this signature in database
GPG Key ID: A2D690CAC7DF3CC7
7 changed files with 60 additions and 52 deletions

View File

@ -247,20 +247,22 @@ impl DatabaseConnection {
impl DatabaseConnection { impl DatabaseConnection {
/// Sets a callback to metric this connection /// Sets a callback to metric this connection
pub fn set_metric_callback<F>(&mut self, callback: F) pub fn set_metric_callback<F>(&mut self, _callback: F)
where where
F: Fn(&crate::metric::Info<'_>) + Send + Sync + 'static, F: Fn(&crate::metric::Info<'_>) + Send + Sync + 'static,
{ {
match self { match self {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
DatabaseConnection::SqlxMySqlPoolConnection(conn) => conn.set_metric_callback(callback), DatabaseConnection::SqlxMySqlPoolConnection(conn) => {
conn.set_metric_callback(_callback)
}
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
DatabaseConnection::SqlxPostgresPoolConnection(conn) => { DatabaseConnection::SqlxPostgresPoolConnection(conn) => {
conn.set_metric_callback(callback) conn.set_metric_callback(_callback)
} }
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
DatabaseConnection::SqlxSqlitePoolConnection(conn) => { DatabaseConnection::SqlxSqlitePoolConnection(conn) => {
conn.set_metric_callback(callback) conn.set_metric_callback(_callback)
} }
_ => {} _ => {}
} }

View File

@ -120,11 +120,11 @@ impl QueryStream {
stmt, stmt,
conn, conn,
metric_callback, metric_callback,
stream_builder: |conn, stmt, metric_callback| match conn { stream_builder: |conn, stmt, _metric_callback| match conn {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
InnerConnection::MySql(c) => { InnerConnection::MySql(c) => {
let query = crate::driver::sqlx_mysql::sqlx_query(stmt); let query = crate::driver::sqlx_mysql::sqlx_query(stmt);
crate::metric::metric_ok!(metric_callback, stmt, { crate::metric::metric_ok!(_metric_callback, stmt, {
Box::pin( Box::pin(
c.fetch(query) c.fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -135,7 +135,7 @@ impl QueryStream {
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
InnerConnection::Postgres(c) => { InnerConnection::Postgres(c) => {
let query = crate::driver::sqlx_postgres::sqlx_query(stmt); let query = crate::driver::sqlx_postgres::sqlx_query(stmt);
crate::metric::metric_ok!(metric_callback, stmt, { crate::metric::metric_ok!(_metric_callback, stmt, {
Box::pin( Box::pin(
c.fetch(query) c.fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -146,7 +146,7 @@ impl QueryStream {
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
InnerConnection::Sqlite(c) => { InnerConnection::Sqlite(c) => {
let query = crate::driver::sqlx_sqlite::sqlx_query(stmt); let query = crate::driver::sqlx_sqlite::sqlx_query(stmt);
crate::metric::metric_ok!(metric_callback, stmt, { crate::metric::metric_ok!(_metric_callback, stmt, {
Box::pin( Box::pin(
c.fetch(query) c.fetch(query)
.map_ok(Into::into) .map_ok(Into::into)

View File

@ -44,13 +44,13 @@ impl<'a> TransactionStream<'a> {
stmt, stmt,
conn, conn,
metric_callback, metric_callback,
stream_builder: |conn, stmt, metric_callback| { stream_builder: |conn, stmt, _metric_callback| {
Box::pin(async move { Box::pin(async move {
match conn.deref_mut() { match conn.deref_mut() {
#[cfg(feature = "sqlx-mysql")] #[cfg(feature = "sqlx-mysql")]
InnerConnection::MySql(c) => { InnerConnection::MySql(c) => {
let query = crate::driver::sqlx_mysql::sqlx_query(stmt); let query = crate::driver::sqlx_mysql::sqlx_query(stmt);
crate::metric::metric_ok!(metric_callback, stmt, { crate::metric::metric_ok!(_metric_callback, stmt, {
Box::pin( Box::pin(
c.fetch(query) c.fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -62,7 +62,7 @@ impl<'a> TransactionStream<'a> {
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
InnerConnection::Postgres(c) => { InnerConnection::Postgres(c) => {
let query = crate::driver::sqlx_postgres::sqlx_query(stmt); let query = crate::driver::sqlx_postgres::sqlx_query(stmt);
crate::metric::metric_ok!(metric_callback, stmt, { crate::metric::metric_ok!(_metric_callback, stmt, {
Box::pin( Box::pin(
c.fetch(query) c.fetch(query)
.map_ok(Into::into) .map_ok(Into::into)
@ -74,7 +74,7 @@ impl<'a> TransactionStream<'a> {
#[cfg(feature = "sqlx-sqlite")] #[cfg(feature = "sqlx-sqlite")]
InnerConnection::Sqlite(c) => { InnerConnection::Sqlite(c) => {
let query = crate::driver::sqlx_sqlite::sqlx_query(stmt); let query = crate::driver::sqlx_sqlite::sqlx_query(stmt);
crate::metric::metric_ok!(metric_callback, stmt, { crate::metric::metric_ok!(_metric_callback, stmt, {
Box::pin( Box::pin(
c.fetch(query) c.fetch(query)
.map_ok(Into::into) .map_ok(Into::into)

View File

@ -28,6 +28,7 @@ where
S: SelectorTrait, S: SelectorTrait,
{ {
stmt: Statement, stmt: Statement,
#[allow(dead_code)]
selector: S, selector: S,
} }

View File

@ -2,6 +2,7 @@ use std::{sync::Arc, time::Duration};
pub(crate) type Callback = Arc<dyn Fn(&Info<'_>) + Send + Sync>; pub(crate) type Callback = Arc<dyn Fn(&Info<'_>) + Send + Sync>;
#[allow(unused_imports)]
pub(crate) use inner::{metric, metric_ok}; pub(crate) use inner::{metric, metric_ok};
#[derive(Debug)] #[derive(Debug)]
@ -16,6 +17,7 @@ pub struct Info<'a> {
} }
mod inner { mod inner {
#[allow(unused_macros)]
macro_rules! metric { macro_rules! metric {
($metric_callback:expr, $stmt:expr, $code:block) => {{ ($metric_callback:expr, $stmt:expr, $code:block) => {{
let _start = std::time::SystemTime::now(); let _start = std::time::SystemTime::now();
@ -32,6 +34,7 @@ mod inner {
}}; }};
} }
pub(crate) use metric; pub(crate) use metric;
#[allow(unused_macros)]
macro_rules! metric_ok { macro_rules! metric_ok {
($metric_callback:expr, $stmt:expr, $code:block) => {{ ($metric_callback:expr, $stmt:expr, $code:block) => {{
let _start = std::time::SystemTime::now(); let _start = std::time::SystemTime::now();

View File

@ -401,15 +401,15 @@ mod tests {
color: None, color: None,
tea: None, tea: None,
}; };
let select = active_enum_model.find_related(ActiveEnumChild); let _select = active_enum_model.find_related(ActiveEnumChild);
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))]
{ {
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
select.build(DbBackend::Sqlite).to_string(), _select.build(DbBackend::Sqlite).to_string(),
); );
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
[ [
"SELECT `active_enum_child`.`id`, `active_enum_child`.`parent_id`, `active_enum_child`.`category`, `active_enum_child`.`color`, `active_enum_child`.`tea`", "SELECT `active_enum_child`.`id`, `active_enum_child`.`parent_id`, `active_enum_child`.`category`, `active_enum_child`.`color`, `active_enum_child`.`tea`",
"FROM `active_enum_child`", "FROM `active_enum_child`",
@ -421,7 +421,7 @@ mod tests {
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
assert_eq!( assert_eq!(
select.build(DbBackend::Postgres).to_string(), _select.build(DbBackend::Postgres).to_string(),
[ [
r#"SELECT "active_enum_child"."id", "active_enum_child"."parent_id", "active_enum_child"."category", "active_enum_child"."color", CAST("active_enum_child"."tea" AS text)"#, r#"SELECT "active_enum_child"."id", "active_enum_child"."parent_id", "active_enum_child"."category", "active_enum_child"."color", CAST("active_enum_child"."tea" AS text)"#,
r#"FROM "public"."active_enum_child""#, r#"FROM "public"."active_enum_child""#,
@ -431,15 +431,15 @@ mod tests {
.join(" ") .join(" ")
); );
let select = ActiveEnum::find().find_also_related(ActiveEnumChild); let _select = ActiveEnum::find().find_also_related(ActiveEnumChild);
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))]
{ {
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
select.build(DbBackend::Sqlite).to_string(), _select.build(DbBackend::Sqlite).to_string(),
); );
assert_eq!( assert_eq!(
select _select
.build(DbBackend::MySql) .build(DbBackend::MySql)
.to_string(), .to_string(),
[ [
@ -453,7 +453,7 @@ mod tests {
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
assert_eq!( assert_eq!(
select _select
.build(DbBackend::Postgres) .build(DbBackend::Postgres)
.to_string(), .to_string(),
[ [
@ -474,15 +474,15 @@ mod tests {
color: None, color: None,
tea: None, tea: None,
}; };
let select = active_enum_model.find_linked(active_enum::ActiveEnumChildLink); let _select = active_enum_model.find_linked(active_enum::ActiveEnumChildLink);
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))]
{ {
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
select.build(DbBackend::Sqlite).to_string(), _select.build(DbBackend::Sqlite).to_string(),
); );
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
[ [
"SELECT `active_enum_child`.`id`, `active_enum_child`.`parent_id`, `active_enum_child`.`category`, `active_enum_child`.`color`, `active_enum_child`.`tea`", "SELECT `active_enum_child`.`id`, `active_enum_child`.`parent_id`, `active_enum_child`.`category`, `active_enum_child`.`color`, `active_enum_child`.`tea`",
"FROM `active_enum_child`", "FROM `active_enum_child`",
@ -494,7 +494,7 @@ mod tests {
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
assert_eq!( assert_eq!(
select.build(DbBackend::Postgres).to_string(), _select.build(DbBackend::Postgres).to_string(),
[ [
r#"SELECT "active_enum_child"."id", "active_enum_child"."parent_id", "active_enum_child"."category", "active_enum_child"."color", CAST("active_enum_child"."tea" AS text)"#, r#"SELECT "active_enum_child"."id", "active_enum_child"."parent_id", "active_enum_child"."category", "active_enum_child"."color", CAST("active_enum_child"."tea" AS text)"#,
r#"FROM "public"."active_enum_child""#, r#"FROM "public"."active_enum_child""#,
@ -504,15 +504,15 @@ mod tests {
.join(" ") .join(" ")
); );
let select = ActiveEnum::find().find_also_linked(active_enum::ActiveEnumChildLink); let _select = ActiveEnum::find().find_also_linked(active_enum::ActiveEnumChildLink);
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))]
{ {
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
select.build(DbBackend::Sqlite).to_string(), _select.build(DbBackend::Sqlite).to_string(),
); );
assert_eq!( assert_eq!(
select _select
.build(DbBackend::MySql) .build(DbBackend::MySql)
.to_string(), .to_string(),
[ [
@ -526,7 +526,7 @@ mod tests {
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
assert_eq!( assert_eq!(
select _select
.build(DbBackend::Postgres) .build(DbBackend::Postgres)
.to_string(), .to_string(),
[ [
@ -548,15 +548,15 @@ mod tests {
color: None, color: None,
tea: None, tea: None,
}; };
let select = active_enum_child_model.find_related(ActiveEnum); let _select = active_enum_child_model.find_related(ActiveEnum);
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))]
{ {
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
select.build(DbBackend::Sqlite).to_string(), _select.build(DbBackend::Sqlite).to_string(),
); );
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
[ [
"SELECT `active_enum`.`id`, `active_enum`.`category`, `active_enum`.`color`, `active_enum`.`tea`", "SELECT `active_enum`.`id`, `active_enum`.`category`, `active_enum`.`color`, `active_enum`.`tea`",
"FROM `active_enum`", "FROM `active_enum`",
@ -568,7 +568,7 @@ mod tests {
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
assert_eq!( assert_eq!(
select.build(DbBackend::Postgres).to_string(), _select.build(DbBackend::Postgres).to_string(),
[ [
r#"SELECT "active_enum"."id", "active_enum"."category", "active_enum"."color", CAST("active_enum"."tea" AS text)"#, r#"SELECT "active_enum"."id", "active_enum"."category", "active_enum"."color", CAST("active_enum"."tea" AS text)"#,
r#"FROM "public"."active_enum""#, r#"FROM "public"."active_enum""#,
@ -578,15 +578,15 @@ mod tests {
.join(" ") .join(" ")
); );
let select = ActiveEnumChild::find().find_also_related(ActiveEnum); let _select = ActiveEnumChild::find().find_also_related(ActiveEnum);
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))]
{ {
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
select.build(DbBackend::Sqlite).to_string(), _select.build(DbBackend::Sqlite).to_string(),
); );
assert_eq!( assert_eq!(
select _select
.build(DbBackend::MySql) .build(DbBackend::MySql)
.to_string(), .to_string(),
[ [
@ -600,7 +600,7 @@ mod tests {
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
assert_eq!( assert_eq!(
select _select
.build(DbBackend::Postgres) .build(DbBackend::Postgres)
.to_string(), .to_string(),
[ [
@ -622,15 +622,15 @@ mod tests {
color: None, color: None,
tea: None, tea: None,
}; };
let select = active_enum_child_model.find_linked(active_enum_child::ActiveEnumLink); let _select = active_enum_child_model.find_linked(active_enum_child::ActiveEnumLink);
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))]
{ {
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
select.build(DbBackend::Sqlite).to_string(), _select.build(DbBackend::Sqlite).to_string(),
); );
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
[ [
"SELECT `active_enum`.`id`, `active_enum`.`category`, `active_enum`.`color`, `active_enum`.`tea`", "SELECT `active_enum`.`id`, `active_enum`.`category`, `active_enum`.`color`, `active_enum`.`tea`",
"FROM `active_enum`", "FROM `active_enum`",
@ -642,7 +642,7 @@ mod tests {
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
assert_eq!( assert_eq!(
select.build(DbBackend::Postgres).to_string(), _select.build(DbBackend::Postgres).to_string(),
[ [
r#"SELECT "active_enum"."id", "active_enum"."category", "active_enum"."color", CAST("active_enum"."tea" AS text)"#, r#"SELECT "active_enum"."id", "active_enum"."category", "active_enum"."color", CAST("active_enum"."tea" AS text)"#,
r#"FROM "public"."active_enum""#, r#"FROM "public"."active_enum""#,
@ -652,15 +652,15 @@ mod tests {
.join(" ") .join(" ")
); );
let select = ActiveEnumChild::find().find_also_linked(active_enum_child::ActiveEnumLink); let _select = ActiveEnumChild::find().find_also_linked(active_enum_child::ActiveEnumLink);
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))]
{ {
assert_eq!( assert_eq!(
select.build(DbBackend::MySql).to_string(), _select.build(DbBackend::MySql).to_string(),
select.build(DbBackend::Sqlite).to_string(), _select.build(DbBackend::Sqlite).to_string(),
); );
assert_eq!( assert_eq!(
select _select
.build(DbBackend::MySql) .build(DbBackend::MySql)
.to_string(), .to_string(),
[ [
@ -674,7 +674,7 @@ mod tests {
} }
#[cfg(feature = "sqlx-postgres")] #[cfg(feature = "sqlx-postgres")]
assert_eq!( assert_eq!(
select _select
.build(DbBackend::Postgres) .build(DbBackend::Postgres)
.to_string(), .to_string(),
[ [

View File

@ -71,6 +71,7 @@ pub async fn left_join() {
.await .await
.unwrap() .unwrap()
.unwrap(); .unwrap();
assert_eq!(result.name.as_str(), "Baker 1");
assert_eq!(result.bakery_name, Some("SeaSide Bakery".to_string())); assert_eq!(result.bakery_name, Some("SeaSide Bakery".to_string()));
let select = baker::Entity::find() let select = baker::Entity::find()
@ -340,6 +341,7 @@ pub async fn group_by() {
.unwrap() .unwrap()
.unwrap(); .unwrap();
assert_eq!(result.name.as_str(), "Kate");
assert_eq!(result.number_orders, Some(2)); assert_eq!(result.number_orders, Some(2));
assert_eq!( assert_eq!(
result.total_spent, result.total_spent,