diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 112ed51f..a62e0233 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -43,7 +43,7 @@ jobs: with: toolchain: stable components: clippy - - run: cargo clippy --all-targets --all + - run: cargo clippy --all-targets --all -- -D warnings test: name: Unit Test diff --git a/src/mysql/discovery/executor/mock.rs b/src/mysql/discovery/executor/mock.rs index a07d5ee2..3ddcb01d 100644 --- a/src/mysql/discovery/executor/mock.rs +++ b/src/mysql/discovery/executor/mock.rs @@ -3,6 +3,7 @@ use sea_query::{MysqlQueryBuilder, SelectStatement}; use crate::debug_print; +#[allow(dead_code)] pub struct Executor { pool: MySqlPool, } @@ -19,8 +20,8 @@ impl IntoExecutor for MySqlPool { impl Executor { pub async fn fetch_all(&self, select: SelectStatement) -> Vec { - let (sql, values) = select.build(MysqlQueryBuilder); - debug_print!("{}, {:?}", sql, values); + let (_sql, _values) = select.build(MysqlQueryBuilder); + debug_print!("{}, {:?}", _sql, _values); panic!("This is a mock Executor"); } diff --git a/src/mysql/query/column.rs b/src/mysql/query/column.rs index 89732f04..439204b6 100644 --- a/src/mysql/query/column.rs +++ b/src/mysql/query/column.rs @@ -93,7 +93,7 @@ impl From<&MySqlRow> for ColumnQueryResult { #[cfg(not(feature = "sqlx-mysql"))] impl From<&MySqlRow> for ColumnQueryResult { - fn from(row: &MySqlRow) -> Self { + fn from(_: &MySqlRow) -> Self { Self::default() } } diff --git a/src/mysql/query/foreign_key.rs b/src/mysql/query/foreign_key.rs index d931e251..8896a43b 100644 --- a/src/mysql/query/foreign_key.rs +++ b/src/mysql/query/foreign_key.rs @@ -63,19 +63,19 @@ impl SchemaQueryBuilder { .from((Schema::Schema, Schema::KeyColumnUsage)) .inner_join( (Schema::Schema, Schema::ReferentialConstraints), - Expr::tbl(Schema::KeyColumnUsage, Key::ConstraintSchema) + Expr::col((Schema::KeyColumnUsage, Key::ConstraintSchema)) .equals((Schema::ReferentialConstraints, Ref::ConstraintSchema)) .and( - Expr::tbl(Schema::KeyColumnUsage, Key::ConstraintName) + Expr::col((Schema::KeyColumnUsage, Key::ConstraintName)) .equals((Schema::ReferentialConstraints, Ref::ConstraintName)), ), ) .and_where( - Expr::tbl(Schema::KeyColumnUsage, Key::ConstraintSchema).eq(schema.to_string()), + Expr::col((Schema::KeyColumnUsage, Key::ConstraintSchema)).eq(schema.to_string()), ) - .and_where(Expr::tbl(Schema::KeyColumnUsage, Key::TableName).eq(table.to_string())) - .and_where(Expr::tbl(Schema::KeyColumnUsage, Key::ReferencedTableName).is_not_null()) - .and_where(Expr::tbl(Schema::KeyColumnUsage, Key::ReferencedColumnName).is_not_null()) + .and_where(Expr::col((Schema::KeyColumnUsage, Key::TableName)).eq(table.to_string())) + .and_where(Expr::col((Schema::KeyColumnUsage, Key::ReferencedTableName)).is_not_null()) + .and_where(Expr::col((Schema::KeyColumnUsage, Key::ReferencedColumnName)).is_not_null()) .order_by(Key::ConstraintName, Order::Asc) .order_by(Key::OrdinalPosition, Order::Asc) .take() @@ -99,7 +99,7 @@ impl From<&MySqlRow> for ForeignKeyQueryResult { #[cfg(not(feature = "sqlx-mysql"))] impl From<&MySqlRow> for ForeignKeyQueryResult { - fn from(row: &MySqlRow) -> Self { + fn from(_: &MySqlRow) -> Self { Self::default() } } diff --git a/src/mysql/query/index.rs b/src/mysql/query/index.rs index 00b71eed..2aa2c8a1 100644 --- a/src/mysql/query/index.rs +++ b/src/mysql/query/index.rs @@ -93,7 +93,7 @@ impl From<&MySqlRow> for IndexQueryResult { #[cfg(not(feature = "sqlx-mysql"))] impl From<&MySqlRow> for IndexQueryResult { - fn from(row: &MySqlRow) -> Self { + fn from(_: &MySqlRow) -> Self { Self::default() } } diff --git a/src/mysql/query/table.rs b/src/mysql/query/table.rs index c6f7faf2..f13b0a75 100644 --- a/src/mysql/query/table.rs +++ b/src/mysql/query/table.rs @@ -69,10 +69,10 @@ impl SchemaQueryBuilder { .from((Schema::Schema, Schema::Tables)) .left_join( (Schema::Schema, Schema::CollationCharacterSet), - Expr::tbl( + Expr::col(( Schema::CollationCharacterSet, CharacterSetFields::CollationName, - ) + )) .equals((Schema::Tables, TablesFields::TableCollation)), ) .and_where(Expr::col(TablesFields::TableSchema).eq(schema.to_string())) @@ -103,7 +103,7 @@ impl From<&MySqlRow> for TableQueryResult { #[cfg(not(feature = "sqlx-mysql"))] impl From<&MySqlRow> for TableQueryResult { - fn from(row: &MySqlRow) -> Self { + fn from(_: &MySqlRow) -> Self { Self::default() } } diff --git a/src/mysql/query/version.rs b/src/mysql/query/version.rs index 5d889321..87384284 100644 --- a/src/mysql/query/version.rs +++ b/src/mysql/query/version.rs @@ -30,7 +30,7 @@ impl From<&MySqlRow> for VersionQueryResult { #[cfg(not(feature = "sqlx-mysql"))] impl From<&MySqlRow> for VersionQueryResult { - fn from(row: &MySqlRow) -> Self { + fn from(_: &MySqlRow) -> Self { Self::default() } } diff --git a/src/postgres/discovery/executor/mock.rs b/src/postgres/discovery/executor/mock.rs index 91fbc286..3b63aee6 100644 --- a/src/postgres/discovery/executor/mock.rs +++ b/src/postgres/discovery/executor/mock.rs @@ -3,6 +3,7 @@ use sea_query::{PostgresQueryBuilder, SelectStatement}; use crate::debug_print; +#[allow(dead_code)] pub struct Executor { pool: PgPool, } @@ -19,8 +20,8 @@ impl IntoExecutor for PgPool { impl Executor { pub async fn fetch_all(&self, select: SelectStatement) -> Vec { - let (sql, values) = select.build(PostgresQueryBuilder); - debug_print!("{}, {:?}", sql, values); + let (_sql, _values) = select.build(PostgresQueryBuilder); + debug_print!("{}, {:?}", _sql, _values); panic!("This is a mock Executor"); } diff --git a/src/postgres/query/column.rs b/src/postgres/query/column.rs index aa001aef..ffebe158 100644 --- a/src/postgres/query/column.rs +++ b/src/postgres/query/column.rs @@ -131,7 +131,7 @@ impl From<&PgRow> for ColumnQueryResult { #[cfg(not(feature = "sqlx-postgres"))] impl From<&PgRow> for ColumnQueryResult { - fn from(row: &PgRow) -> Self { + fn from(_: &PgRow) -> Self { Self::default() } } diff --git a/src/postgres/query/constraints/mod.rs b/src/postgres/query/constraints/mod.rs index 7abdefaa..5de001da 100644 --- a/src/postgres/query/constraints/mod.rs +++ b/src/postgres/query/constraints/mod.rs @@ -90,15 +90,15 @@ impl SchemaQueryBuilder { (Schema::Schema, Schema::CheckConstraints), Condition::all() .add( - Expr::tbl(Schema::TableConstraints, Tcf::ConstraintName) + Expr::col((Schema::TableConstraints, Tcf::ConstraintName)) .equals((Schema::CheckConstraints, Cf::ConstraintName)), ) .add( - Expr::tbl(Schema::TableConstraints, Tcf::ConstraintCatalog) + Expr::col((Schema::TableConstraints, Tcf::ConstraintCatalog)) .equals((Schema::CheckConstraints, Cf::ConstraintCatalog)), ) .add( - Expr::tbl(Schema::TableConstraints, Tcf::ConstraintSchema) + Expr::col((Schema::TableConstraints, Tcf::ConstraintSchema)) .equals((Schema::CheckConstraints, Cf::ConstraintSchema)), ), ) @@ -107,27 +107,27 @@ impl SchemaQueryBuilder { (Schema::Schema, Schema::KeyColumnUsage), Condition::all() .add( - Expr::tbl(Schema::TableConstraints, Tcf::ConstraintName) + Expr::col((Schema::TableConstraints, Tcf::ConstraintName)) .equals((Schema::KeyColumnUsage, Kcuf::ConstraintName)), ) .add( - Expr::tbl(Schema::TableConstraints, Tcf::ConstraintCatalog) + Expr::col((Schema::TableConstraints, Tcf::ConstraintCatalog)) .equals((Schema::KeyColumnUsage, Kcuf::ConstraintCatalog)), ) .add( - Expr::tbl(Schema::TableConstraints, Tcf::ConstraintSchema) + Expr::col((Schema::TableConstraints, Tcf::ConstraintSchema)) .equals((Schema::KeyColumnUsage, Kcuf::ConstraintSchema)), ) .add( - Expr::tbl(Schema::TableConstraints, Tcf::TableCatalog) + Expr::col((Schema::TableConstraints, Tcf::TableCatalog)) .equals((Schema::KeyColumnUsage, Kcuf::TableCatalog)), ) .add( - Expr::tbl(Schema::TableConstraints, Tcf::TableSchema) + Expr::col((Schema::TableConstraints, Tcf::TableSchema)) .equals((Schema::KeyColumnUsage, Kcuf::TableSchema)), ) .add( - Expr::tbl(Schema::TableConstraints, Tcf::TableName) + Expr::col((Schema::TableConstraints, Tcf::TableName)) .equals((Schema::KeyColumnUsage, Kcuf::TableName)), ), ) @@ -150,12 +150,12 @@ impl SchemaQueryBuilder { .from((Schema::Schema, Schema::ReferentialConstraints)) .left_join( (Schema::Schema, Schema::ConstraintColumnUsage), - Expr::tbl(Schema::ReferentialConstraints, RefC::ConstraintName) + Expr::col((Schema::ReferentialConstraints, RefC::ConstraintName)) .equals((Schema::ConstraintColumnUsage, Kcuf::ConstraintName)), ) .take(), rcsq.clone(), - Expr::tbl(Schema::TableConstraints, Tcf::ConstraintName) + Expr::col((Schema::TableConstraints, Tcf::ConstraintName)) .equals((rcsq.clone(), RefC::ConstraintName)), ) .and_where( @@ -203,7 +203,7 @@ impl From<&PgRow> for TableConstraintsQueryResult { #[cfg(not(feature = "sqlx-postgres"))] impl From<&PgRow> for TableConstraintsQueryResult { - fn from(_row: &PgRow) -> Self { + fn from(_: &PgRow) -> Self { Self::default() } } diff --git a/src/postgres/query/enumeration.rs b/src/postgres/query/enumeration.rs index beb8be3b..043edf10 100644 --- a/src/postgres/query/enumeration.rs +++ b/src/postgres/query/enumeration.rs @@ -36,7 +36,7 @@ impl SchemaQueryBuilder { .from(PgType::Table) .inner_join( PgEnum::Table, - Expr::tbl(PgEnum::Table, PgEnum::EnumTypeId).equals((PgType::Table, PgType::Oid)), + Expr::col((PgEnum::Table, PgEnum::EnumTypeId)).equals((PgType::Table, PgType::Oid)), ) .order_by((PgType::Table, PgType::TypeName), Order::Asc) .order_by((PgEnum::Table, PgEnum::EnumLabel), Order::Asc) @@ -57,7 +57,7 @@ impl From<&PgRow> for EnumQueryResult { #[cfg(not(feature = "sqlx-postgres"))] impl From<&PgRow> for EnumQueryResult { - fn from(row: &PgRow) -> Self { + fn from(_: &PgRow) -> Self { Self::default() } } diff --git a/src/postgres/query/table.rs b/src/postgres/query/table.rs index a6f3c368..4d3355c9 100644 --- a/src/postgres/query/table.rs +++ b/src/postgres/query/table.rs @@ -64,7 +64,7 @@ impl From<&PgRow> for TableQueryResult { #[cfg(not(feature = "sqlx-postgres"))] impl From<&PgRow> for TableQueryResult { - fn from(row: &PgRow) -> Self { + fn from(_: &PgRow) -> Self { Self::default() } } diff --git a/src/sqlite/def/column.rs b/src/sqlite/def/column.rs index 90bf138a..fb59925a 100644 --- a/src/sqlite/def/column.rs +++ b/src/sqlite/def/column.rs @@ -1,10 +1,12 @@ use super::{DefaultType, Type}; -use crate::sqlx_types::{sqlite::SqliteRow, Row}; use sea_query::{ foreign_key::ForeignKeyAction as SeaQueryForeignKeyAction, Alias, Index, IndexCreateStatement, }; use std::num::ParseIntError; +#[allow(unused_imports)] +use crate::sqlx_types::{sqlite::SqliteRow, Row}; + /// An SQLite column definition #[derive(Debug, PartialEq, Clone)] pub struct ColumnInfo { @@ -33,7 +35,7 @@ impl ColumnInfo { } else if default_value.is_empty() { DefaultType::Unspecified } else { - let value = default_value.to_owned().replace("'", ""); + let value = default_value.to_owned().replace('\'', ""); if let Ok(is_int) = value.parse::() { DefaultType::Integer(is_int) @@ -50,7 +52,7 @@ impl ColumnInfo { #[cfg(not(feature = "sqlx-sqlite"))] impl ColumnInfo { - pub fn to_column_def(row: &SqliteRow) -> Result { + pub fn to_column_def(_: &SqliteRow) -> Result { i32::from_str_radix("", 10)?; unimplemented!() } @@ -119,7 +121,7 @@ impl From<&SqliteRow> for PartialIndexInfo { #[cfg(not(feature = "sqlx-sqlite"))] impl From<&SqliteRow> for PartialIndexInfo { - fn from(row: &SqliteRow) -> Self { + fn from(_: &SqliteRow) -> Self { Self::default() } } @@ -145,7 +147,7 @@ impl From<&SqliteRow> for IndexedColumns { let columns_to_index = split_at_open_bracket[1] .replace(')', "") .split(',') - .map(|column| column.trim().replace('`', "").replace('"', "")) + .map(|column| column.trim().replace(['`', '"'], "")) .collect::>(); Self { @@ -160,7 +162,7 @@ impl From<&SqliteRow> for IndexedColumns { #[cfg(not(feature = "sqlx-sqlite"))] impl From<&SqliteRow> for IndexedColumns { - fn from(row: &SqliteRow) -> Self { + fn from(_: &SqliteRow) -> Self { Self::default() } } @@ -179,7 +181,7 @@ impl From<&SqliteRow> for PrimaryKeyAutoincrement { #[cfg(not(feature = "sqlx-sqlite"))] impl From<&SqliteRow> for PrimaryKeyAutoincrement { - fn from(row: &SqliteRow) -> Self { + fn from(_: &SqliteRow) -> Self { Self::default() } } @@ -225,7 +227,7 @@ impl From<&SqliteRow> for ForeignKeysInfo { #[cfg(not(feature = "sqlx-sqlite"))] impl From<&SqliteRow> for ForeignKeysInfo { - fn from(row: &SqliteRow) -> Self { + fn from(_: &SqliteRow) -> Self { Self::default() } } diff --git a/src/sqlite/def/table.rs b/src/sqlite/def/table.rs index 4bd6bc1a..f69f8c91 100644 --- a/src/sqlite/def/table.rs +++ b/src/sqlite/def/table.rs @@ -6,6 +6,8 @@ use super::{ ColumnInfo, DefaultType, ForeignKeysInfo, IndexInfo, IndexedColumns, PartialIndexInfo, }; use crate::sqlite::{error::DiscoveryResult, executor::Executor}; + +#[allow(unused_imports)] use crate::sqlx_types::{sqlite::SqliteRow, Row}; /// Defines a table for SQLite @@ -38,7 +40,7 @@ impl From<&SqliteRow> for TableDef { #[cfg(not(feature = "sqlx-sqlite"))] /// Gets the table name from a `SqliteRow` and maps it to the [TableDef] impl From<&SqliteRow> for TableDef { - fn from(row: &SqliteRow) -> Self { + fn from(_: &SqliteRow) -> Self { Self::default() } } diff --git a/src/sqlite/executor/mock.rs b/src/sqlite/executor/mock.rs index 2186dbd5..7f7591ef 100644 --- a/src/sqlite/executor/mock.rs +++ b/src/sqlite/executor/mock.rs @@ -3,6 +3,7 @@ use sea_query::{SelectStatement, SqliteQueryBuilder}; use crate::debug_print; +#[allow(dead_code)] pub struct Executor { pool: SqlitePool, } @@ -19,21 +20,21 @@ impl IntoExecutor for SqlitePool { impl Executor { pub async fn fetch_all(&self, select: SelectStatement) -> Vec { - let (sql, values) = select.build(SqliteQueryBuilder); - debug_print!("{}, {:?}", sql, values); + let (_sql, _values) = select.build(SqliteQueryBuilder); + debug_print!("{}, {:?}", _sql, _values); panic!("This is a mock Executor"); } pub async fn fetch_one(&self, select: SelectStatement) -> SqliteRow { - let (sql, values) = select.build(SqliteQueryBuilder); - debug_print!("{}, {:?}", sql, values); + let (_sql, _values) = select.build(SqliteQueryBuilder); + debug_print!("{}, {:?}", _sql, _values); panic!("This is a mock Executor"); } - pub async fn fetch_all_raw(&self, sql: String) -> Vec { - debug_print!("{}", sql); + pub async fn fetch_all_raw(&self, _sql: String) -> Vec { + debug_print!("{}", _sql); panic!("This is a mock Executor"); } diff --git a/tests/discovery/mysql/src/main.rs b/tests/discovery/mysql/src/main.rs index 4dc97625..fed993b3 100644 --- a/tests/discovery/mysql/src/main.rs +++ b/tests/discovery/mysql/src/main.rs @@ -8,8 +8,8 @@ async fn main() { // .is_test(true) // .init(); - let url = - std::env::var("DATABASE_URL_SAKILA").unwrap_or("mysql://root:root@localhost".to_owned()); + let url = std::env::var("DATABASE_URL_SAKILA") + .unwrap_or_else(|_| "mysql://root:root@localhost".to_owned()); let connection = MySqlPool::connect(&url).await.unwrap(); diff --git a/tests/discovery/postgres/src/main.rs b/tests/discovery/postgres/src/main.rs index d4b2c347..6133beef 100644 --- a/tests/discovery/postgres/src/main.rs +++ b/tests/discovery/postgres/src/main.rs @@ -9,7 +9,7 @@ async fn main() { // .init(); let url = std::env::var("DATABASE_URL_SAKILA") - .unwrap_or("postgres://root:root@localhost/sakila".to_owned()); + .unwrap_or_else(|_| "postgres://root:root@localhost/sakila".to_owned()); let connection = PgPool::connect(&url).await.unwrap(); diff --git a/tests/discovery/sqlite/src/main.rs b/tests/discovery/sqlite/src/main.rs index e8ee1973..096efdf1 100644 --- a/tests/discovery/sqlite/src/main.rs +++ b/tests/discovery/sqlite/src/main.rs @@ -4,7 +4,7 @@ use sqlx::SqlitePool; #[async_std::main] async fn main() -> DiscoveryResult<()> { let url = std::env::var("DATABASE_URL_SAKILA") - .unwrap_or("sqlite://tests/sakila/sqlite/sakila.db".to_owned()); + .unwrap_or_else(|_| "sqlite://tests/sakila/sqlite/sakila.db".to_owned()); let connection = SqlitePool::connect(&url).await.unwrap(); diff --git a/tests/live/mysql/src/main.rs b/tests/live/mysql/src/main.rs index 32695113..afcf1d4a 100644 --- a/tests/live/mysql/src/main.rs +++ b/tests/live/mysql/src/main.rs @@ -16,8 +16,8 @@ async fn main() { // .is_test(true) // .init(); - let url = - std::env::var("DATABASE_URL_LIVE").unwrap_or("mysql://root:root@localhost".to_owned()); + let url = std::env::var("DATABASE_URL_LIVE") + .unwrap_or_else(|_| "mysql://root:root@localhost".to_owned()); let connection = setup(&url, "sea-schema").await; let mut executor = connection.acquire().await.unwrap(); diff --git a/tests/live/postgres/src/main.rs b/tests/live/postgres/src/main.rs index 9583234d..e562e2be 100644 --- a/tests/live/postgres/src/main.rs +++ b/tests/live/postgres/src/main.rs @@ -16,8 +16,8 @@ async fn main() { // .is_test(true) // .init(); - let url = - std::env::var("DATABASE_URL_LIVE").unwrap_or("postgres://root:root@localhost".to_owned()); + let url = std::env::var("DATABASE_URL_LIVE") + .unwrap_or_else(|_| "postgres://root:root@localhost".to_owned()); let connection = setup(&url, "sea-schema").await; let mut executor = connection.acquire().await.unwrap(); diff --git a/tests/live/sqlite/src/main.rs b/tests/live/sqlite/src/main.rs index 6c5053ab..da931827 100644 --- a/tests/live/sqlite/src/main.rs +++ b/tests/live/sqlite/src/main.rs @@ -27,7 +27,7 @@ async fn main() -> DiscoveryResult<()> { } async fn test_001() -> DiscoveryResult<()> { - let url = std::env::var("DATABASE_URL_LIVE").unwrap_or("sqlite::memory:".to_owned()); + let url = std::env::var("DATABASE_URL_LIVE").unwrap_or_else(|_| "sqlite::memory:".to_owned()); let sqlite_pool = SqlitePoolOptions::new().connect(&url).await.unwrap(); @@ -240,7 +240,7 @@ async fn test_001() -> DiscoveryResult<()> { } async fn test_002() -> DiscoveryResult<()> { - let url = std::env::var("DATABASE_URL_LIVE").unwrap_or("sqlite::memory:".to_owned()); + let url = std::env::var("DATABASE_URL_LIVE").unwrap_or_else(|_| "sqlite::memory:".to_owned()); let connection = SqlitePool::connect(&url).await.unwrap(); let mut executor = connection.acquire().await.unwrap(); diff --git a/tests/writer/mysql/src/main.rs b/tests/writer/mysql/src/main.rs index af518216..ec2d25ad 100644 --- a/tests/writer/mysql/src/main.rs +++ b/tests/writer/mysql/src/main.rs @@ -9,8 +9,8 @@ async fn main() { // .is_test(true) // .init(); - let url = - std::env::var("DATABASE_URL_SAKILA").unwrap_or("mysql://root:root@localhost".to_owned()); + let url = std::env::var("DATABASE_URL_SAKILA") + .unwrap_or_else(|_| "mysql://root:root@localhost".to_owned()); let connection = MySqlPool::connect(&url).await.unwrap(); diff --git a/tests/writer/postgres/src/main.rs b/tests/writer/postgres/src/main.rs index 28a086a5..33d37793 100644 --- a/tests/writer/postgres/src/main.rs +++ b/tests/writer/postgres/src/main.rs @@ -10,7 +10,7 @@ async fn main() { // .init(); let url = std::env::var("DATABASE_URL_SAKILA") - .unwrap_or("postgres://root:root@localhost/sakila".to_owned()); + .unwrap_or_else(|_| "postgres://root:root@localhost/sakila".to_owned()); let connection = PgPool::connect(&url).await.unwrap(); diff --git a/tests/writer/sqlite/src/main.rs b/tests/writer/sqlite/src/main.rs index cafa24f5..3f88986a 100644 --- a/tests/writer/sqlite/src/main.rs +++ b/tests/writer/sqlite/src/main.rs @@ -5,7 +5,7 @@ use sqlx::sqlite::SqlitePool; #[async_std::main] async fn main() -> DiscoveryResult<()> { let url = std::env::var("DATABASE_URL_SAKILA") - .unwrap_or("sqlite://tests/sakila/sqlite/sakila.db".to_owned()); + .unwrap_or_else(|_| "sqlite://tests/sakila/sqlite/sakila.db".to_owned()); let sqlite_pool = SqlitePool::connect(&url).await.unwrap();