Skip to content

Commit

Permalink
Fix clippy and remove the use of deprecated methods (#98)
Browse files Browse the repository at this point in the history
* Fix clippy and remove the use of deprecated methods

* CI
  • Loading branch information
billy1624 authored Jan 5, 2023
1 parent e4a1d51 commit b19d935
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/mysql/discovery/executor/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use sea_query::{MysqlQueryBuilder, SelectStatement};

use crate::debug_print;

#[allow(dead_code)]
pub struct Executor {
pool: MySqlPool,
}
Expand All @@ -19,8 +20,8 @@ impl IntoExecutor for MySqlPool {

impl Executor {
pub async fn fetch_all(&self, select: SelectStatement) -> Vec<MySqlRow> {
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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/mysql/query/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
14 changes: 7 additions & 7 deletions src/mysql/query/foreign_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
}
}
2 changes: 1 addition & 1 deletion src/mysql/query/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
6 changes: 3 additions & 3 deletions src/mysql/query/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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()
}
}
2 changes: 1 addition & 1 deletion src/mysql/query/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
5 changes: 3 additions & 2 deletions src/postgres/discovery/executor/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use sea_query::{PostgresQueryBuilder, SelectStatement};

use crate::debug_print;

#[allow(dead_code)]
pub struct Executor {
pool: PgPool,
}
Expand All @@ -19,8 +20,8 @@ impl IntoExecutor for PgPool {

impl Executor {
pub async fn fetch_all(&self, select: SelectStatement) -> Vec<PgRow> {
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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/postgres/query/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
24 changes: 12 additions & 12 deletions src/postgres/query/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
),
)
Expand All @@ -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)),
),
)
Expand All @@ -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(
Expand Down Expand Up @@ -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()
}
}
4 changes: 2 additions & 2 deletions src/postgres/query/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}
}
2 changes: 1 addition & 1 deletion src/postgres/query/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
18 changes: 10 additions & 8 deletions src/sqlite/def/column.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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::<i32>() {
DefaultType::Integer(is_int)
Expand All @@ -50,7 +52,7 @@ impl ColumnInfo {

#[cfg(not(feature = "sqlx-sqlite"))]
impl ColumnInfo {
pub fn to_column_def(row: &SqliteRow) -> Result<ColumnInfo, ParseIntError> {
pub fn to_column_def(_: &SqliteRow) -> Result<ColumnInfo, ParseIntError> {
i32::from_str_radix("", 10)?;
unimplemented!()
}
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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::<Vec<String>>();

Self {
Expand All @@ -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()
}
}
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/sqlite/def/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/sqlite/executor/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use sea_query::{SelectStatement, SqliteQueryBuilder};

use crate::debug_print;

#[allow(dead_code)]
pub struct Executor {
pool: SqlitePool,
}
Expand All @@ -19,21 +20,21 @@ impl IntoExecutor for SqlitePool {

impl Executor {
pub async fn fetch_all(&self, select: SelectStatement) -> Vec<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_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<SqliteRow> {
debug_print!("{}", sql);
pub async fn fetch_all_raw(&self, _sql: String) -> Vec<SqliteRow> {
debug_print!("{}", _sql);

panic!("This is a mock Executor");
}
Expand Down
4 changes: 2 additions & 2 deletions tests/discovery/mysql/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tests/discovery/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading

0 comments on commit b19d935

Please sign in to comment.