From 0f2075c380f0f409b28935d4dfc0122911b47d47 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 6 Aug 2025 22:27:50 +0800 Subject: [PATCH 01/38] Enable --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index bf69e0520..5750ec5bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ #![cfg_attr(docsrs, feature(doc_cfg))] -#![warn(clippy::nursery)] +#![warn(clippy::nursery, clippy::pedantic)] #![deny(missing_debug_implementations)] #![forbid(unsafe_code)] #![allow( From 418bed65ba755526a1101cf06fa1973159c51768 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 6 Aug 2025 22:28:01 +0800 Subject: [PATCH 02/38] Auto fix --- tests/mysql/query.rs | 9 +++------ tests/postgres/query.rs | 4 ++-- tests/sqlite/query.rs | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/mysql/query.rs b/tests/mysql/query.rs index 255a00837..b1415a7c9 100644 --- a/tests/mysql/query.rs +++ b/tests/mysql/query.rs @@ -736,7 +736,7 @@ fn select_48() { .from(Glyph::Table) .cond_where( Cond::all().add_option(Some( - Expr::tuple([Expr::col(Glyph::Aspect).into(), Expr::value(100)]) + Expr::tuple([Expr::col(Glyph::Aspect), Expr::value(100)]) .lt(Expr::tuple([Expr::value(8), Expr::value(100)])), )), ) @@ -755,11 +755,8 @@ fn select_48a() { .from(Glyph::Table) .cond_where( Cond::all().add_option(Some( - Expr::tuple([ - Expr::col(Glyph::Aspect).into(), - Expr::value(String::from("100")), - ]) - .in_tuples([(8, String::from("100"))]), + Expr::tuple([Expr::col(Glyph::Aspect), Expr::value(String::from("100"))]) + .in_tuples([(8, String::from("100"))]), )), ) .to_string(MysqlQueryBuilder); diff --git a/tests/postgres/query.rs b/tests/postgres/query.rs index c9ec7d8fe..09a37ed11 100644 --- a/tests/postgres/query.rs +++ b/tests/postgres/query.rs @@ -822,7 +822,7 @@ fn select_48() { .from(Glyph::Table) .cond_where( Cond::all().add_option(Some( - Expr::tuple([Expr::col(Glyph::Aspect).into(), Expr::value(100)]) + Expr::tuple([Expr::col(Glyph::Aspect), Expr::value(100)]) .lt(Expr::tuple([Expr::value(8), Expr::value(100)])), )), ) @@ -842,7 +842,7 @@ fn select_48a() { .cond_where( Cond::all().add_option(Some( Expr::tuple([ - Expr::col(Glyph::Aspect).into(), + Expr::col(Glyph::Aspect), Expr::value(String::from("100")), ]) .in_tuples([(8, String::from("100"))]), diff --git a/tests/sqlite/query.rs b/tests/sqlite/query.rs index 6bb781920..8d82e3196 100644 --- a/tests/sqlite/query.rs +++ b/tests/sqlite/query.rs @@ -737,7 +737,7 @@ fn select_48() { .from(Glyph::Table) .cond_where( Cond::all().add_option(Some( - Expr::tuple([Expr::col(Glyph::Aspect).into(), Expr::value(100)]) + Expr::tuple([Expr::col(Glyph::Aspect), Expr::value(100)]) .lt(Expr::tuple([Expr::value(8), Expr::value(100)])), )), ) @@ -757,7 +757,7 @@ fn select_48a() { .cond_where( Cond::all().add_option(Some( Expr::tuple([ - Expr::col(Glyph::Aspect).into(), + Expr::col(Glyph::Aspect), Expr::value(String::from("100")), ]) .in_tuples([(8, String::from("100"))]), From 02b83d2186e773631b2d1cc28c2412a62b84a06d Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 12:11:47 +0800 Subject: [PATCH 03/38] default_trait_access --- src/func.rs | 4 ++-- src/index/create.rs | 2 +- src/query/insert.rs | 2 +- src/query/on_conflict.rs | 2 +- src/table/column.rs | 2 +- src/value.rs | 1 + 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/func.rs b/src/func.rs index 7c8b8977b..bc5a9b175 100644 --- a/src/func.rs +++ b/src/func.rs @@ -828,7 +828,7 @@ impl FunctionCall { where T: Into, { - self.arg_with(arg, Default::default()) + self.arg_with(arg, FuncArgMod::default()) } pub(crate) fn arg_with(mut self, arg: T, mod_: FuncArgMod) -> Self @@ -846,7 +846,7 @@ impl FunctionCall { I: IntoIterator, { self.args = args.into_iter().collect(); - self.mods = vec![Default::default(); self.args.len()]; + self.mods = vec![FuncArgMod::default(); self.args.len()]; self } diff --git a/src/index/create.rs b/src/index/create.rs index c839f6fb6..f9bd73125 100644 --- a/src/index/create.rs +++ b/src/index/create.rs @@ -235,7 +235,7 @@ impl IndexCreateStatement { pub fn new() -> Self { Self { table: None, - index: Default::default(), + index: TableIndex::default(), primary: false, unique: false, nulls_not_distinct: false, diff --git a/src/query/insert.rs b/src/query/insert.rs index 0e21ec731..74282c345 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -285,7 +285,7 @@ impl InsertStatement { let values_source = if let Some(InsertValueSource::Values(values)) = &mut self.source { values } else { - self.source = Some(InsertValueSource::Values(Default::default())); + self.source = Some(InsertValueSource::Values(Vec::new())); if let Some(InsertValueSource::Values(values)) = &mut self.source { values } else { diff --git a/src/query/on_conflict.rs b/src/query/on_conflict.rs index 05992426c..cc402b367 100644 --- a/src/query/on_conflict.rs +++ b/src/query/on_conflict.rs @@ -39,7 +39,7 @@ impl OnConflict { /// Create a ON CONFLICT expression without target column, /// a special method designed for MySQL pub fn new() -> Self { - Default::default() + Self::default() } /// Set ON CONFLICT target column diff --git a/src/table/column.rs b/src/table/column.rs index 6c2ea2c97..f0baa6e76 100644 --- a/src/table/column.rs +++ b/src/table/column.rs @@ -368,7 +368,7 @@ impl ColumnDef { /// Set column type as string pub fn string(&mut self) -> &mut Self { - self.types = Some(ColumnType::String(Default::default())); + self.types = Some(ColumnType::String(StringLen::default())); self } diff --git a/src/value.rs b/src/value.rs index 9b397b1f4..31f7b8da2 100644 --- a/src/value.rs +++ b/src/value.rs @@ -481,6 +481,7 @@ impl Value { /// let n = v.dummy_value(); /// assert_eq!(n, Value::Int(Some(0))); /// ``` + #[expect(clippy::default_trait_access)] pub fn dummy_value(&self) -> Self { match self { Self::Bool(_) => Self::Bool(Some(Default::default())), From b5ed5333989f95b11b799aabc7a90af66abfac8d Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 12:32:39 +0800 Subject: [PATCH 04/38] unnecessary_literal_bound --- src/backend/mysql/query.rs | 6 +++--- src/backend/mysql/table.rs | 2 +- src/backend/postgres/query.rs | 2 +- src/backend/postgres/table.rs | 2 +- src/backend/query_builder.rs | 14 +++++++------- src/backend/sqlite/query.rs | 6 +++--- src/backend/sqlite/table.rs | 2 +- src/extension/postgres/ltree.rs | 2 +- src/types.rs | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/backend/mysql/query.rs b/src/backend/mysql/query.rs index cbe6d753d..f7809fe37 100644 --- a/src/backend/mysql/query.rs +++ b/src/backend/mysql/query.rs @@ -2,7 +2,7 @@ use super::*; use crate::extension::mysql::*; impl QueryBuilder for MysqlQueryBuilder { - fn values_list_tuple_prefix(&self) -> &str { + fn values_list_tuple_prefix(&self) -> &'static str { "ROW" } @@ -194,11 +194,11 @@ impl QueryBuilder for MysqlQueryBuilder { fn prepare_returning(&self, _returning: &Option, _sql: &mut dyn SqlWriter) {} - fn random_function(&self) -> &str { + fn random_function(&self) -> &'static str { "RAND" } - fn insert_default_keyword(&self) -> &str { + fn insert_default_keyword(&self) -> &'static str { "()" } } diff --git a/src/backend/mysql/table.rs b/src/backend/mysql/table.rs index 8dffd16ab..fc1a12ee2 100644 --- a/src/backend/mysql/table.rs +++ b/src/backend/mysql/table.rs @@ -110,7 +110,7 @@ impl TableBuilder for MysqlQueryBuilder { } } - fn column_spec_auto_increment_keyword(&self) -> &str { + fn column_spec_auto_increment_keyword(&self) -> &'static str { "AUTO_INCREMENT" } diff --git a/src/backend/postgres/query.rs b/src/backend/postgres/query.rs index 62f923919..9f68fd22b 100644 --- a/src/backend/postgres/query.rs +++ b/src/backend/postgres/query.rs @@ -192,7 +192,7 @@ impl QueryBuilder for PostgresQueryBuilder { write!(buffer, "'").unwrap(); } - fn if_null_function(&self) -> &str { + fn if_null_function(&self) -> &'static str { "COALESCE" } } diff --git a/src/backend/postgres/table.rs b/src/backend/postgres/table.rs index f8d3feb5a..4840640f7 100644 --- a/src/backend/postgres/table.rs +++ b/src/backend/postgres/table.rs @@ -87,7 +87,7 @@ impl TableBuilder for PostgresQueryBuilder { .unwrap() } - fn column_spec_auto_increment_keyword(&self) -> &str { + fn column_spec_auto_increment_keyword(&self) -> &'static str { "" } diff --git a/src/backend/query_builder.rs b/src/backend/query_builder.rs index 76d755210..408c66d60 100644 --- a/src/backend/query_builder.rs +++ b/src/backend/query_builder.rs @@ -13,7 +13,7 @@ pub trait QueryBuilder: } /// Prefix for tuples in VALUES list (e.g. ROW for MySQL) - fn values_list_tuple_prefix(&self) -> &str { + fn values_list_tuple_prefix(&self) -> &'static str { "" } @@ -1540,37 +1540,37 @@ pub trait QueryBuilder: #[doc(hidden)] /// The name of the function that represents the "if null" condition. - fn if_null_function(&self) -> &str { + fn if_null_function(&self) -> &'static str { "IFNULL" } #[doc(hidden)] /// The name of the function that represents the "greatest" function. - fn greatest_function(&self) -> &str { + fn greatest_function(&self) -> &'static str { "GREATEST" } #[doc(hidden)] /// The name of the function that represents the "least" function. - fn least_function(&self) -> &str { + fn least_function(&self) -> &'static str { "LEAST" } #[doc(hidden)] /// The name of the function that returns the char length. - fn char_length_function(&self) -> &str { + fn char_length_function(&self) -> &'static str { "CHAR_LENGTH" } #[doc(hidden)] /// The name of the function that returns a random number - fn random_function(&self) -> &str { + fn random_function(&self) -> &'static str { // Returning it with parens as part of the name because the tuple preparer can't deal with empty lists "RANDOM" } /// The keywords for insert default row. - fn insert_default_keyword(&self) -> &str { + fn insert_default_keyword(&self) -> &'static str { "(DEFAULT)" } diff --git a/src/backend/sqlite/query.rs b/src/backend/sqlite/query.rs index 02fdd556b..84286d742 100644 --- a/src/backend/sqlite/query.rs +++ b/src/backend/sqlite/query.rs @@ -76,15 +76,15 @@ impl QueryBuilder for SqliteQueryBuilder { sql.push_param(value, self as _); } - fn greatest_function(&self) -> &str { + fn greatest_function(&self) -> &'static str { "MAX" } - fn least_function(&self) -> &str { + fn least_function(&self) -> &'static str { "MIN" } - fn char_length_function(&self) -> &str { + fn char_length_function(&self) -> &'static str { "LENGTH" } diff --git a/src/backend/sqlite/table.rs b/src/backend/sqlite/table.rs index c821e9bf8..9f2fa91fa 100644 --- a/src/backend/sqlite/table.rs +++ b/src/backend/sqlite/table.rs @@ -42,7 +42,7 @@ impl TableBuilder for SqliteQueryBuilder { self.prepare_column_type(&[], column_type, sql) } - fn column_spec_auto_increment_keyword(&self) -> &str { + fn column_spec_auto_increment_keyword(&self) -> &'static str { "AUTOINCREMENT" } diff --git a/src/extension/postgres/ltree.rs b/src/extension/postgres/ltree.rs index 848308449..64a3a8f9d 100644 --- a/src/extension/postgres/ltree.rs +++ b/src/extension/postgres/ltree.rs @@ -51,7 +51,7 @@ use crate::Iden; pub struct PgLTree; impl Iden for PgLTree { - fn unquoted(&self) -> &str { + fn unquoted(&self) -> &'static str { "ltree" } } diff --git a/src/types.rs b/src/types.rs index 4e2092f9f..4416c56f1 100644 --- a/src/types.rs +++ b/src/types.rs @@ -776,7 +776,7 @@ impl NullAlias { } impl Iden for NullAlias { - fn unquoted(&self) -> &str { + fn unquoted(&self) -> &'static str { "" } } From 15aae439a75755beded4637352467680e14d2494 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:30:02 +0800 Subject: [PATCH 05/38] doc_markdown and typos --- .clippy.toml | 9 +++ src/audit/mod.rs | 8 +- src/expr.rs | 2 +- src/extension/postgres/ltree.rs | 2 +- src/index/create.rs | 2 +- src/query/condition.rs | 2 +- src/query/delete.rs | 4 +- src/query/insert.rs | 5 +- src/query/select.rs | 10 +-- src/query/traits.rs | 2 +- src/query/update.rs | 4 +- src/query/window.rs | 6 +- src/query/with.rs | 136 +++++++++++++++++--------------- src/table/column.rs | 14 ++-- src/table/create.rs | 10 +-- src/types.rs | 5 +- 16 files changed, 121 insertions(+), 100 deletions(-) create mode 100644 .clippy.toml diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 000000000..3795dd22f --- /dev/null +++ b/.clippy.toml @@ -0,0 +1,9 @@ +doc-valid-idents = [ + "SeaQL", + "SeaQuery", + "MySQL", + "SQLite", + "MariaDB", + "PostgreSQL", + "..", +] diff --git a/src/audit/mod.rs b/src/audit/mod.rs index 44e427789..ed72a28c1 100644 --- a/src/audit/mod.rs +++ b/src/audit/mod.rs @@ -71,25 +71,25 @@ impl QueryAccessAudit { .collect() } - /// Warning: this discards the schema part of SchemaTable. + /// Warning: this discards the schema part of [`SchemaTable`]. /// Intended for testing only. pub fn selected_tables(&self) -> Vec { self.filter_table_with_access_type(AccessType::Select) } - /// Warning: this discards the schema part of SchemaTable. + /// Warning: this discards the schema part of [`SchemaTable`]. /// Intended for testing only. pub fn inserted_tables(&self) -> Vec { self.filter_table_with_access_type(AccessType::Insert) } - /// Warning: this discards the schema part of SchemaTable. + /// Warning: this discards the schema part of [`SchemaTable`]. /// Intended for testing only. pub fn updated_tables(&self) -> Vec { self.filter_table_with_access_type(AccessType::Update) } - /// Warning: this discards the schema part of SchemaTable. + /// Warning: this discards the schema part of [`SchemaTable`]. /// Intended for testing only. pub fn deleted_tables(&self) -> Vec { self.filter_table_with_access_type(AccessType::Delete) diff --git a/src/expr.rs b/src/expr.rs index 8c9cf9664..370c4fd28 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1490,7 +1490,7 @@ pub trait ExprTrait: Sized { } /// This generic implementation covers all expression types, -/// including [ColumnRef], [Value], [FunctionCall], [Expr]... +/// including [`ColumnRef`], [Value], [`FunctionCall`], [Expr]... impl ExprTrait for T where T: Into, diff --git a/src/extension/postgres/ltree.rs b/src/extension/postgres/ltree.rs index 64a3a8f9d..5b115c8c5 100644 --- a/src/extension/postgres/ltree.rs +++ b/src/extension/postgres/ltree.rs @@ -5,7 +5,7 @@ use crate::Iden; /// `ltree` stores a raber path which in this struct is represented as the /// tuple's first value. /// -/// # PostcreSQL Reference +/// # PostgreSQL Reference /// /// The following set of SQL statements can be used to create a table with /// a `ltree` column. Here the `ltree` column is called `path`. diff --git a/src/index/create.rs b/src/index/create.rs index f9bd73125..0ceb5abf6 100644 --- a/src/index/create.rs +++ b/src/index/create.rs @@ -299,7 +299,7 @@ impl IndexCreateStatement { /// Set index as full text. /// On MySQL, this is `FULLTEXT`. - /// On PgSQL, this is `GIN`. + /// On PostgreSQL, this is `GIN`. pub fn full_text(&mut self) -> &mut Self { self.index_type(IndexType::FullText) } diff --git a/src/query/condition.rs b/src/query/condition.rs index 2b76d12ac..b263b954f 100644 --- a/src/query/condition.rs +++ b/src/query/condition.rs @@ -535,7 +535,7 @@ pub trait ConditionalStatement { /// ); /// ``` /// - /// Calling multiple times; will be ANDed togother + /// Calling this method multiple times will combine the conditions with AND. /// /// ``` /// use sea_query::{tests_cfg::*, *}; diff --git a/src/query/delete.rs b/src/query/delete.rs index 8d8c9c560..6d5ecaacf 100644 --- a/src/query/delete.rs +++ b/src/query/delete.rs @@ -211,7 +211,7 @@ impl DeleteStatement { self.returning(ReturningClause::All) } - /// Create a [WithQuery] by specifying a [WithClause] to execute this query with. + /// Create a [`WithQuery`] by specifying a [`WithClause`] to execute this query with. /// /// # Examples /// @@ -260,7 +260,7 @@ impl DeleteStatement { clause.query(self) } - /// Create a Common Table Expression by specifying a [CommonTableExpression] or [WithClause] to execute this query with. + /// Create a Common Table Expression by specifying a [`CommonTableExpression`](crate::CommonTableExpression) or [`WithClause`] to execute this query with. /// /// # Examples /// diff --git a/src/query/insert.rs b/src/query/insert.rs index 74282c345..ecdb2fac6 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -197,6 +197,7 @@ impl InsertStatement { /// r#"INSERT INTO "glyph" ("image") SELECT 'hello' WHERE NOT EXISTS(SELECT 'world')"# /// ); /// ``` + /// ``` /// use sea_query::{audit::*, tests_cfg::*, *}; /// let query = Query::insert() /// .into_table(Glyph::Table) @@ -483,7 +484,7 @@ impl InsertStatement { self.returning(ReturningClause::All) } - /// Create a [WithQuery] by specifying a [WithClause] to execute this query with. + /// Create a [`WithQuery`] by specifying a [`WithClause`] to execute this query with. /// /// # Examples /// @@ -531,7 +532,7 @@ impl InsertStatement { clause.query(self) } - /// Create a Common Table Expression by specifying a [CommonTableExpression] or [WithClause] to execute this query with. + /// Create a Common Table Expression by specifying a [`CommonTableExpression`](crate::CommonTableExpression) or [`WithClause`] to execute this query with. /// /// # Examples /// diff --git a/src/query/select.rs b/src/query/select.rs index ddae04b62..903731d68 100644 --- a/src/query/select.rs +++ b/src/query/select.rs @@ -75,7 +75,7 @@ pub enum SelectDistinct { #[derive(Debug, Clone, PartialEq)] #[non_exhaustive] pub enum WindowSelectType { - /// Name in [`SelectStatement`] + /// Name in [[`SelectStatement`]] Name(DynIden), /// Inline query in [`SelectExpr`] Query(WindowStatement), @@ -2227,7 +2227,7 @@ impl SelectStatement { self.lock(LockType::Update) } - /// Union with another SelectStatement that must have the same selected fields. + /// Union with another [`SelectStatement`] that must have the same selected fields. /// /// # Examples /// @@ -2268,7 +2268,7 @@ impl SelectStatement { self } - /// Union with multiple SelectStatement that must have the same selected fields. + /// Union with multiple [`SelectStatement`] that must have the same selected fields. /// /// # Examples /// @@ -2317,7 +2317,7 @@ impl SelectStatement { self } - /// Create a [WithQuery] by specifying a [WithClause] to execute this query with. + /// Create a [`WithQuery`] by specifying a [`WithClause`] to execute this query with. /// /// # Examples /// @@ -2387,7 +2387,7 @@ impl SelectStatement { clause.query(self) } - /// Create a Common Table Expression by specifying a [CommonTableExpression] or [WithClause] to execute this query with. + /// Create a Common Table Expression by specifying a [`CommonTableExpression`](crate::CommonTableExpression) or [`WithClause`] to execute this query with. /// /// # Examples /// diff --git a/src/query/traits.rs b/src/query/traits.rs index 3e854f09c..8eeb7f9ae 100644 --- a/src/query/traits.rs +++ b/src/query/traits.rs @@ -21,7 +21,7 @@ pub trait QueryStatementBuilder: Debug + Into { sql.to_string() } - /// Build corresponding SQL statement into the SqlWriter for certain database backend and collect query parameters + /// Build corresponding SQL statement into the [`SqlWriter`] for certain database backend and collect query parameters fn build_collect_any_into(&self, query_builder: &dyn QueryBuilder, sql: &mut dyn SqlWriter); fn into_sub_query_statement(self) -> SubQueryStatement { diff --git a/src/query/update.rs b/src/query/update.rs index b22011923..f1fc47e66 100644 --- a/src/query/update.rs +++ b/src/query/update.rs @@ -350,7 +350,7 @@ impl UpdateStatement { self.returning(ReturningClause::All) } - /// Create a [WithQuery] by specifying a [WithClause] to execute this query with. + /// Create a [`WithQuery`] by specifying a [`WithClause`] to execute this query with. /// /// # Examples /// @@ -400,7 +400,7 @@ impl UpdateStatement { clause.query(self) } - /// Create a Common Table Expression by specifying a [CommonTableExpression] or [WithClause] to execute this query with. + /// Create a Common Table Expression by specifying a [`CommonTableExpression`](crate::CommonTableExpression) or [`WithClause`] to execute this query with. /// /// # Examples /// diff --git a/src/query/window.rs b/src/query/window.rs index c69078d21..e925eabf4 100644 --- a/src/query/window.rs +++ b/src/query/window.rs @@ -39,7 +39,7 @@ pub trait OverStatement { } } -/// frame_start or frame_end clause +/// `frame_start` or `frame_end` clause #[derive(Debug, Clone, PartialEq)] pub enum Frame { UnboundedPreceding, @@ -112,7 +112,7 @@ impl WindowStatement { window } - /// frame clause for frame_start + /// frame clause for `frame_start` /// # Examples: /// /// ``` @@ -145,7 +145,7 @@ impl WindowStatement { self.frame(r#type, start, None) } - /// frame clause for BETWEEN frame_start AND frame_end + /// frame clause for BETWEEN `frame_start` AND `frame_end` /// /// # Examples: /// diff --git a/src/query/with.rs b/src/query/with.rs index dcbc79356..6ec8f2687 100644 --- a/src/query/with.rs +++ b/src/query/with.rs @@ -5,26 +5,26 @@ use crate::{ }; use inherent::inherent; -/// A table definition inside a WITH clause ([WithClause]). +/// A table definition inside a WITH clause ([`WithClause`]). /// -/// A WITH clause can contain one or multiple common table expressions ([CommonTableExpression]). +/// A WITH clause can contain one or multiple common table expressions ([`CommonTableExpression`]). /// /// These named queries can act as a "query local table" that are materialized during execution and /// then can be used by the query prefixed with the WITH clause. /// -/// A WITH clause can contain multiple of these [CommonTableExpression]. (Except in the case of -/// recursive WITH query which can only contain one [CommonTableExpression]). +/// A WITH clause can contain multiple of these [`CommonTableExpression`]. (Except in the case of +/// recursive WITH query which can only contain one [`CommonTableExpression`]). /// -/// A [CommonTableExpression] is a name, column names and a query returning data for those columns. +/// A [`CommonTableExpression`] is a name, column names and a query returning data for those columns. /// /// Some databases (like sqlite) restrict the acceptable kinds of queries inside of the WITH clause -/// common table expressions. These databases only allow [SelectStatement]s to form a common table +/// common table expressions. These databases only allow [`SelectStatement`]s to form a common table /// expression. /// /// Other databases like postgres allow modification queries (UPDATE, DELETE) inside of the WITH /// clause but they have to return a table. (They must have a RETURNING clause). /// -/// sea-query doesn't check this or restrict the kind of [CommonTableExpression] that you can create +/// sea-query doesn't check this or restrict the kind of [`CommonTableExpression`] that you can create /// in rust. This means that you can put an UPDATE or DELETE queries into WITH clause and sea-query /// will succeed in generating that kind of sql query but the execution inside the database will /// fail because they are invalid. @@ -33,7 +33,7 @@ use inherent::inherent; /// sense and valid for that database that you are using. /// /// NOTE that for recursive WITH queries (in sql: "WITH RECURSIVE") you can only have a -/// single [CommonTableExpression] inside of the WITH clause. That query must match certain +/// single [`CommonTableExpression`] inside of the WITH clause. That query must match certain /// requirements: /// * It is a query of UNION or UNION ALL of two queries. /// * The first part of the query (the left side of the UNION) must be executable first in itself. @@ -41,11 +41,14 @@ use inherent::inherent; /// * The self reference must appear in the right hand side of the UNION. /// * The query can only have a single self-reference. /// * Recursive data-modifying statements are not supported, but you can use the results of a -/// recursive SELECT query in a data-modifying statement. (like so: WITH RECURSIVE -/// cte_name(a,b,c,d) AS (SELECT ... UNION SELECT ... FROM ... JOIN cte_name ON ... WHERE ...) -/// DELETE FROM table WHERE table.a = cte_name.a) -/// -/// It is mandatory to set the [Self::table_name] and the [Self::query]. +/// recursive SELECT query in a data-modifying statement. +/// like so: +/// ```sql +/// WITH RECURSIVE +/// cte_name(a,b,c,d) AS (SELECT ... UNION SELECT ... FROM ... JOIN cte_name ON ... WHERE ...) +/// DELETE FROM table WHERE table.a = cte_name.a +/// ``` +/// It is mandatory to set the [`Self::table_name`] the [`Self::query`]. #[derive(Debug, Clone, Default, PartialEq)] pub struct CommonTableExpression { pub(crate) table_name: Option, @@ -90,7 +93,7 @@ impl CommonTableExpression { } /// Some databases allow you to put "MATERIALIZED" or "NOT MATERIALIZED" in the CTE definition. - /// This will affect how during the execution of [WithQuery] the CTE in the [WithClause] will be + /// This will affect how during the execution of [`WithQuery`] the CTE in the [`WithClause`] will be /// executed. If the database doesn't support this syntax this option specified here will be /// ignored and not appear in the generated sql. pub fn materialized(&mut self, materialized: bool) -> &mut Self { @@ -129,7 +132,7 @@ impl CommonTableExpression { self.table_name = Some(format!("cte_{iden}").into_iden()) } - /// Set up the columns of the CTE to match the given [SelectStatement] selected columns. + /// Set up the columns of the CTE to match the given [`SelectStatement`] selected columns. /// This will fail if the select contains non named columns like expressions of wildcards. /// /// Returns true if the column setup from the select query was successful. If the returned @@ -172,7 +175,7 @@ impl CommonTableExpression { } } -/// For recursive [WithQuery] [WithClause]s the traversing order can be specified in some databases +/// For recursive [`WithQuery`] [`WithClause`]s the traversing order can be specified in some databases /// that support this functionality. #[derive(Debug, Clone, PartialEq)] #[non_exhaustive] @@ -183,16 +186,16 @@ pub enum SearchOrder { DEPTH, } -/// For recursive [WithQuery] [WithClause]s the traversing order can be specified in some databases +/// For recursive [`WithQuery`] [`WithClause`]s the traversing order can be specified in some databases /// that support this functionality. /// -/// The clause contains the type of traversal: [SearchOrder] and the expression that is used to +/// The clause contains the type of traversal: [`SearchOrder`] and the expression that is used to /// construct the current path. /// /// A query can have both SEARCH and CYCLE clauses. /// -/// Setting [Self::order] and [Self::expr] is mandatory. The [SelectExpr] used must specify an alias -/// which will be the name that you can use to order the result of the [CommonTableExpression]. +/// Setting [`Self::order`] and [`Self::expr`] is mandatory. The [`SelectExpr`] used must specify an alias +/// which will be the name that you can use to order the result of the [`CommonTableExpression`]. #[derive(Debug, Clone, Default, PartialEq)] pub struct Search { pub(crate) order: Option, @@ -200,8 +203,8 @@ pub struct Search { } impl Search { - /// Create a complete [Search] specification from the [SearchOrder] and a [SelectExpr]. The - /// given [SelectExpr] must have an alias specified. + /// Create a complete [Search] specification from the [`SearchOrder`] and a [`SelectExpr`]. The + /// given [`SelectExpr`] must have an alias specified. pub fn new_from_order_and_expr(order: SearchOrder, expr: EXPR) -> Self where EXPR: Into, @@ -225,11 +228,11 @@ impl Search { self } - /// The given [SelectExpr] must have an alias specified. + /// The given [`SelectExpr`] must have an alias specified. /// /// The actual expression will be the one used to track the path in the graph. /// - /// The alias of the given [SelectExpr] will be the name of the order column generated by this + /// The alias of the given [`SelectExpr`] will be the name of the order column generated by this /// clause. pub fn expr(&mut self, expr: EXPR) -> &mut Self where @@ -242,14 +245,14 @@ impl Search { } } -/// For recursive [WithQuery] [WithClauses](WithClause) the CYCLE sql clause can be specified to avoid creating +/// For recursive [`WithQuery`] [`WithClauses`](WithClause) the CYCLE sql clause can be specified to avoid creating /// an infinite traversals that loops on graph cycles indefinitely. /// /// You specify an expression that identifies a node in the graph, which is used during the query execution iteration, to determine newly appended values are distinct new nodes or are already visited, and therefore they should be added into the result again. /// /// A query can have both SEARCH and CYCLE clauses. /// -/// Setting [Self::set], [Self::expr] and [Self::using] is mandatory. +/// Setting [`Self::set`], [`Self::expr`] and [`Self::using`] is mandatory. #[derive(Debug, Clone, Default, PartialEq)] pub struct Cycle { pub(crate) expr: Option, @@ -258,8 +261,8 @@ pub struct Cycle { } impl Cycle { - /// Create a complete [Search] specification from the [SearchOrder] and a [SelectExpr]. The - /// given [SelectExpr] must have an alias specified. + /// Create a complete [Search] specification from the [`SearchOrder`] and a [`SelectExpr`]. The + /// given [`SelectExpr`] must have an alias specified. pub fn new_from_expr_set_using(expr: EXPR, set: ID1, using: ID2) -> Self where EXPR: Into, @@ -298,7 +301,7 @@ impl Cycle { } /// The name of the array typed column that contains the node ids (generated using the - /// [Self::expr]) that specify the current nodes path that will be generated by this clause. + /// [`Self::expr`]) that specify the current nodes path that will be generated by this clause. pub fn using(&mut self, using: ID) -> &mut Self where ID: IntoIden, @@ -308,26 +311,26 @@ impl Cycle { } } -/// A WITH clause can contain one or multiple common table expressions ([CommonTableExpression]). +/// A WITH clause can contain one or multiple common table expressions ([`CommonTableExpression`]). /// -/// You can use this to generate [WithQuery] by calling [WithClause::query]. +/// You can use this to generate [`WithQuery`] by calling [`WithClause::query`]. /// /// These named queries can act as a "query local table" that are materialized during execution and /// then can be used by the query prefixed with the WITH clause. /// -/// A WITH clause can contain multiple of these [CommonTableExpression]. (Except in the case of -/// recursive WITH query which can only contain one [CommonTableExpression]). +/// A WITH clause can contain multiple of these [`CommonTableExpression`]. (Except in the case of +/// recursive WITH query which can only contain one [`CommonTableExpression`]). /// -/// A [CommonTableExpression] is a name, column names and a query returning data for those columns. +/// A [`CommonTableExpression`] is a name, column names and a query returning data for those columns. /// /// Some databases (like sqlite) restrict the acceptable kinds of queries inside of the WITH clause -/// common table expressions. These databases only allow [SelectStatement]s to form a common table +/// common table expressions. These databases only allow [`SelectStatement`]s to form a common table /// expression. /// /// Other databases like postgres allow modification queries (UPDATE, DELETE) inside of the WITH /// clause but they have to return a table. (They must have a RETURNING clause). /// -/// sea-query doesn't check this or restrict the kind of [CommonTableExpression] that you can create +/// sea-query doesn't check this or restrict the kind of [`CommonTableExpression`] that you can create /// in rust. This means that you can put an UPDATE or DELETE queries into WITH clause and sea-query /// will succeed in generating that kind of sql query but the execution inside the database will /// fail because they are invalid. @@ -336,7 +339,7 @@ impl Cycle { /// sense and valid for that database that you are using. /// /// NOTE that for recursive WITH queries (in sql: "WITH RECURSIVE") you can only have a -/// single [CommonTableExpression] inside of the WITH clause. That query must match certain +/// single [`CommonTableExpression`] inside of the WITH clause. That query must match certain /// requirements: /// * It is a query of UNION or UNION ALL of two queries. /// * The first part of the query (the left side of the UNION) must be executable first in itself. @@ -344,11 +347,14 @@ impl Cycle { /// * The self reference must appear in the right hand side of the UNION. /// * The query can only have a single self-reference. /// * Recursive data-modifying statements are not supported, but you can use the results of a -/// recursive SELECT query in a data-modifying statement. (like so: WITH RECURSIVE -/// cte_name(a,b,c,d) AS (SELECT ... UNION SELECT ... FROM ... JOIN cte_name ON ... WHERE ...) -/// DELETE FROM table WHERE table.a = cte_name.a) +/// recursive SELECT query in a data-modifying statement. like so: +/// ```sql +/// WITH RECURSIVE +/// cte_name(a,b,c,d) AS (SELECT ... UNION SELECT ... FROM ... JOIN cte_name ON ... WHERE ...) +/// DELETE FROM table WHERE table.a = cte_name.a +/// ``` +/// It is mandatory to set the [`Self::cte`]. With queries must have at least one CTE. /// -/// It is mandatory to set the [Self::cte]. With queries must have at least one CTE. /// Recursive with query generation will panic if you specify more than one CTE. /// /// # Examples @@ -431,7 +437,7 @@ impl WithClause { /// Sets whether this clause is a recursive with clause of not. /// If set to true it will generate a 'WITH RECURSIVE' query. /// - /// You can only specify a single [CommonTableExpression] containing a union query + /// You can only specify a single [`CommonTableExpression`] containing a union query /// if this is set to true. pub fn recursive(&mut self, recursive: bool) -> &mut Self { self.recursive = recursive; @@ -458,13 +464,13 @@ impl WithClause { self } - /// Add a [CommonTableExpression] to this with clause. + /// Add a [`CommonTableExpression`] to this with clause. pub fn cte(&mut self, cte: CommonTableExpression) -> &mut Self { self.cte_expressions.push(cte); self } - /// You can turn this into a [WithQuery] using this function. The resulting WITH query will + /// You can turn this into a [`WithQuery`] using this function. The resulting WITH query will /// execute the argument query with this WITH clause. pub fn query(self, query: T) -> WithQuery where @@ -480,26 +486,26 @@ impl From for WithClause { } } -/// A WITH query. A simple SQL query that has a WITH clause ([WithClause]). +/// A WITH query. A simple SQL query that has a WITH clause ([`WithClause`]). /// -/// The [WithClause] can contain one or multiple common table expressions ([CommonTableExpression]). +/// The [`WithClause`] can contain one or multiple common table expressions ([`CommonTableExpression`]). /// /// These named queries can act as a "query local table" that are materialized during execution and /// then can be used by the query prefixed with the WITH clause. /// -/// A WITH clause can contain multiple of these [CommonTableExpression]. (Except in the case of -/// recursive WITH query which can only contain one [CommonTableExpression]). +/// A WITH clause can contain multiple of these [`CommonTableExpression`]. (Except in the case of +/// recursive WITH query which can only contain one [`CommonTableExpression`]). /// -/// A [CommonTableExpression] is a name, column names and a query returning data for those columns. +/// A [`CommonTableExpression`] is a name, column names and a query returning data for those columns. /// /// Some databases (like sqlite) restrict the acceptable kinds of queries inside of the WITH clause -/// common table expressions. These databases only allow [SelectStatement]s to form a common table +/// common table expressions. These databases only allow [`SelectStatement`]s to form a common table /// expression. /// /// Other databases like postgres allow modification queries (UPDATE, DELETE) inside of the WITH /// clause but they have to return a table. (They must have a RETURNING clause). /// -/// sea-query doesn't check this or restrict the kind of [CommonTableExpression] that you can create +/// sea-query doesn't check this or restrict the kind of [`CommonTableExpression`] that you can create /// in rust. This means that you can put an UPDATE or DELETE queries into WITH clause and sea-query /// will succeed in generating that kind of sql query but the execution inside the database will /// fail because they are invalid. @@ -508,7 +514,7 @@ impl From for WithClause { /// sense and valid for that database that you are using. /// /// NOTE that for recursive WITH queries (in sql: "WITH RECURSIVE") you can only have a -/// single [CommonTableExpression] inside of the WITH clause. That query must match certain +/// single [`CommonTableExpression`] inside of the WITH clause. That query must match certain /// requirements: /// * It is a query of UNION or UNION ALL of two queries. /// * The first part of the query (the left side of the UNION) must be executable first in itself. @@ -516,11 +522,15 @@ impl From for WithClause { /// * The self reference must appear in the right hand side of the UNION. /// * The query can only have a single self-reference. /// * Recursive data-modifying statements are not supported, but you can use the results of a -/// recursive SELECT query in a data-modifying statement. (like so: WITH RECURSIVE -/// cte_name(a,b,c,d) AS (SELECT ... UNION SELECT ... FROM ... JOIN cte_name ON ... WHERE ...) -/// DELETE FROM table WHERE table.a = cte_name.a) -/// -/// It is mandatory to set the [Self::cte] and the [Self::query]. +/// recursive SELECT query in a data-modifying statement. +/// like so: +/// ```sql +/// WITH RECURSIVE +/// cte_name(a,b,c,d) AS (SELECT ... UNION SELECT ... FROM ... JOIN cte_name ON ... WHERE ...) +/// DELETE FROM table WHERE table.a = cte_name.a +/// ``` +/// +/// It is mandatory to set the [`Self::cte`] and the [`Self::query`]. #[derive(Debug, Clone, Default, PartialEq)] pub struct WithQuery { pub(crate) with_clause: WithClause, @@ -533,37 +543,37 @@ impl WithQuery { Self::default() } - /// Set the whole [WithClause]. + /// Set the whole [`WithClause`]. pub fn with_clause(&mut self, with_clause: WithClause) -> &mut Self { self.with_clause = with_clause; self } - /// Set the [WithClause::recursive]. See that method for more information. + /// Set the [`WithClause::recursive`]. See that method for more information. pub fn recursive(&mut self, recursive: bool) -> &mut Self { self.with_clause.recursive = recursive; self } - /// Add the [WithClause::search]. See that method for more information. + /// Add the [`WithClause::search`]. See that method for more information. pub fn search(&mut self, search: Search) -> &mut Self { self.with_clause.search = Some(search); self } - /// Set the [WithClause::cycle]. See that method for more information. + /// Set the [`WithClause::cycle`]. See that method for more information. pub fn cycle(&mut self, cycle: Cycle) -> &mut Self { self.with_clause.cycle = Some(cycle); self } - /// Add a [CommonTableExpression] to the with clause. See [WithClause::cte]. + /// Add a [`CommonTableExpression`] to the with clause. See [`WithClause::cte`]. pub fn cte(&mut self, cte: CommonTableExpression) -> &mut Self { self.with_clause.cte_expressions.push(cte); self } - /// Set the query that you execute with the [WithClause]. + /// Set the query that you execute with the [`WithClause`]. pub fn query(&mut self, query: T) -> &mut Self where T: Into, diff --git a/src/table/column.rs b/src/table/column.rs index f0baa6e76..03bae5b2d 100644 --- a/src/table/column.rs +++ b/src/table/column.rs @@ -378,13 +378,13 @@ impl ColumnDef { self } - /// Set column type as tiny_integer + /// Set column type as tiny integer pub fn tiny_integer(&mut self) -> &mut Self { self.types = Some(ColumnType::TinyInteger); self } - /// Set column type as small_integer + /// Set column type as small integer pub fn small_integer(&mut self) -> &mut Self { self.types = Some(ColumnType::SmallInteger); self @@ -396,19 +396,19 @@ impl ColumnDef { self } - /// Set column type as big_integer + /// Set column type as big integer pub fn big_integer(&mut self) -> &mut Self { self.types = Some(ColumnType::BigInteger); self } - /// Set column type as tiny_unsigned + /// Set column type as tiny unsigned pub fn tiny_unsigned(&mut self) -> &mut Self { self.types = Some(ColumnType::TinyUnsigned); self } - /// Set column type as small_unsigned + /// Set column type as small unsigned pub fn small_unsigned(&mut self) -> &mut Self { self.types = Some(ColumnType::SmallUnsigned); self @@ -420,7 +420,7 @@ impl ColumnDef { self } - /// Set column type as big_unsigned + /// Set column type as big unsigned pub fn big_unsigned(&mut self) -> &mut Self { self.types = Some(ColumnType::BigUnsigned); self @@ -450,7 +450,7 @@ impl ColumnDef { self } - /// Set column type as date_time + /// Set column type as date time pub fn date_time(&mut self) -> &mut Self { self.types = Some(ColumnType::DateTime); self diff --git a/src/table/create.rs b/src/table/create.rs index 3dc1049a4..51fe129d5 100644 --- a/src/table/create.rs +++ b/src/table/create.rs @@ -300,7 +300,7 @@ impl TableCreateStatement { } /// Rewriting extra param. You should take care self about concat extra params. Add extra after options. - /// Example for PostgresSQL [Citus](https://github.com/citusdata/citus) extension: + /// Example for PostgreSQL [Citus](https://github.com/citusdata/citus) extension: /// ``` /// use sea_query::{tests_cfg::*, *}; /// let table = Table::create() @@ -348,10 +348,10 @@ impl TableCreateStatement { /// Create temporary table /// /// Ref: - /// - PostgreSQL: https://www.postgresql.org/docs/17/sql-createtable.html#SQL-CREATETABLE-TEMPORARY - /// - MySQL: https://dev.mysql.com/doc/refman/9.2/en/create-temporary-table.html - /// - MariaDB: https://mariadb.com/kb/en/create-table/#create-temporary-table - /// - SQLite: https://sqlite.org/lang_createtable.html + /// - PostgreSQL: + /// - MySQL: + /// - MariaDB: + /// - SQLite: /// /// # Examples /// diff --git a/src/types.rs b/src/types.rs index 4416c56f1..d893a64ce 100644 --- a/src/types.rs +++ b/src/types.rs @@ -28,12 +28,12 @@ pub struct Quote(pub(crate) u8, pub(crate) u8); pub trait Iden { /// Return the to-be sanitized version of the identifier. /// - /// For example, for MySQL "hel`lo`" would have to be escaped as "hel``lo". + /// For example, for MySQL "hel\`lo\`" would have to be escaped as "hel\`\`lo". /// Note that this method doesn't do the actual escape, /// as it's backend specific. /// It only indicates whether the identifier needs to be escaped. /// - /// If the identifier doesn't need to be escaped, return `'static str`. + /// If the identifier doesn't need to be escaped, return `&'static str`. /// This can be deduced at compile-time by the `Iden` macro, /// or using the [`is_static_iden`] function. /// @@ -440,6 +440,7 @@ pub trait IntoLikeExpr { fn into_like_expr(self) -> LikeExpr; } +#[expect(clippy::doc_markdown)] /// SubQuery operators #[derive(Debug, Copy, Clone, PartialEq)] #[non_exhaustive] From edae14fc32b52ff209b36e6a86282cb760c2d1ee Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:33:01 +0800 Subject: [PATCH 06/38] needless_pass_by_value --- src/query/window.rs | 2 +- src/table/column.rs | 4 ++-- src/types.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/query/window.rs b/src/query/window.rs index e925eabf4..420ce6193 100644 --- a/src/query/window.rs +++ b/src/query/window.rs @@ -103,7 +103,7 @@ impl WindowStatement { } /// Construct a new [`WindowStatement`] with PARTITION BY custom - pub fn partition_by_custom(col: T) -> Self + pub fn partition_by_custom(col: &T) -> Self where T: ToString, { diff --git a/src/table/column.rs b/src/table/column.rs index 03bae5b2d..5715892e3 100644 --- a/src/table/column.rs +++ b/src/table/column.rs @@ -187,7 +187,7 @@ pub enum ColumnSpec { } // All interval fields -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, Copy, Eq, PartialEq)] #[non_exhaustive] pub enum PgInterval { Year, @@ -206,7 +206,7 @@ pub enum PgInterval { } // All possible inputs to DATE_TRUNC (https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC) -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, Copy, Eq, PartialEq)] #[non_exhaustive] pub enum PgDateTruncUnit { Microseconds, diff --git a/src/types.rs b/src/types.rs index d893a64ce..0cae80049 100644 --- a/src/types.rs +++ b/src/types.rs @@ -100,7 +100,7 @@ impl SeaRc { /// Note that most `Iden`s are statically known /// and their representations aren't actually "rendered" and allocated at runtime. #[allow(clippy::new_ret_no_self)] - pub fn new(i: I) -> DynIden + pub fn new(i: &I) -> DynIden where I: Iden, { From 22d16dffca74d40b8b8bd7f1785416ce83bec93d Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:38:51 +0800 Subject: [PATCH 07/38] match_same_arms --- src/audit/common.rs | 6 +++--- src/audit/select.rs | 19 ++++++++++--------- src/backend/mysql/table.rs | 12 +++--------- src/backend/postgres/table.rs | 12 +++++++----- src/backend/sqlite/table.rs | 7 +------ src/table/column.rs | 14 ++++++-------- src/token.rs | 19 +++++-------------- 7 files changed, 35 insertions(+), 54 deletions(-) diff --git a/src/audit/common.rs b/src/audit/common.rs index e3d8ad0e9..52e8acef6 100644 --- a/src/audit/common.rs +++ b/src/audit/common.rs @@ -3,9 +3,9 @@ use crate::TableRef; pub(super) fn parse_audit_table(table_ref: &TableRef) -> Option { match table_ref { - TableRef::SubQuery(_, _) => None, - TableRef::FunctionCall(_, _) => None, TableRef::Table(tbl, _) => Some(tbl.clone()), - TableRef::ValuesList(_, _) => None, + TableRef::ValuesList(_, _) | TableRef::FunctionCall(_, _) | TableRef::SubQuery(_, _) => { + None + } } } diff --git a/src/audit/select.rs b/src/audit/select.rs index 681d7a3ea..e2f739f02 100644 --- a/src/audit/select.rs +++ b/src/audit/select.rs @@ -109,7 +109,6 @@ impl Walker { fn recurse_audit_expr(&mut self, expr: &Expr) -> Result<(), Error> { match expr { - Expr::Column(_) => (), Expr::Unary(_, expr) | Expr::AsEnum(_, expr) => self.recurse_audit_expr(expr)?, Expr::FunctionCall(function) => self.recurse_audit_function(function)?, Expr::Binary(left, _, right) => { @@ -117,18 +116,19 @@ impl Walker { self.recurse_audit_expr(right)?; } Expr::SubQuery(_, subquery) => self.recurse_audit_subquery(subquery)?, - Expr::Value(_) => (), - Expr::Values(_) => (), - Expr::Custom(_) => (), Expr::CustomWithExpr(_, exprs) | Expr::Tuple(exprs) => { for expr in exprs { self.recurse_audit_expr(expr)?; } } - Expr::Keyword(_) => (), Expr::Case(case) => self.recurse_audit_case(case)?, - Expr::Constant(_) => (), - Expr::TypeName(_) => (), + Expr::Value(_) + | Expr::Column(_) + | Expr::Values(_) + | Expr::Custom(_) + | Expr::Keyword(_) + | Expr::Constant(_) + | Expr::TypeName(_) => (), } Ok(()) } @@ -213,8 +213,9 @@ impl Walker { ConditionHolderContents::Chain(chain) => { for oper in chain { match oper { - LogicalChainOper::And(expr) => self.recurse_audit_expr(expr)?, - LogicalChainOper::Or(expr) => self.recurse_audit_expr(expr)?, + LogicalChainOper::Or(expr) | LogicalChainOper::And(expr) => { + self.recurse_audit_expr(expr)? + } } } } diff --git a/src/backend/mysql/table.rs b/src/backend/mysql/table.rs index fc1a12ee2..c5fc66151 100644 --- a/src/backend/mysql/table.rs +++ b/src/backend/mysql/table.rs @@ -45,13 +45,12 @@ impl TableBuilder for MysqlQueryBuilder { ColumnType::BigInteger | ColumnType::BigUnsigned => "bigint".into(), ColumnType::Float => "float".into(), ColumnType::Double => "double".into(), - ColumnType::Decimal(precision) => match precision { + ColumnType::Decimal(precision) | ColumnType::Money(precision) => match precision { Some((precision, scale)) => format!("decimal({precision}, {scale})"), None => "decimal".into(), }, ColumnType::DateTime => "datetime".into(), - ColumnType::Timestamp => "timestamp".into(), - ColumnType::TimestampWithTimeZone => "timestamp".into(), + ColumnType::Timestamp | ColumnType::TimestampWithTimeZone => "timestamp".into(), ColumnType::Time => "time".into(), ColumnType::Date => "date".into(), ColumnType::Year => "year".into(), @@ -73,12 +72,7 @@ impl TableBuilder for MysqlQueryBuilder { format!("bit({length})") } ColumnType::Boolean => "bool".into(), - ColumnType::Money(precision) => match precision { - Some((precision, scale)) => format!("decimal({precision}, {scale})"), - None => "decimal".into(), - }, - ColumnType::Json => "json".into(), - ColumnType::JsonBinary => "json".into(), + ColumnType::Json | ColumnType::JsonBinary => "json".into(), ColumnType::Uuid => "binary(16)".into(), ColumnType::Custom(iden) => iden.to_string(), ColumnType::Enum { variants, .. } => format!( diff --git a/src/backend/postgres/table.rs b/src/backend/postgres/table.rs index 4840640f7..f7736ea75 100644 --- a/src/backend/postgres/table.rs +++ b/src/backend/postgres/table.rs @@ -22,8 +22,10 @@ impl TableBuilder for PostgresQueryBuilder { _ => "varchar".into(), }, ColumnType::Text => "text".into(), - ColumnType::TinyInteger | ColumnType::TinyUnsigned => "smallint".into(), - ColumnType::SmallInteger | ColumnType::SmallUnsigned => "smallint".into(), + ColumnType::TinyInteger + | ColumnType::TinyUnsigned + | ColumnType::SmallInteger + | ColumnType::SmallUnsigned => "smallint".into(), ColumnType::Integer | ColumnType::Unsigned => "integer".into(), ColumnType::BigInteger | ColumnType::BigUnsigned => "bigint".into(), ColumnType::Float => "real".into(), @@ -151,7 +153,6 @@ impl TableBuilder for PostgresQueryBuilder { write!(sql, ", ").unwrap(); } match column_spec { - ColumnSpec::AutoIncrement => {} ColumnSpec::Null => { write!(sql, "ALTER COLUMN ").unwrap(); self.prepare_iden(&column_def.name, sql); @@ -179,13 +180,14 @@ impl TableBuilder for PostgresQueryBuilder { write!(sql, ")").unwrap(); } ColumnSpec::Check(check) => self.prepare_check_constraint(check, sql), - ColumnSpec::Generated { .. } => {} ColumnSpec::Extra(string) => write!(sql, "{string}").unwrap(), - ColumnSpec::Comment(_) => {} ColumnSpec::Using(expr) => { write!(sql, " USING ").unwrap(); QueryBuilder::prepare_simple_expr(self, expr, sql); } + ColumnSpec::Generated { .. } + | ColumnSpec::AutoIncrement + | ColumnSpec::Comment(_) => {} } false }); diff --git a/src/backend/sqlite/table.rs b/src/backend/sqlite/table.rs index 9f2fa91fa..cc33526bf 100644 --- a/src/backend/sqlite/table.rs +++ b/src/backend/sqlite/table.rs @@ -91,12 +91,7 @@ impl TableBuilder for SqliteQueryBuilder { write!(sql, "DROP COLUMN ").unwrap(); self.prepare_iden(col_name, sql); } - TableAlterOption::DropForeignKey(_) => { - panic!( - "Sqlite does not support modification of foreign key constraints to existing tables" - ); - } - TableAlterOption::AddForeignKey(_) => { + TableAlterOption::DropForeignKey(_) | TableAlterOption::AddForeignKey(_) => { panic!( "Sqlite does not support modification of foreign key constraints to existing tables" ); diff --git a/src/table/column.rs b/src/table/column.rs index 5715892e3..4a3ebbdce 100644 --- a/src/table/column.rs +++ b/src/table/column.rs @@ -117,15 +117,13 @@ pub enum StringLen { impl PartialEq for ColumnType { fn eq(&self, other: &Self) -> bool { match (self, other) { - (Self::Char(l0), Self::Char(r0)) => l0 == r0, - (Self::String(l0), Self::String(r0)) => l0 == r0, - (Self::Decimal(l0), Self::Decimal(r0)) => l0 == r0, + (Self::String(l0), Self::String(r0)) | (Self::VarBinary(l0), Self::VarBinary(r0)) => { + l0 == r0 + } + (Self::Decimal(l0), Self::Decimal(r0)) | (Self::Money(l0), Self::Money(r0)) => l0 == r0, (Self::Interval(l0, l1), Self::Interval(r0, r1)) => l0 == r0 && l1 == r1, - (Self::Binary(l0), Self::Binary(r0)) => l0 == r0, - (Self::VarBinary(l0), Self::VarBinary(r0)) => l0 == r0, - (Self::Bit(l0), Self::Bit(r0)) => l0 == r0, - (Self::VarBit(l0), Self::VarBit(r0)) => l0 == r0, - (Self::Money(l0), Self::Money(r0)) => l0 == r0, + (Self::Binary(l0), Self::Binary(r0)) | (Self::VarBit(l0), Self::VarBit(r0)) => l0 == r0, + (Self::Bit(l0), Self::Bit(r0)) | (Self::Char(l0), Self::Char(r0)) => l0 == r0, (Self::Custom(l0), Self::Custom(r0)) => l0.to_string() == r0.to_string(), ( Self::Enum { diff --git a/src/token.rs b/src/token.rs index 955ffdfc1..1ef47d4b2 100644 --- a/src/token.rs +++ b/src/token.rs @@ -251,10 +251,10 @@ impl Token { pub fn as_str(&self) -> &str { match self { - Self::Quoted(string) => string, - Self::Unquoted(string) => string, - Self::Space(string) => string, - Self::Punctuation(string) => string, + Token::Quoted(string) + | Token::Unquoted(string) + | Token::Space(string) + | Token::Punctuation(string) => string, } } @@ -270,16 +270,7 @@ impl Token { impl std::fmt::Display for Token { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}", - match self { - Token::Unquoted(string) => string, - Token::Space(string) => string, - Token::Quoted(string) => string, - Token::Punctuation(string) => string, - } - ) + f.write_str(self.as_str()) } } From ca7284287751d174bf0256b8bb905b6c1a835695 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:41:17 +0800 Subject: [PATCH 08/38] if_not_else --- src/backend/mysql/query.rs | 6 +++--- src/query/select.rs | 6 +++--- src/token.rs | 36 ++++++++++++++++++------------------ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/backend/mysql/query.rs b/src/backend/mysql/query.rs index f7809fe37..f78d170e5 100644 --- a/src/backend/mysql/query.rs +++ b/src/backend/mysql/query.rs @@ -157,7 +157,9 @@ impl QueryBuilder for MysqlQueryBuilder { ) { match on_conflict_action { Some(OnConflictAction::DoNothing(pk_cols)) => { - if !pk_cols.is_empty() { + if pk_cols.is_empty() { + write!(sql, " IGNORE").unwrap(); + } else { self.prepare_on_conflict_do_update_keywords(sql); pk_cols.iter().fold(true, |first, pk_col| { if !first { @@ -168,8 +170,6 @@ impl QueryBuilder for MysqlQueryBuilder { self.prepare_iden(pk_col, sql); false }); - } else { - write!(sql, " IGNORE").unwrap(); } } _ => self.prepare_on_conflict_action_common(on_conflict_action, sql), diff --git a/src/query/select.rs b/src/query/select.rs index 903731d68..cb456dac6 100644 --- a/src/query/select.rs +++ b/src/query/select.rs @@ -450,10 +450,10 @@ impl SelectStatement { .into_iter() .map(|col| col.into_column_ref()) .collect::>(); - self.distinct = if !cols.is_empty() { - Some(SelectDistinct::DistinctOn(cols)) - } else { + self.distinct = if cols.is_empty() { None + } else { + Some(SelectDistinct::DistinctOn(cols)) }; self } diff --git a/src/token.rs b/src/token.rs index 1ef47d4b2..e1d69cc94 100644 --- a/src/token.rs +++ b/src/token.rs @@ -53,10 +53,10 @@ impl Tokenizer { } self.inc(); } - if !string.is_empty() { - Some(Token::Space(string)) - } else { + if string.is_empty() { None + } else { + Some(Token::Space(string)) } } @@ -76,10 +76,10 @@ impl Tokenizer { break; } } - if !string.is_empty() { - Some(Token::Unquoted(string)) - } else { + if string.is_empty() { None + } else { + Some(Token::Unquoted(string)) } } @@ -101,11 +101,11 @@ impl Tokenizer { if self.end() { break; } - if !Self::is_string_escape_for(start, self.get()) { - break; - } else { + if Self::is_string_escape_for(start, self.get()) { write!(string, "{}", self.get()).unwrap(); self.inc(); + } else { + break; } } else if !first { escape = !escape && Self::is_escape_char(c); @@ -115,10 +115,10 @@ impl Tokenizer { break; } } - if !string.is_empty() { - Some(Token::Quoted(string)) - } else { + if string.is_empty() { None + } else { + Some(Token::Quoted(string)) } } @@ -139,11 +139,11 @@ impl Tokenizer { if self.end() { break; } - if !Self::is_string_escape_for(start, self.get()) { - break; - } else { + if Self::is_string_escape_for(start, self.get()) { write!(string, "{c}").unwrap(); self.inc(); + } else { + break; } } else if !first { escape = !escape && Self::is_escape_char(c); @@ -165,10 +165,10 @@ impl Tokenizer { self.inc(); } } - if !string.is_empty() { - Some(Token::Punctuation(string)) - } else { + if string.is_empty() { None + } else { + Some(Token::Punctuation(string)) } } From cd7c3a1e07ef401063ad52d5bc57aa133c7cc847 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:48:40 +0800 Subject: [PATCH 09/38] redundant_closure_for_method_calls --- src/backend/mysql/table.rs | 2 +- src/expr.rs | 4 ++-- src/foreign_key/common.rs | 7 ++----- src/index/common.rs | 2 +- src/query/insert.rs | 2 +- src/query/returning.rs | 5 ++++- src/query/select.rs | 16 +++++++++++----- src/query/with.rs | 3 +-- src/table/column.rs | 4 ++-- 9 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/backend/mysql/table.rs b/src/backend/mysql/table.rs index c5fc66151..f31bc19f2 100644 --- a/src/backend/mysql/table.rs +++ b/src/backend/mysql/table.rs @@ -79,7 +79,7 @@ impl TableBuilder for MysqlQueryBuilder { "ENUM('{}')", variants .iter() - .map(|v| v.to_string()) + .map(ToString::to_string) .collect::>() .join("', '") ), diff --git a/src/expr.rs b/src/expr.rs index 370c4fd28..0721ed7d9 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -693,7 +693,7 @@ pub trait ExprTrait: Sized { { self.binary( BinOper::In, - Expr::Tuple(v.into_iter().map(|v| v.into()).collect()), + Expr::Tuple(v.into_iter().map(Into::into).collect()), ) } @@ -796,7 +796,7 @@ pub trait ExprTrait: Sized { { self.binary( BinOper::NotIn, - Expr::Tuple(v.into_iter().map(|v| v.into()).collect()), + Expr::Tuple(v.into_iter().map(Into::into).collect()), ) } diff --git a/src/foreign_key/common.rs b/src/foreign_key/common.rs index 597fd2b03..7968591b9 100644 --- a/src/foreign_key/common.rs +++ b/src/foreign_key/common.rs @@ -105,14 +105,11 @@ impl TableForeignKey { } pub fn get_columns(&self) -> Vec { - self.columns.iter().map(|col| col.to_string()).collect() + self.columns.iter().map(ToString::to_string).collect() } pub fn get_ref_columns(&self) -> Vec { - self.ref_columns - .iter() - .map(|ref_col| ref_col.to_string()) - .collect() + self.ref_columns.iter().map(ToString::to_string).collect() } pub fn get_on_delete(&self) -> Option { diff --git a/src/index/common.rs b/src/index/common.rs index 4a76e3018..7b6d15471 100644 --- a/src/index/common.rs +++ b/src/index/common.rs @@ -166,7 +166,7 @@ impl TableIndex { pub fn get_column_names(&self) -> Vec { self.columns .iter() - .filter_map(|col| col.name().map(|name| name.to_string())) + .filter_map(|col| col.name().map(ToString::to_string)) .collect() } diff --git a/src/query/insert.rs b/src/query/insert.rs index ecdb2fac6..3ac16e398 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -130,7 +130,7 @@ impl InsertStatement { C: IntoIden, I: IntoIterator, { - self.columns = columns.into_iter().map(|c| c.into_iden()).collect(); + self.columns = columns.into_iter().map(IntoIden::into_iden).collect(); self } diff --git a/src/query/returning.rs b/src/query/returning.rs index 8a412769c..7d670b711 100644 --- a/src/query/returning.rs +++ b/src/query/returning.rs @@ -106,7 +106,10 @@ impl Returning { T: IntoColumnRef, I: IntoIterator, { - let cols: Vec<_> = cols.into_iter().map(|c| c.into_column_ref()).collect(); + let cols: Vec<_> = cols + .into_iter() + .map(IntoColumnRef::into_column_ref) + .collect(); ReturningClause::Columns(cols) } diff --git a/src/query/select.rs b/src/query/select.rs index cb456dac6..dbaf4f817 100644 --- a/src/query/select.rs +++ b/src/query/select.rs @@ -369,7 +369,7 @@ impl SelectStatement { I: IntoIterator, { self.selects - .append(&mut exprs.into_iter().map(|c| c.into()).collect()); + .append(&mut exprs.into_iter().map(Into::into).collect()); self } @@ -448,7 +448,7 @@ impl SelectStatement { { let cols = cols .into_iter() - .map(|col| col.into_column_ref()) + .map(IntoColumnRef::into_column_ref) .collect::>(); self.distinct = if cols.is_empty() { None @@ -929,7 +929,7 @@ impl SelectStatement { { let value_tuples: Vec = value_tuples .into_iter() - .map(|vt| vt.into_value_tuple()) + .map(IntoValueTuple::into_value_tuple) .collect(); assert!(!value_tuples.is_empty()); self.from_from(TableRef::ValuesList(value_tuples, alias.into_iden())) @@ -2078,7 +2078,10 @@ impl SelectStatement { { self.lock = Some(LockClause { r#type, - tables: tables.into_iter().map(|t| t.into_table_ref()).collect(), + tables: tables + .into_iter() + .map(IntoTableRef::into_table_ref) + .collect(), behavior: None, }); self @@ -2159,7 +2162,10 @@ impl SelectStatement { { self.lock = Some(LockClause { r#type, - tables: tables.into_iter().map(|t| t.into_table_ref()).collect(), + tables: tables + .into_iter() + .map(IntoTableRef::into_table_ref) + .collect(), behavior: Some(behavior), }); self diff --git a/src/query/with.rs b/src/query/with.rs index 6ec8f2687..62c9d81e6 100644 --- a/src/query/with.rs +++ b/src/query/with.rs @@ -87,8 +87,7 @@ impl CommonTableExpression { T: IntoIden, I: IntoIterator, { - self.cols - .extend(cols.into_iter().map(|col| col.into_iden())); + self.cols.extend(cols.into_iter().map(IntoIden::into_iden)); self } diff --git a/src/table/column.rs b/src/table/column.rs index 4a3ebbdce..0f7af32ca 100644 --- a/src/table/column.rs +++ b/src/table/column.rs @@ -138,8 +138,8 @@ impl PartialEq for ColumnType { l_name.to_string() == r_name.to_string() && l_variants .iter() - .map(|v| v.to_string()) - .eq(r_variants.iter().map(|v| v.to_string())) + .map(ToString::to_string) + .eq(r_variants.iter().map(ToString::to_string)) } (Self::Array(l0), Self::Array(r0)) => l0 == r0, _ => core::mem::discriminant(self) == core::mem::discriminant(other), From 1ee00bac5a52cd3402e2dcbcf86da31f94d80b92 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:50:08 +0800 Subject: [PATCH 10/38] semicolon_if_nothing_returned --- src/audit/insert.rs | 2 +- src/audit/select.rs | 4 +-- src/backend/foreign_key_builder.rs | 6 ++-- src/backend/mysql/foreign_key.rs | 2 +- src/backend/mysql/index.rs | 2 +- src/backend/mysql/query.rs | 10 +++--- src/backend/mysql/table.rs | 4 +-- src/backend/postgres/extension.rs | 2 +- src/backend/postgres/query.rs | 2 +- src/backend/postgres/table.rs | 4 +-- src/backend/postgres/types.rs | 6 ++-- src/backend/query_builder.rs | 52 +++++++++++++++--------------- src/backend/sqlite/foreign_key.rs | 2 +- src/backend/sqlite/index.rs | 2 +- src/backend/sqlite/query.rs | 2 +- src/backend/sqlite/table.rs | 4 +-- src/backend/table_builder.rs | 8 ++--- src/prepare.rs | 6 ++-- src/query/condition.rs | 2 +- src/query/select.rs | 4 +-- src/query/with.rs | 2 +- 21 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/audit/insert.rs b/src/audit/insert.rs index cb3fc342c..0893f1582 100644 --- a/src/audit/insert.rs +++ b/src/audit/insert.rs @@ -22,7 +22,7 @@ impl AuditTrait for InsertStatement { }); if let Some(InsertValueSource::Select(select)) = &self.source { - requests.append(&mut select.audit()?.requests) + requests.append(&mut select.audit()?.requests); } if let Some(with) = &self.with { diff --git a/src/audit/select.rs b/src/audit/select.rs index e2f739f02..8c6af9068 100644 --- a/src/audit/select.rs +++ b/src/audit/select.rs @@ -214,13 +214,13 @@ impl Walker { for oper in chain { match oper { LogicalChainOper::Or(expr) | LogicalChainOper::And(expr) => { - self.recurse_audit_expr(expr)? + self.recurse_audit_expr(expr)?; } } } } ConditionHolderContents::Condition(condition) => { - self.recurse_audit_condition(condition)? + self.recurse_audit_condition(condition)?; } } Ok(()) diff --git a/src/backend/foreign_key_builder.rs b/src/backend/foreign_key_builder.rs index ae7bc9883..64f463fe3 100644 --- a/src/backend/foreign_key_builder.rs +++ b/src/backend/foreign_key_builder.rs @@ -15,7 +15,7 @@ pub trait ForeignKeyBuilder: QuotedBuilder + TableRefBuilder { create: &ForeignKeyCreateStatement, sql: &mut dyn SqlWriter, ) { - self.prepare_foreign_key_create_statement_internal(create, sql, Mode::Alter) + self.prepare_foreign_key_create_statement_internal(create, sql, Mode::Alter); } /// Translate [`ForeignKeyDropStatement`] into SQL statement. @@ -24,7 +24,7 @@ pub trait ForeignKeyBuilder: QuotedBuilder + TableRefBuilder { drop: &ForeignKeyDropStatement, sql: &mut dyn SqlWriter, ) { - self.prepare_foreign_key_drop_statement_internal(drop, sql, Mode::Alter) + self.prepare_foreign_key_drop_statement_internal(drop, sql, Mode::Alter); } /// Translate [`ForeignKeyAction`] into SQL statement. @@ -44,7 +44,7 @@ pub trait ForeignKeyBuilder: QuotedBuilder + TableRefBuilder { ForeignKeyAction::SetDefault => "SET DEFAULT", } ) - .unwrap() + .unwrap(); } /// Translate [`TableRef`] into SQL statement. diff --git a/src/backend/mysql/foreign_key.rs b/src/backend/mysql/foreign_key.rs index a3edf1f05..26e309f14 100644 --- a/src/backend/mysql/foreign_key.rs +++ b/src/backend/mysql/foreign_key.rs @@ -5,7 +5,7 @@ impl ForeignKeyBuilder for MysqlQueryBuilder { match table_ref { // Support only "naked" table names with no schema or alias. TableRef::Table(TableName(None, _), None) => { - self.prepare_table_ref_iden(table_ref, sql) + self.prepare_table_ref_iden(table_ref, sql); } _ => panic!("Not supported"), } diff --git a/src/backend/mysql/index.rs b/src/backend/mysql/index.rs index e96344d71..6deb1e875 100644 --- a/src/backend/mysql/index.rs +++ b/src/backend/mysql/index.rs @@ -62,7 +62,7 @@ impl IndexBuilder for MysqlQueryBuilder { match table_ref { // Support only "naked" table names with no schema or alias. TableRef::Table(TableName(None, _), None) => { - self.prepare_table_ref_iden(table_ref, sql) + self.prepare_table_ref_iden(table_ref, sql); } _ => panic!("Not supported"), } diff --git a/src/backend/mysql/query.rs b/src/backend/mysql/query.rs index f78d170e5..7b4ba070c 100644 --- a/src/backend/mysql/query.rs +++ b/src/backend/mysql/query.rs @@ -21,7 +21,7 @@ impl QueryBuilder for MysqlQueryBuilder { } for (i, hint) in select.index_hints.iter().enumerate() { if i != 0 { - write!(sql, " ").unwrap() + write!(sql, " ").unwrap(); } match hint.r#type { IndexHintType::Use => { @@ -102,7 +102,7 @@ impl QueryBuilder for MysqlQueryBuilder { } } } - self.prepare_iden(column, sql) + self.prepare_iden(column, sql); } fn prepare_update_condition( @@ -129,11 +129,11 @@ impl QueryBuilder for MysqlQueryBuilder { None => (), Some(NullOrdering::Last) => { self.prepare_simple_expr(&order_expr.expr, sql); - write!(sql, " IS NULL ASC, ").unwrap() + write!(sql, " IS NULL ASC, ").unwrap(); } Some(NullOrdering::First) => { self.prepare_simple_expr(&order_expr.expr, sql); - write!(sql, " IS NULL DESC, ").unwrap() + write!(sql, " IS NULL DESC, ").unwrap(); } } if !matches!(order_expr.order, Order::Field(_)) { @@ -163,7 +163,7 @@ impl QueryBuilder for MysqlQueryBuilder { self.prepare_on_conflict_do_update_keywords(sql); pk_cols.iter().fold(true, |first, pk_col| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_iden(pk_col, sql); write!(sql, " = ").unwrap(); diff --git a/src/backend/mysql/table.rs b/src/backend/mysql/table.rs index f31bc19f2..191e558d1 100644 --- a/src/backend/mysql/table.rs +++ b/src/backend/mysql/table.rs @@ -7,7 +7,7 @@ impl TableBuilder for MysqlQueryBuilder { let comment = self.escape_string(comment); write!(sql, " COMMENT '{comment}'").unwrap(); } - self.prepare_table_opt_def(create, sql) + self.prepare_table_opt_def(create, sql); } fn prepare_column_def(&self, column_def: &ColumnDef, sql: &mut dyn SqlWriter) { @@ -188,6 +188,6 @@ impl TableBuilder for MysqlQueryBuilder { /// column comment fn column_comment(&self, comment: &str, sql: &mut dyn SqlWriter) { let comment = self.escape_string(comment); - write!(sql, "COMMENT '{comment}'").unwrap() + write!(sql, "COMMENT '{comment}'").unwrap(); } } diff --git a/src/backend/postgres/extension.rs b/src/backend/postgres/extension.rs index 68f28b6d2..29f79c4e7 100644 --- a/src/backend/postgres/extension.rs +++ b/src/backend/postgres/extension.rs @@ -10,7 +10,7 @@ impl ExtensionBuilder for PostgresQueryBuilder { write!(sql, "CREATE EXTENSION ").unwrap(); if create.if_not_exists { - write!(sql, "IF NOT EXISTS ").unwrap() + write!(sql, "IF NOT EXISTS ").unwrap(); } write!(sql, "{}", create.name).unwrap(); diff --git a/src/backend/postgres/query.rs b/src/backend/postgres/query.rs index 9f68fd22b..0356af0dd 100644 --- a/src/backend/postgres/query.rs +++ b/src/backend/postgres/query.rs @@ -181,7 +181,7 @@ impl QueryBuilder for PostgresQueryBuilder { } else { "'".to_owned() + &escaped + "'" }; - write!(buffer, "{string}").unwrap() + write!(buffer, "{string}").unwrap(); } fn write_bytes(&self, bytes: &[u8], buffer: &mut String) { diff --git a/src/backend/postgres/table.rs b/src/backend/postgres/table.rs index f7736ea75..bc6ee0ea2 100644 --- a/src/backend/postgres/table.rs +++ b/src/backend/postgres/table.rs @@ -86,7 +86,7 @@ impl TableBuilder for PostgresQueryBuilder { ColumnType::LTree => "ltree".into(), } ) - .unwrap() + .unwrap(); } fn column_spec_auto_increment_keyword(&self) -> &'static str { @@ -161,7 +161,7 @@ impl TableBuilder for PostgresQueryBuilder { ColumnSpec::NotNull => { write!(sql, "ALTER COLUMN ").unwrap(); self.prepare_iden(&column_def.name, sql); - write!(sql, " SET NOT NULL").unwrap() + write!(sql, " SET NOT NULL").unwrap(); } ColumnSpec::Default(v) => { write!(sql, "ALTER COLUMN ").unwrap(); diff --git a/src/backend/postgres/types.rs b/src/backend/postgres/types.rs index 198fe5cfa..4c7a8a10e 100644 --- a/src/backend/postgres/types.rs +++ b/src/backend/postgres/types.rs @@ -57,7 +57,7 @@ impl TypeBuilder for PostgresQueryBuilder { } if let Some(option) = &alter.option { - self.prepare_alter_type_opt(option, sql) + self.prepare_alter_type_opt(option, sql); } } } @@ -71,7 +71,7 @@ impl PostgresQueryBuilder { TypeAs::Enum => "ENUM", } ) - .unwrap() + .unwrap(); } fn prepare_drop_type_opt(&self, opt: &TypeDropOpt, sql: &mut dyn SqlWriter) { @@ -83,7 +83,7 @@ impl PostgresQueryBuilder { TypeDropOpt::Restrict => "RESTRICT", } ) - .unwrap() + .unwrap(); } fn prepare_alter_type_opt(&self, opt: &TypeAlterOpt, sql: &mut dyn SqlWriter) { diff --git a/src/backend/query_builder.rs b/src/backend/query_builder.rs index 408c66d60..a7a685ec0 100644 --- a/src/backend/query_builder.rs +++ b/src/backend/query_builder.rs @@ -43,7 +43,7 @@ pub trait QueryBuilder: write!(sql, "(").unwrap(); insert.columns.iter().fold(true, |first, col| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_iden(col, sql); false @@ -59,12 +59,12 @@ pub trait QueryBuilder: write!(sql, "VALUES ").unwrap(); values.iter().fold(true, |first, row| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } write!(sql, "(").unwrap(); row.iter().fold(true, |first, col| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_simple_expr(col, sql); false @@ -116,7 +116,7 @@ pub trait QueryBuilder: select.selects.iter().fold(true, |first, expr| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_select_expr(expr, sql); false @@ -126,7 +126,7 @@ pub trait QueryBuilder: write!(sql, " FROM ").unwrap(); select.from.iter().fold(true, |first, table_ref| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_table_ref(table_ref, sql); false @@ -148,7 +148,7 @@ pub trait QueryBuilder: write!(sql, " GROUP BY ").unwrap(); select.groups.iter().fold(true, |first, expr| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_simple_expr(expr, sql); false @@ -167,7 +167,7 @@ pub trait QueryBuilder: write!(sql, " ORDER BY ").unwrap(); select.orders.iter().fold(true, |first, expr| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_order_expr(expr, sql); false @@ -221,7 +221,7 @@ pub trait QueryBuilder: update.values.iter().fold(true, |first, row| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } let (col, v) = row; self.prepare_update_column(&update.table, &update.from, col, sql); @@ -256,7 +256,7 @@ pub trait QueryBuilder: from.iter().fold(true, |first, table_ref| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_table_ref(table_ref, sql); @@ -384,10 +384,10 @@ pub trait QueryBuilder: } Expr::Binary(left, op, right) => match (op, right.as_ref()) { (BinOper::In, Expr::Tuple(t)) if t.is_empty() => { - self.binary_expr(&1i32.into(), &BinOper::Equal, &2i32.into(), sql) + self.binary_expr(&1i32.into(), &BinOper::Equal, &2i32.into(), sql); } (BinOper::NotIn, Expr::Tuple(t)) if t.is_empty() => { - self.binary_expr(&1i32.into(), &BinOper::Equal, &1i32.into(), sql) + self.binary_expr(&1i32.into(), &BinOper::Equal, &1i32.into(), sql); } _ => self.binary_expr(left, op, right, sql), }, @@ -719,7 +719,7 @@ pub trait QueryBuilder: /// Translate [`Function`] into SQL statement. fn prepare_function_name_common(&self, function: &Func, sql: &mut dyn SqlWriter) { if let Func::Custom(iden) = function { - write!(sql, "{iden}").unwrap() + write!(sql, "{iden}").unwrap(); } else { write!( sql, @@ -886,7 +886,7 @@ pub trait QueryBuilder: "{} MATERIALIZED ", if materialized { "" } else { "NOT" } ) - .unwrap() + .unwrap(); } } @@ -907,12 +907,12 @@ pub trait QueryBuilder: } fn prepare_function_name(&self, function: &Func, sql: &mut dyn SqlWriter) { - self.prepare_function_name_common(function, sql) + self.prepare_function_name_common(function, sql); } /// Translate [`JoinType`] into SQL statement. fn prepare_join_type(&self, join_type: &JoinType, sql: &mut dyn SqlWriter) { - self.prepare_join_type_common(join_type, sql) + self.prepare_join_type_common(join_type, sql); } fn prepare_join_type_common(&self, join_type: &JoinType, sql: &mut dyn SqlWriter) { @@ -928,7 +928,7 @@ pub trait QueryBuilder: JoinType::FullOuterJoin => "FULL OUTER JOIN", } ) - .unwrap() + .unwrap(); } /// Translate [`OrderExpr`] into SQL statement. @@ -1112,7 +1112,7 @@ pub trait QueryBuilder: Value::Double(Some(v)) => write!(s, "{v}").unwrap(), Value::String(Some(v)) => self.write_string_quoted(v, &mut s), Value::Char(Some(v)) => { - self.write_string_quoted(std::str::from_utf8(&[*v as u8]).unwrap(), &mut s) + self.write_string_quoted(std::str::from_utf8(&[*v as u8]).unwrap(), &mut s); } Value::Bytes(Some(v)) => self.write_bytes(v, &mut s), #[cfg(feature = "with-json")] @@ -1247,7 +1247,7 @@ pub trait QueryBuilder: write!(sql, "(").unwrap(); on_conflict_targets.iter().fold(true, |first, target| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } match target { OnConflictTarget::ConflictColumn(col) => { @@ -1287,7 +1287,7 @@ pub trait QueryBuilder: self.prepare_on_conflict_do_update_keywords(sql); update_strats.iter().fold(true, |first, update_strat| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } match update_strat { OnConflictUpdate::Column(col) => { @@ -1341,7 +1341,7 @@ pub trait QueryBuilder: on_conflict_condition: &ConditionHolder, sql: &mut dyn SqlWriter, ) { - self.prepare_condition(on_conflict_condition, "WHERE", sql) + self.prepare_condition(on_conflict_condition, "WHERE", sql); } #[doc(hidden)] @@ -1358,7 +1358,7 @@ pub trait QueryBuilder: ReturningClause::Columns(cols) => { cols.iter().fold(true, |first, column_ref| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_column_ref(column_ref, sql); false @@ -1367,7 +1367,7 @@ pub trait QueryBuilder: ReturningClause::Exprs(exprs) => { exprs.iter().fold(true, |first, expr| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_simple_expr(expr, sql); false @@ -1432,7 +1432,7 @@ pub trait QueryBuilder: write!(sql, "PARTITION BY ").unwrap(); window.partition_by.iter().fold(true, |first, expr| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_simple_expr(expr, sql); false @@ -1443,7 +1443,7 @@ pub trait QueryBuilder: write!(sql, " ORDER BY ").unwrap(); window.order_by.iter().fold(true, |first, expr| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } self.prepare_order_expr(expr, sql); false @@ -1525,7 +1525,7 @@ pub trait QueryBuilder: #[doc(hidden)] /// Write a string surrounded by escaped quotes. fn write_string_quoted(&self, string: &str, buffer: &mut String) { - write!(buffer, "'{}'", self.escape_string(string)).unwrap() + write!(buffer, "'{}'", self.escape_string(string)).unwrap(); } #[doc(hidden)] @@ -1579,7 +1579,7 @@ pub trait QueryBuilder: write!(sql, "VALUES ").unwrap(); (0..num_rows).fold(true, |first, _| { if !first { - write!(sql, ", ").unwrap() + write!(sql, ", ").unwrap(); } write!(sql, "{}", self.insert_default_keyword()).unwrap(); false diff --git a/src/backend/sqlite/foreign_key.rs b/src/backend/sqlite/foreign_key.rs index 9c4368a7d..1168a5204 100644 --- a/src/backend/sqlite/foreign_key.rs +++ b/src/backend/sqlite/foreign_key.rs @@ -5,7 +5,7 @@ impl ForeignKeyBuilder for SqliteQueryBuilder { match table_ref { // Support only "naked" table names with no schema or alias. TableRef::Table(TableName(None, _), None) => { - self.prepare_table_ref_iden(table_ref, sql) + self.prepare_table_ref_iden(table_ref, sql); } _ => panic!("Not supported"), } diff --git a/src/backend/sqlite/index.rs b/src/backend/sqlite/index.rs index 7adbb803b..e7177e6b4 100644 --- a/src/backend/sqlite/index.rs +++ b/src/backend/sqlite/index.rs @@ -39,7 +39,7 @@ impl IndexBuilder for SqliteQueryBuilder { match table_ref { // Support only "naked" table names with no schema or alias. TableRef::Table(TableName(None, _), None) => { - self.prepare_table_ref_iden(table_ref, sql) + self.prepare_table_ref_iden(table_ref, sql); } _ => panic!("Not supported"), } diff --git a/src/backend/sqlite/query.rs b/src/backend/sqlite/query.rs index 84286d742..460bb5422 100644 --- a/src/backend/sqlite/query.rs +++ b/src/backend/sqlite/query.rs @@ -90,6 +90,6 @@ impl QueryBuilder for SqliteQueryBuilder { fn insert_default_values(&self, _: u32, sql: &mut dyn SqlWriter) { // SQLite doesn't support inserting multiple rows with default values - write!(sql, "DEFAULT VALUES").unwrap() + write!(sql, "DEFAULT VALUES").unwrap(); } } diff --git a/src/backend/sqlite/table.rs b/src/backend/sqlite/table.rs index cc33526bf..56742c296 100644 --- a/src/backend/sqlite/table.rs +++ b/src/backend/sqlite/table.rs @@ -39,7 +39,7 @@ impl TableBuilder for SqliteQueryBuilder { } fn prepare_column_type(&self, column_type: &ColumnType, sql: &mut dyn SqlWriter) { - self.prepare_column_type(&[], column_type, sql) + self.prepare_column_type(&[], column_type, sql); } fn column_spec_auto_increment_keyword(&self) -> &'static str { @@ -193,7 +193,7 @@ impl SqliteQueryBuilder { ColumnType::LTree => unimplemented!("LTree is not available in Sqlite."), } ) - .unwrap() + .unwrap(); } } diff --git a/src/backend/table_builder.rs b/src/backend/table_builder.rs index c6fbf0880..73c316052 100644 --- a/src/backend/table_builder.rs +++ b/src/backend/table_builder.rs @@ -100,13 +100,13 @@ pub trait TableBuilder: QueryBuilder::prepare_simple_expr(self, value, sql); } ColumnSpec::AutoIncrement => { - write!(sql, "{}", self.column_spec_auto_increment_keyword()).unwrap() + write!(sql, "{}", self.column_spec_auto_increment_keyword()).unwrap(); } ColumnSpec::UniqueKey => write!(sql, "UNIQUE").unwrap(), ColumnSpec::PrimaryKey => write!(sql, "PRIMARY KEY").unwrap(), ColumnSpec::Check(check) => self.prepare_check_constraint(check, sql), ColumnSpec::Generated { expr, stored } => { - self.prepare_generated_column(expr, *stored, sql) + self.prepare_generated_column(expr, *stored, sql); } ColumnSpec::Extra(string) => write!(sql, "{string}").unwrap(), ColumnSpec::Comment(comment) => self.column_comment(comment, sql), @@ -122,7 +122,7 @@ pub trait TableBuilder: /// Translate [`TableOpt`] into SQL statement. fn prepare_table_opt(&self, create: &TableCreateStatement, sql: &mut dyn SqlWriter) { - self.prepare_table_opt_def(create, sql) + self.prepare_table_opt_def(create, sql); } /// Default function @@ -138,7 +138,7 @@ pub trait TableBuilder: TableOpt::CharacterSet(s) => format!("DEFAULT CHARSET={s}"), } ) - .unwrap() + .unwrap(); } } diff --git a/src/prepare.rs b/src/prepare.rs index 93c3b56e6..d9c7751f5 100644 --- a/src/prepare.rs +++ b/src/prepare.rs @@ -11,7 +11,7 @@ pub trait SqlWriter: Write + ToString { impl SqlWriter for String { fn push_param(&mut self, value: Value, query_builder: &dyn QueryBuilder) { - self.push_str(&query_builder.value_to_string(&value)) + self.push_str(&query_builder.value_to_string(&value)); } fn as_writer(&mut self) -> &mut dyn Write { @@ -68,7 +68,7 @@ impl SqlWriter for SqlWriterValues { } else { write!(self.string, "{}", self.placeholder).unwrap(); } - self.values.push(value) + self.values.push(value); } fn as_writer(&mut self) -> &mut dyn Write { @@ -106,7 +106,7 @@ where } } } - output.push(mark.clone()) + output.push(mark.clone()); } _ => output.push(token.to_string()), } diff --git a/src/query/condition.rs b/src/query/condition.rs index b263b954f..feba273b2 100644 --- a/src/query/condition.rs +++ b/src/query/condition.rs @@ -654,7 +654,7 @@ impl ConditionHolder { pub fn add_and_or(&mut self, condition: LogicalChainOper) { match &mut self.contents { ConditionHolderContents::Empty => { - self.contents = ConditionHolderContents::Chain(vec![condition]) + self.contents = ConditionHolderContents::Chain(vec![condition]); } ConditionHolderContents::Chain(c) => c.push(condition), ConditionHolderContents::Condition(_) => { diff --git a/src/query/select.rs b/src/query/select.rs index dbaf4f817..bf7982d06 100644 --- a/src/query/select.rs +++ b/src/query/select.rs @@ -218,9 +218,9 @@ impl SelectStatement { F: FnOnce(&mut Self), { if b { - if_true(self) + if_true(self); } else { - if_false(self) + if_false(self); } self } diff --git a/src/query/with.rs b/src/query/with.rs index 62c9d81e6..c4ce1cac6 100644 --- a/src/query/with.rs +++ b/src/query/with.rs @@ -128,7 +128,7 @@ impl CommonTableExpression { } fn set_table_name_from_select(&mut self, iden: &DynIden) { - self.table_name = Some(format!("cte_{iden}").into_iden()) + self.table_name = Some(format!("cte_{iden}").into_iden()); } /// Set up the columns of the CTE to match the given [`SelectStatement`] selected columns. From dbb348f97fcfd39f7f61c90b85f19af7a2b3e55f Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:52:48 +0800 Subject: [PATCH 11/38] explicit_into_iter_loop --- src/extension/postgres/types.rs | 4 ++-- src/query/update.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/extension/postgres/types.rs b/src/extension/postgres/types.rs index e702c5621..b898fdc3b 100644 --- a/src/extension/postgres/types.rs +++ b/src/extension/postgres/types.rs @@ -198,7 +198,7 @@ impl TypeCreateStatement { T: IntoIden, I: IntoIterator, { - for v in values.into_iter() { + for v in values { self.values.push(v.into_iden()); } self @@ -275,7 +275,7 @@ impl TypeDropStatement { T: IntoTypeRef, I: IntoIterator, { - for n in names.into_iter() { + for n in names { self.names.push(n.into_type_ref()); } self diff --git a/src/query/update.rs b/src/query/update.rs index f1fc47e66..cca900560 100644 --- a/src/query/update.rs +++ b/src/query/update.rs @@ -176,7 +176,7 @@ impl UpdateStatement { T: IntoIden, I: IntoIterator, { - for (k, v) in values.into_iter() { + for (k, v) in values { self.values.push((k.into_iden(), Box::new(v))); } self From e3ff67b22dfbfac619b7c6f789c5527c1b89d13b Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:53:47 +0800 Subject: [PATCH 12/38] struct_excessive_bools --- src/index/create.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index/create.rs b/src/index/create.rs index 0ceb5abf6..7d30de59a 100644 --- a/src/index/create.rs +++ b/src/index/create.rs @@ -208,6 +208,7 @@ use super::common::*; /// ); /// ``` #[derive(Default, Debug, Clone)] +#[expect(clippy::struct_excessive_bools, reason = "Not a state machine")] pub struct IndexCreateStatement { pub(crate) table: Option, pub(crate) index: TableIndex, From 9bd417129601e2260fc00949a495e8e4fa4e8e7e Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:56:03 +0800 Subject: [PATCH 13/38] match_wildcard_for_single_variants --- src/audit/select.rs | 2 +- src/backend/mod.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/audit/select.rs b/src/audit/select.rs index 8c6af9068..649069f29 100644 --- a/src/audit/select.rs +++ b/src/audit/select.rs @@ -263,7 +263,7 @@ fn wrap_result(access: Vec) -> QueryAccessAudit { AccessType::Insert => &mut insert_set, AccessType::Update => &mut update_set, AccessType::Delete => &mut delete_set, - _ => todo!(), + AccessType::Schema(_) => todo!(), }; if set.contains(&access.schema_table) { None diff --git a/src/backend/mod.rs b/src/backend/mod.rs index b47224746..d57cedffe 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -179,6 +179,7 @@ impl Oper { ) } + #[allow(clippy::match_wildcard_for_single_variants)] pub(crate) fn is_arithmetic(&self) -> bool { match self { Oper::BinOper(b) => { @@ -191,6 +192,7 @@ impl Oper { } } + #[allow(clippy::match_wildcard_for_single_variants)] pub(crate) fn is_comparison(&self) -> bool { match self { Oper::BinOper(b) => { From 3c199e6c013b3fa888fb76addeed3d5099eeeeb2 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 13:56:52 +0800 Subject: [PATCH 14/38] explicit_iter_loop --- src/backend/mysql/table.rs | 2 +- src/backend/postgres/table.rs | 2 +- src/backend/query_builder.rs | 4 ++-- src/backend/sqlite/table.rs | 2 +- src/backend/table_builder.rs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/backend/mysql/table.rs b/src/backend/mysql/table.rs index 191e558d1..18e26983f 100644 --- a/src/backend/mysql/table.rs +++ b/src/backend/mysql/table.rs @@ -18,7 +18,7 @@ impl TableBuilder for MysqlQueryBuilder { self.prepare_column_type(column_type, sql); } - for column_spec in column_def.spec.iter() { + for column_spec in &column_def.spec { write!(sql, " ").unwrap(); self.prepare_column_spec(column_spec, sql); } diff --git a/src/backend/postgres/table.rs b/src/backend/postgres/table.rs index bc6ee0ea2..cf20933d4 100644 --- a/src/backend/postgres/table.rs +++ b/src/backend/postgres/table.rs @@ -283,7 +283,7 @@ impl PostgresQueryBuilder { f(column_def, sql); - for column_spec in column_def.spec.iter() { + for column_spec in &column_def.spec { if matches!(column_spec, ColumnSpec::AutoIncrement) { continue; } diff --git a/src/backend/query_builder.rs b/src/backend/query_builder.rs index a7a685ec0..c59032782 100644 --- a/src/backend/query_builder.rs +++ b/src/backend/query_builder.rs @@ -136,7 +136,7 @@ pub trait QueryBuilder: } if !select.join.is_empty() { - for expr in select.join.iter() { + for expr in &select.join { write!(sql, " ").unwrap(); self.prepare_join_expr(expr, sql); } @@ -466,7 +466,7 @@ pub trait QueryBuilder: let CaseStatement { when, r#else } = stmts; - for case in when.iter() { + for case in when { write!(sql, " WHEN (").unwrap(); self.prepare_condition_where(&case.condition, sql); write!(sql, ") THEN ").unwrap(); diff --git a/src/backend/sqlite/table.rs b/src/backend/sqlite/table.rs index 56742c296..33b20acd4 100644 --- a/src/backend/sqlite/table.rs +++ b/src/backend/sqlite/table.rs @@ -12,7 +12,7 @@ impl TableBuilder for SqliteQueryBuilder { let mut is_primary_key = false; let mut is_auto_increment = false; - for column_spec in column_def.spec.iter() { + for column_spec in &column_def.spec { if matches!(column_spec, ColumnSpec::PrimaryKey) { is_primary_key = true; continue; diff --git a/src/backend/table_builder.rs b/src/backend/table_builder.rs index 73c316052..26244c423 100644 --- a/src/backend/table_builder.rs +++ b/src/backend/table_builder.rs @@ -127,7 +127,7 @@ pub trait TableBuilder: /// Default function fn prepare_table_opt_def(&self, create: &TableCreateStatement, sql: &mut dyn SqlWriter) { - for table_opt in create.options.iter() { + for table_opt in &create.options { write!(sql, " ").unwrap(); write!( sql, @@ -162,7 +162,7 @@ pub trait TableBuilder: false }); - for drop_opt in drop.options.iter() { + for drop_opt in &drop.options { self.prepare_table_drop_opt(drop_opt, sql); } } From 2ad9c5cd449eb8b1cacc2f520d5dadb59f21b720 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 14:03:03 +0800 Subject: [PATCH 15/38] explicit_deref_methods --- src/backend/mysql/query.rs | 12 ++++-------- src/backend/query_builder.rs | 10 ++++------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/backend/mysql/query.rs b/src/backend/mysql/query.rs index 7b4ba070c..c16126aa6 100644 --- a/src/backend/mysql/query.rs +++ b/src/backend/mysql/query.rs @@ -90,16 +90,12 @@ impl QueryBuilder for MysqlQueryBuilder { column: &DynIden, sql: &mut dyn SqlWriter, ) { - use std::ops::Deref; - if !from.is_empty() { - if let Some(table) = table { + if let Some(TableRef::Table(TableName(None, table), None)) = table.as_deref() { // Support only "naked" table names with no schema or alias. - if let TableRef::Table(TableName(None, table), None) = table.deref() { - let column_name = ColumnName::from((table.clone(), column.clone())); - self.prepare_column_ref(&ColumnRef::Column(column_name), sql); - return; - } + let column_name = ColumnName::from((table.clone(), column.clone())); + self.prepare_column_ref(&ColumnRef::Column(column_name), sql); + return; } } self.prepare_iden(column, sql); diff --git a/src/backend/query_builder.rs b/src/backend/query_builder.rs index c59032782..31ee32e2e 100644 --- a/src/backend/query_builder.rs +++ b/src/backend/query_builder.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use crate::*; const QUOTE: Quote = Quote(b'"', b'"'); @@ -74,7 +72,7 @@ pub trait QueryBuilder: }); } InsertValueSource::Select(select_query) => { - self.prepare_select_statement(select_query.deref(), sql); + self.prepare_select_statement(select_query, sql); } } } @@ -396,7 +394,7 @@ pub trait QueryBuilder: self.prepare_sub_query_oper(oper, sql); } write!(sql, "(").unwrap(); - self.prepare_query_statement(sel.deref(), sql); + self.prepare_query_statement(sel, sql); write!(sql, ")").unwrap(); } Expr::Value(val) => { @@ -772,7 +770,7 @@ pub trait QueryBuilder: fn prepare_with_query(&self, query: &WithQuery, sql: &mut dyn SqlWriter) { self.prepare_with_clause(&query.with_clause, sql); - self.prepare_query_statement(query.query.as_ref().unwrap().deref(), sql); + self.prepare_query_statement(query.query.as_ref().unwrap(), sql); } fn prepare_with_clause(&self, with_clause: &WithClause, sql: &mut dyn SqlWriter) { @@ -870,7 +868,7 @@ pub trait QueryBuilder: write!(sql, "(").unwrap(); - self.prepare_query_statement(cte.query.as_ref().unwrap().deref(), sql); + self.prepare_query_statement(cte.query.as_ref().unwrap(), sql); write!(sql, ") ").unwrap(); } From 8c1f68fa3def52c5717b037e96c6a6a57b04a59e Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 14:07:02 +0800 Subject: [PATCH 16/38] unused_self --- src/backend/mysql/query.rs | 8 ++++---- src/backend/postgres/table.rs | 6 +++--- src/backend/postgres/types.rs | 8 ++++---- src/backend/sqlite/table.rs | 5 ++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/backend/mysql/query.rs b/src/backend/mysql/query.rs index c16126aa6..352bf8cdc 100644 --- a/src/backend/mysql/query.rs +++ b/src/backend/mysql/query.rs @@ -26,19 +26,19 @@ impl QueryBuilder for MysqlQueryBuilder { match hint.r#type { IndexHintType::Use => { write!(sql, "USE INDEX ",).unwrap(); - self.prepare_index_hint_scope(&hint.scope, sql); + Self::prepare_index_hint_scope(&hint.scope, sql); write!(sql, "(").unwrap(); self.prepare_iden(&hint.index, sql); } IndexHintType::Ignore => { write!(sql, "IGNORE INDEX ",).unwrap(); - self.prepare_index_hint_scope(&hint.scope, sql); + Self::prepare_index_hint_scope(&hint.scope, sql); write!(sql, "(").unwrap(); self.prepare_iden(&hint.index, sql); } IndexHintType::Force => { write!(sql, "FORCE INDEX ",).unwrap(); - self.prepare_index_hint_scope(&hint.scope, sql); + Self::prepare_index_hint_scope(&hint.scope, sql); write!(sql, "(").unwrap(); self.prepare_iden(&hint.index, sql); } @@ -200,7 +200,7 @@ impl QueryBuilder for MysqlQueryBuilder { } impl MysqlQueryBuilder { - fn prepare_index_hint_scope(&self, index_hint_scope: &IndexHintScope, sql: &mut dyn SqlWriter) { + fn prepare_index_hint_scope(index_hint_scope: &IndexHintScope, sql: &mut dyn SqlWriter) { match index_hint_scope { IndexHintScope::Join => { write!(sql, "FOR JOIN ").unwrap(); diff --git a/src/backend/postgres/table.rs b/src/backend/postgres/table.rs index cf20933d4..6e01162fc 100644 --- a/src/backend/postgres/table.rs +++ b/src/backend/postgres/table.rs @@ -124,7 +124,7 @@ impl TableBuilder for PostgresQueryBuilder { .iter() .any(|v| matches!(v, ColumnSpec::AutoIncrement)) { - self.prepare_column_auto_increment(column_type, sql); + Self::prepare_column_auto_increment(column_type, sql); } else { self.prepare_column_type(column_type, sql); } @@ -243,7 +243,7 @@ impl TableBuilder for PostgresQueryBuilder { } impl PostgresQueryBuilder { - fn prepare_column_auto_increment(&self, column_type: &ColumnType, sql: &mut dyn SqlWriter) { + fn prepare_column_auto_increment(column_type: &ColumnType, sql: &mut dyn SqlWriter) { let num_ty = match column_type { ColumnType::SmallInteger => "smallint", ColumnType::Integer => "integer", @@ -268,7 +268,7 @@ impl PostgresQueryBuilder { write!(sql, " ").unwrap(); if is_auto_increment.is_some() { - self.prepare_column_auto_increment(column_type, sql); + Self::prepare_column_auto_increment(column_type, sql); } else { self.prepare_column_type(column_type, sql); } diff --git a/src/backend/postgres/types.rs b/src/backend/postgres/types.rs index 4c7a8a10e..9e6bc4ff1 100644 --- a/src/backend/postgres/types.rs +++ b/src/backend/postgres/types.rs @@ -11,7 +11,7 @@ impl TypeBuilder for PostgresQueryBuilder { if let Some(as_type) = &create.as_type { write!(sql, " AS ").unwrap(); - self.prepare_create_as_type(as_type, sql); + Self::prepare_create_as_type(as_type, sql); } if !create.values.is_empty() { @@ -45,7 +45,7 @@ impl TypeBuilder for PostgresQueryBuilder { if let Some(option) = &drop.option { write!(sql, " ").unwrap(); - self.prepare_drop_type_opt(option, sql); + Self::prepare_drop_type_opt(option, sql); } } @@ -63,7 +63,7 @@ impl TypeBuilder for PostgresQueryBuilder { } impl PostgresQueryBuilder { - fn prepare_create_as_type(&self, as_type: &TypeAs, sql: &mut dyn SqlWriter) { + fn prepare_create_as_type(as_type: &TypeAs, sql: &mut dyn SqlWriter) { write!( sql, "{}", @@ -74,7 +74,7 @@ impl PostgresQueryBuilder { .unwrap(); } - fn prepare_drop_type_opt(&self, opt: &TypeDropOpt, sql: &mut dyn SqlWriter) { + fn prepare_drop_type_opt(opt: &TypeDropOpt, sql: &mut dyn SqlWriter) { write!( sql, "{}", diff --git a/src/backend/sqlite/table.rs b/src/backend/sqlite/table.rs index 33b20acd4..070689784 100644 --- a/src/backend/sqlite/table.rs +++ b/src/backend/sqlite/table.rs @@ -6,7 +6,7 @@ impl TableBuilder for SqliteQueryBuilder { if let Some(column_type) = &column_def.types { write!(sql, " ").unwrap(); - self.prepare_column_type(&column_def.spec, column_type, sql); + Self::prepare_column_type(&column_def.spec, column_type, sql); } let mut is_primary_key = false; @@ -39,7 +39,7 @@ impl TableBuilder for SqliteQueryBuilder { } fn prepare_column_type(&self, column_type: &ColumnType, sql: &mut dyn SqlWriter) { - self.prepare_column_type(&[], column_type, sql); + Self::prepare_column_type(&[], column_type, sql); } fn column_spec_auto_increment_keyword(&self) -> &'static str { @@ -117,7 +117,6 @@ impl TableBuilder for SqliteQueryBuilder { impl SqliteQueryBuilder { fn prepare_column_type( - &self, column_specs: &[ColumnSpec], column_type: &ColumnType, sql: &mut dyn SqlWriter, From 75c11ddc45c2c7ba2daecafdd71d405646b22b4e Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 14:08:03 +0800 Subject: [PATCH 17/38] trivially_copy_pass_by_ref --- src/backend/mysql/query.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/mysql/query.rs b/src/backend/mysql/query.rs index 352bf8cdc..d114f2dac 100644 --- a/src/backend/mysql/query.rs +++ b/src/backend/mysql/query.rs @@ -26,19 +26,19 @@ impl QueryBuilder for MysqlQueryBuilder { match hint.r#type { IndexHintType::Use => { write!(sql, "USE INDEX ",).unwrap(); - Self::prepare_index_hint_scope(&hint.scope, sql); + Self::prepare_index_hint_scope(hint.scope, sql); write!(sql, "(").unwrap(); self.prepare_iden(&hint.index, sql); } IndexHintType::Ignore => { write!(sql, "IGNORE INDEX ",).unwrap(); - Self::prepare_index_hint_scope(&hint.scope, sql); + Self::prepare_index_hint_scope(hint.scope, sql); write!(sql, "(").unwrap(); self.prepare_iden(&hint.index, sql); } IndexHintType::Force => { write!(sql, "FORCE INDEX ",).unwrap(); - Self::prepare_index_hint_scope(&hint.scope, sql); + Self::prepare_index_hint_scope(hint.scope, sql); write!(sql, "(").unwrap(); self.prepare_iden(&hint.index, sql); } @@ -200,7 +200,7 @@ impl QueryBuilder for MysqlQueryBuilder { } impl MysqlQueryBuilder { - fn prepare_index_hint_scope(index_hint_scope: &IndexHintScope, sql: &mut dyn SqlWriter) { + fn prepare_index_hint_scope(index_hint_scope: IndexHintScope, sql: &mut dyn SqlWriter) { match index_hint_scope { IndexHintScope::Join => { write!(sql, "FOR JOIN ").unwrap(); From ab4b22658a5afb1378a4fcc1ba07387313971cf0 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 14:09:26 +0800 Subject: [PATCH 18/38] unnested_or_patterns --- src/backend/mod.rs | 27 ++++++--------------------- src/backend/postgres/query.rs | 16 +++++++++------- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index d57cedffe..0612ea631 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -140,43 +140,28 @@ impl Oper { pub(crate) fn is_logical(&self) -> bool { matches!( self, - Oper::UnOper(UnOper::Not) | Oper::BinOper(BinOper::And) | Oper::BinOper(BinOper::Or) + Oper::UnOper(UnOper::Not) | Oper::BinOper(BinOper::And | BinOper::Or) ) } pub(crate) fn is_between(&self) -> bool { - matches!( - self, - Oper::BinOper(BinOper::Between) | Oper::BinOper(BinOper::NotBetween) - ) + matches!(self, Oper::BinOper(BinOper::Between | BinOper::NotBetween)) } pub(crate) fn is_like(&self) -> bool { - matches!( - self, - Oper::BinOper(BinOper::Like) | Oper::BinOper(BinOper::NotLike) - ) + matches!(self, Oper::BinOper(BinOper::Like | BinOper::NotLike)) } pub(crate) fn is_in(&self) -> bool { - matches!( - self, - Oper::BinOper(BinOper::In) | Oper::BinOper(BinOper::NotIn) - ) + matches!(self, Oper::BinOper(BinOper::In | BinOper::NotIn)) } pub(crate) fn is_is(&self) -> bool { - matches!( - self, - Oper::BinOper(BinOper::Is) | Oper::BinOper(BinOper::IsNot) - ) + matches!(self, Oper::BinOper(BinOper::Is | BinOper::IsNot)) } pub(crate) fn is_shift(&self) -> bool { - matches!( - self, - Oper::BinOper(BinOper::LShift) | Oper::BinOper(BinOper::RShift) - ) + matches!(self, Oper::BinOper(BinOper::LShift | BinOper::RShift)) } #[allow(clippy::match_wildcard_for_single_variants)] diff --git a/src/backend/postgres/query.rs b/src/backend/postgres/query.rs index 0356af0dd..ecdd179f1 100644 --- a/src/backend/postgres/query.rs +++ b/src/backend/postgres/query.rs @@ -200,18 +200,20 @@ impl QueryBuilder for PostgresQueryBuilder { fn is_pg_comparison(b: &BinOper) -> bool { matches!( b, - BinOper::PgOperator(PgBinOper::Contained) - | BinOper::PgOperator(PgBinOper::Contains) - | BinOper::PgOperator(PgBinOper::Similarity) - | BinOper::PgOperator(PgBinOper::WordSimilarity) - | BinOper::PgOperator(PgBinOper::StrictWordSimilarity) - | BinOper::PgOperator(PgBinOper::Matches) + BinOper::PgOperator( + PgBinOper::Contained + | PgBinOper::Contains + | PgBinOper::Similarity + | PgBinOper::WordSimilarity + | PgBinOper::StrictWordSimilarity + | PgBinOper::Matches + ) ) } fn is_ilike(b: &BinOper) -> bool { matches!( b, - BinOper::PgOperator(PgBinOper::ILike) | BinOper::PgOperator(PgBinOper::NotILike) + BinOper::PgOperator(PgBinOper::ILike | PgBinOper::NotILike) ) } From f25701649b530cc5f3c3a6cf2624165ee1226a8c Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 14:09:44 +0800 Subject: [PATCH 19/38] Disable wildcard_imports and enum_glob_use --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 5750ec5bf..c89a3bcaf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,9 @@ clippy::option_if_let_else, clippy::redundant_pub_crate, clippy::use_self, - clippy::missing_const_for_fn + clippy::missing_const_for_fn, + clippy::wildcard_imports, + clippy::enum_glob_use )] //!
From 16d1d450e642166606371b6ef22e4a0610b1cccd Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Thu, 7 Aug 2025 14:18:05 +0800 Subject: [PATCH 20/38] Reason --- src/value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/value.rs b/src/value.rs index 31f7b8da2..6925f2dd3 100644 --- a/src/value.rs +++ b/src/value.rs @@ -481,7 +481,7 @@ impl Value { /// let n = v.dummy_value(); /// assert_eq!(n, Value::Int(Some(0))); /// ``` - #[expect(clippy::default_trait_access)] + #[expect(clippy::default_trait_access, reason = "Consistency")] pub fn dummy_value(&self) -> Self { match self { Self::Bool(_) => Self::Bool(Some(Default::default())), From df4bdba5b2434dbd1b89066070293720f5f8b1c8 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Mon, 11 Aug 2025 19:19:18 +0800 Subject: [PATCH 21/38] SeaRc::new --- src/types.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/types.rs b/src/types.rs index 0cae80049..e505dd99b 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,6 +1,6 @@ //! Base types used throughout sea-query. -use crate::{FunctionCall, ValueTuple, Values, expr::*, query::*}; +use crate::{expr::*, query::*, FunctionCall, ValueTuple, Values}; use std::{borrow::Cow, fmt::Debug, iter::Flatten}; #[cfg(feature = "backend-postgres")] @@ -100,7 +100,8 @@ impl SeaRc { /// Note that most `Iden`s are statically known /// and their representations aren't actually "rendered" and allocated at runtime. #[allow(clippy::new_ret_no_self)] - pub fn new(i: &I) -> DynIden + #[expect(clippy::needless_pass_by_value, reason = "compatibility")] + pub fn new(i: I) -> DynIden where I: Iden, { @@ -830,8 +831,8 @@ where #[cfg(test)] mod tests { pub use crate::{tests_cfg::*, *}; - pub use Character as CharReexport; use pretty_assertions::assert_eq; + pub use Character as CharReexport; #[test] fn test_identifier() { From 95f3ff1383d6a5800cf748742b3447894aa288ea Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Mon, 11 Aug 2025 19:38:24 +0800 Subject: [PATCH 22/38] Disable must_use_candidate --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c89a3bcaf..75b8ac3d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,10 @@ clippy::use_self, clippy::missing_const_for_fn, clippy::wildcard_imports, - clippy::enum_glob_use + clippy::enum_glob_use, + // We should consider enabling it someday. + // This would help users understand that the function returns a value instead of producing side effects. + clippy::must_use_candidate )] //!
@@ -848,7 +851,7 @@ pub use types::*; pub use value::*; #[cfg(feature = "derive")] -pub use sea_query_derive::{Iden, IdenStatic, enum_def}; +pub use sea_query_derive::{enum_def, Iden, IdenStatic}; #[cfg(all(feature = "attr", not(feature = "derive")))] pub use sea_query_derive::enum_def; From 04c815ee4338eccc05f4054b9406befd36f5b61f Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Mon, 11 Aug 2025 19:45:52 +0800 Subject: [PATCH 23/38] Fix values_list_tuple_prefix --- src/backend/query_builder.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/query_builder.rs b/src/backend/query_builder.rs index 31ee32e2e..83d2b2f0a 100644 --- a/src/backend/query_builder.rs +++ b/src/backend/query_builder.rs @@ -11,7 +11,8 @@ pub trait QueryBuilder: } /// Prefix for tuples in VALUES list (e.g. ROW for MySQL) - fn values_list_tuple_prefix(&self) -> &'static str { + #[expect(clippy::unnecessary_literal_bound, reason = "compatibility")] + fn values_list_tuple_prefix(&self) -> &str { "" } From 9f3d5f08fdddc615265440a9f90de68e8714a367 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Mon, 11 Aug 2025 20:06:52 +0800 Subject: [PATCH 24/38] Disable clippy::manual_assert --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 75b8ac3d0..0429bb3b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,9 @@ clippy::enum_glob_use, // We should consider enabling it someday. // This would help users understand that the function returns a value instead of producing side effects. - clippy::must_use_candidate + clippy::must_use_candidate, + // semantics + clippy::manual_assert )] //!
From d82ab63b993b11b8524277a53d7ea5cdf03920bf Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Mon, 11 Aug 2025 20:13:37 +0800 Subject: [PATCH 25/38] Sort allow list --- src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0429bb3b8..410cd9b76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,11 +3,13 @@ #![deny(missing_debug_implementations)] #![forbid(unsafe_code)] #![allow( + // compatibility clippy::derive_partial_eq_without_eq, - clippy::option_if_let_else, clippy::redundant_pub_crate, - clippy::use_self, clippy::missing_const_for_fn, + // + clippy::option_if_let_else, + clippy::use_self, clippy::wildcard_imports, clippy::enum_glob_use, // We should consider enabling it someday. From 45d83551a2ecf3f6284d08728a4cee8eb6342fb4 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 00:20:50 +0800 Subject: [PATCH 26/38] Disable return_self_not_must_use --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 410cd9b76..cab022356 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ // We should consider enabling it someday. // This would help users understand that the function returns a value instead of producing side effects. clippy::must_use_candidate, + clippy::return_self_not_must_use, // semantics clippy::manual_assert )] @@ -855,7 +856,7 @@ pub use types::*; pub use value::*; #[cfg(feature = "derive")] -pub use sea_query_derive::{enum_def, Iden, IdenStatic}; +pub use sea_query_derive::{Iden, IdenStatic, enum_def}; #[cfg(all(feature = "attr", not(feature = "derive")))] pub use sea_query_derive::enum_def; From fd323dc035ab215514910448915f0c84b6b63771 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 00:23:22 +0800 Subject: [PATCH 27/38] Fmt --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index cab022356..8da04e23a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ // We should consider enabling it someday. // This would help users understand that the function returns a value instead of producing side effects. clippy::must_use_candidate, - clippy::return_self_not_must_use, + clippy::return_self_not_must_use, // semantics clippy::manual_assert )] From 40e642ea42e02e0d09055c10d8476994343db806 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 00:38:36 +0800 Subject: [PATCH 28/38] Fix --- src/backend/mod.rs | 6 +-- src/backend/mysql/table.rs | 12 ++---- src/backend/postgres/table.rs | 1 + src/backend/query_builder.rs | 27 ++++++------- src/query/with.rs | 10 ++--- src/raw_sql.rs | 14 ++++--- src/raw_sql/seaql.rs | 4 +- src/token.rs | 72 +++++++++++++++++------------------ 8 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 098a1add5..5a97467e4 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -51,9 +51,9 @@ pub trait QuotedBuilder { Cow::Owned(s) => { for char in s.chars() { if char == qq { - sql.write_char(char).unwrap() + sql.write_char(char).unwrap(); } - sql.write_char(char).unwrap() + sql.write_char(char).unwrap(); } } }; @@ -93,7 +93,7 @@ pub trait EscapeBuilder { '\r' => buffer.write_str("\\r"), _ => buffer.write_char(c), } - .unwrap() + .unwrap(); } } diff --git a/src/backend/mysql/table.rs b/src/backend/mysql/table.rs index 7f783a44d..cb1a09740 100644 --- a/src/backend/mysql/table.rs +++ b/src/backend/mysql/table.rs @@ -42,13 +42,12 @@ impl TableBuilder for MysqlQueryBuilder { ColumnType::BigInteger | ColumnType::BigUnsigned => write!(sql, "bigint"), ColumnType::Float => write!(sql, "float"), ColumnType::Double => write!(sql, "double"), - ColumnType::Decimal(precision) => match precision { + ColumnType::Decimal(precision) | ColumnType::Money(precision) => match precision { Some((precision, scale)) => write!(sql, "decimal({precision}, {scale})"), None => write!(sql, "decimal"), }, ColumnType::DateTime => write!(sql, "datetime"), - ColumnType::Timestamp => write!(sql, "timestamp"), - ColumnType::TimestampWithTimeZone => write!(sql, "timestamp"), + ColumnType::Timestamp | ColumnType::TimestampWithTimeZone => write!(sql, "timestamp"), ColumnType::Time => write!(sql, "time"), ColumnType::Date => write!(sql, "date"), ColumnType::Year => write!(sql, "year"), @@ -66,12 +65,7 @@ impl TableBuilder for MysqlQueryBuilder { }, ColumnType::VarBit(length) => write!(sql, "bit({length})"), ColumnType::Boolean => write!(sql, "bool"), - ColumnType::Money(precision) => match precision { - Some((precision, scale)) => write!(sql, "decimal({precision}, {scale})"), - None => write!(sql, "decimal"), - }, - ColumnType::Json => write!(sql, "json"), - ColumnType::JsonBinary => write!(sql, "json"), + ColumnType::Json | ColumnType::JsonBinary => write!(sql, "json"), ColumnType::Uuid => write!(sql, "binary(16)"), ColumnType::Custom(iden) => write!(sql, "{iden}"), ColumnType::Enum { variants, .. } => { diff --git a/src/backend/postgres/table.rs b/src/backend/postgres/table.rs index 6e01162fc..413a354d6 100644 --- a/src/backend/postgres/table.rs +++ b/src/backend/postgres/table.rs @@ -93,6 +93,7 @@ impl TableBuilder for PostgresQueryBuilder { "" } + #[expect(clippy::too_many_lines, reason = "TODO")] fn prepare_table_alter_statement(&self, alter: &TableAlterStatement, sql: &mut dyn SqlWriter) { if alter.options.is_empty() { panic!("No alter option found") diff --git a/src/backend/query_builder.rs b/src/backend/query_builder.rs index d01f964bd..0087c0016 100644 --- a/src/backend/query_builder.rs +++ b/src/backend/query_builder.rs @@ -1,4 +1,4 @@ -use std::{fmt, ops::Deref}; +use std::fmt; use crate::*; @@ -1042,6 +1042,7 @@ pub trait QueryBuilder: } #[doc(hidden)] + #[expect(clippy::too_many_lines, reason = "TODO")] fn write_value(&self, buf: &mut dyn Write, value: &Value) -> fmt::Result { match value { Value::Bool(None) @@ -1117,7 +1118,7 @@ pub trait QueryBuilder: Value::Double(Some(v)) => write!(buf, "{v}")?, Value::String(Some(v)) => self.write_string_quoted(v, buf), Value::Char(Some(v)) => { - self.write_string_quoted(std::str::from_utf8(&[*v as u8]).unwrap(), buf) + self.write_string_quoted(std::str::from_utf8(&[*v as u8]).unwrap(), buf); } Value::Bytes(Some(v)) => self.write_bytes(v, buf), #[cfg(feature = "with-json")] @@ -1128,31 +1129,31 @@ pub trait QueryBuilder: Value::ChronoTime(Some(v)) => write!(buf, "'{}'", v.format("%H:%M:%S%.6f")).unwrap(), #[cfg(feature = "with-chrono")] Value::ChronoDateTime(Some(v)) => { - write!(buf, "'{}'", v.format("%Y-%m-%d %H:%M:%S%.6f")).unwrap() + write!(buf, "'{}'", v.format("%Y-%m-%d %H:%M:%S%.6f")).unwrap(); } #[cfg(feature = "with-chrono")] Value::ChronoDateTimeUtc(Some(v)) => { - write!(buf, "'{}'", v.format("%Y-%m-%d %H:%M:%S%.6f %:z")).unwrap() + write!(buf, "'{}'", v.format("%Y-%m-%d %H:%M:%S%.6f %:z")).unwrap(); } #[cfg(feature = "with-chrono")] Value::ChronoDateTimeLocal(Some(v)) => { - write!(buf, "'{}'", v.format("%Y-%m-%d %H:%M:%S%.6f %:z")).unwrap() + write!(buf, "'{}'", v.format("%Y-%m-%d %H:%M:%S%.6f %:z")).unwrap(); } #[cfg(feature = "with-chrono")] Value::ChronoDateTimeWithTimeZone(Some(v)) => { - write!(buf, "'{}'", v.format("%Y-%m-%d %H:%M:%S%.6f %:z")).unwrap() + write!(buf, "'{}'", v.format("%Y-%m-%d %H:%M:%S%.6f %:z")).unwrap(); } #[cfg(feature = "with-time")] Value::TimeDate(Some(v)) => { - write!(buf, "'{}'", v.format(time_format::FORMAT_DATE).unwrap())? + write!(buf, "'{}'", v.format(time_format::FORMAT_DATE).unwrap())?; } #[cfg(feature = "with-time")] Value::TimeTime(Some(v)) => { - write!(buf, "'{}'", v.format(time_format::FORMAT_TIME).unwrap())? + write!(buf, "'{}'", v.format(time_format::FORMAT_TIME).unwrap())?; } #[cfg(feature = "with-time")] Value::TimeDateTime(Some(v)) => { - write!(buf, "'{}'", v.format(time_format::FORMAT_DATETIME).unwrap())? + write!(buf, "'{}'", v.format(time_format::FORMAT_DATETIME).unwrap())?; } #[cfg(feature = "with-time")] Value::TimeDateTimeWithTimeZone(Some(v)) => write!( @@ -1170,19 +1171,19 @@ pub trait QueryBuilder: #[cfg(feature = "with-jiff")] Value::JiffDateTime(Some(v)) => { use crate::with_jiff::JIFF_DATE_TIME_FMT_STR; - write!(buf, "'{}'", v.strftime(JIFF_DATE_TIME_FMT_STR))? + write!(buf, "'{}'", v.strftime(JIFF_DATE_TIME_FMT_STR))?; } #[cfg(feature = "with-jiff")] Value::JiffTimestamp(Some(v)) => { use crate::with_jiff::JIFF_TIMESTAMP_FMT_STR; - write!(buf, "'{}'", v.strftime(JIFF_TIMESTAMP_FMT_STR))? + write!(buf, "'{}'", v.strftime(JIFF_TIMESTAMP_FMT_STR))?; } #[cfg(feature = "with-jiff")] Value::JiffZoned(Some(v)) => { // Zoned map to timestamp with timezone use crate::with_jiff::JIFF_ZONE_FMT_STR; - write!(buf, "'{}'", v.strftime(JIFF_ZONE_FMT_STR))? + write!(buf, "'{}'", v.strftime(JIFF_ZONE_FMT_STR))?; } #[cfg(feature = "with-rust_decimal")] Value::Decimal(Some(v)) => write!(buf, "{v}")?, @@ -1539,7 +1540,7 @@ pub trait QueryBuilder: #[doc(hidden)] /// Write a string surrounded by escaped quotes. fn write_string_quoted(&self, string: &str, buffer: &mut dyn Write) { - write!(buffer, "'{}'", self.escape_string(string)).unwrap() + write!(buffer, "'{}'", self.escape_string(string)).unwrap(); } #[doc(hidden)] diff --git a/src/query/with.rs b/src/query/with.rs index c4ce1cac6..32d72d41e 100644 --- a/src/query/with.rs +++ b/src/query/with.rs @@ -110,9 +110,9 @@ impl CommonTableExpression { self } - /// Create a CTE from a [SelectStatement] if the selections are named columns then this will - /// return a [CommonTableExpression] that has the column names set. The [Self::table_name] is - /// set if the [SelectStatement] from clause contains at least one table. + /// Create a CTE from a [`SelectStatement`] if the selections are named columns then this will + /// return a [`CommonTableExpression`] that has the column names set. The [`Self::table_name`] is + /// set if the [`SelectStatement`] from clause contains at least one table. pub fn from_select(select: SelectStatement) -> Self { let mut cte = Self::default(); cte.try_set_cols_from_selects(&select.selects); @@ -428,7 +428,7 @@ pub struct WithClause { } impl WithClause { - /// Constructs a new [WithClause]. + /// Constructs a new [`WithClause`]. pub fn new() -> Self { Self::default() } @@ -537,7 +537,7 @@ pub struct WithQuery { } impl WithQuery { - /// Constructs a new empty [WithQuery]. + /// Constructs a new empty [`WithQuery`]. pub fn new() -> Self { Self::default() } diff --git a/src/raw_sql.rs b/src/raw_sql.rs index 343deb4e4..f0ef1efea 100644 --- a/src/raw_sql.rs +++ b/src/raw_sql.rs @@ -12,10 +12,14 @@ pub struct RawSqlQueryBuilder { } impl RawSqlQueryBuilder { + #[expect( + clippy::needless_pass_by_value, + reason = "Query builders are all zero size types" + )] pub fn new(backend: T) -> Self { let (placeholder, numbered) = backend.placeholder(); Self { - sql: Default::default(), + sql: String::default(), parameter_index: 1, placeholder, numbered, @@ -91,18 +95,18 @@ mod test { .push_fragment(" ") .push_parameters(1) .push_fragment(", ") - .push_parameters((&b).len()) + .push_parameters(b.len()) .push_fragment(", ") - .push_parameters((&c).len()); + .push_parameters(c.len()); assert_eq!(builder.finish(), "SELECT $1, $2, $3, $4, $5, $6"); let mut values = Values::default(); values.bind(a); - for v in (&b).iter() { + for v in &b { values.bind(v); } - for v in (&c).iter() { + for v in &c { values.bind(v); } diff --git a/src/raw_sql/seaql.rs b/src/raw_sql/seaql.rs index 37837bdc2..93574a98c 100644 --- a/src/raw_sql/seaql.rs +++ b/src/raw_sql/seaql.rs @@ -9,7 +9,7 @@ pub struct Query { pub fn query(sql: &str) -> Query { Query { sql: sql.to_owned(), - values: Values(Default::default()), + values: Values(Vec::default()), } } @@ -33,7 +33,7 @@ pub struct DebugQuery { pub fn debug(sql: &str) -> DebugQuery { DebugQuery { sql: sql.to_owned(), - params: Default::default(), + params: Vec::default(), } } diff --git a/src/token.rs b/src/token.rs index 9cc33e872..c4d60aba3 100644 --- a/src/token.rs +++ b/src/token.rs @@ -68,10 +68,10 @@ impl<'a> Tokenizer<'a> { self.inc(); } - if a != b { - Some(Token::Space(&self.input[a..b])) - } else { + if a == b { None + } else { + Some(Token::Space(&self.input[a..b])) } } @@ -94,10 +94,10 @@ impl<'a> Tokenizer<'a> { } } - if a != b { - Some(Token::Unquoted(&self.input[a..b])) - } else { + if a == b { None + } else { + Some(Token::Unquoted(&self.input[a..b])) } } @@ -121,11 +121,11 @@ impl<'a> Tokenizer<'a> { if self.end() { break; } - if !Self::is_string_escape_for(start, self.get()) { - break; - } else { + if Self::is_string_escape_for(start, self.get()) { b = self.p_c(c); self.inc(); + } else { + break; } } else if !first { escape = !escape && Self::is_escape_char(c); @@ -135,7 +135,7 @@ impl<'a> Tokenizer<'a> { break; } } - if a = b { + if a == b { Some(Token::Quoted(&self.input[a..b])) } else { None @@ -188,10 +188,10 @@ impl<'a> Tokenizer<'a> { } } - if a != b { - Some(Token::Punctuation(&self.input[a..b])) - } else { + if a == b { None + } else { + Some(Token::Punctuation(&self.input[a..b])) } } @@ -327,7 +327,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -358,7 +358,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -380,7 +380,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -392,7 +392,7 @@ mod tests { assert_eq!(tokens, vec![Token::Quoted("\"a\\\"bc\"")]); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -404,7 +404,7 @@ mod tests { assert_eq!(tokens, vec![Token::Unquoted(string)]); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -425,7 +425,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -444,7 +444,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -456,7 +456,7 @@ mod tests { assert_eq!(tokens, vec![Token::Quoted("`a\"b`"), Token::Space(" ")]); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -468,7 +468,7 @@ mod tests { assert_eq!(tokens, vec![Token::Quoted("[ab]"), Token::Space(" ")]); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -487,7 +487,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -506,7 +506,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -525,7 +525,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -544,7 +544,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -569,7 +569,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -588,7 +588,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -600,7 +600,7 @@ mod tests { assert_eq!(tokens, vec![Token::Unquoted(string)]); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -615,7 +615,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -634,7 +634,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -675,7 +675,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -696,7 +696,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -715,7 +715,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -738,7 +738,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } @@ -765,7 +765,7 @@ mod tests { ); assert_eq!( string, - tokens.iter().map(|x| x.as_str()).collect::() + tokens.iter().map(super::Token::as_str).collect::() ); } } From 99260b22038aa73d3a4da0e8547b52f019fbd656 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 00:51:04 +0800 Subject: [PATCH 29/38] Tweak --- src/lib.rs | 13 +++++++------ src/raw_sql.rs | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5c7e6755d..3da248256 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,17 +7,18 @@ clippy::derive_partial_eq_without_eq, clippy::redundant_pub_crate, clippy::missing_const_for_fn, - // - clippy::option_if_let_else, - clippy::use_self, - clippy::wildcard_imports, - clippy::enum_glob_use, // We should consider enabling it someday. // This would help users understand that the function returns a value instead of producing side effects. clippy::must_use_candidate, clippy::return_self_not_must_use, // semantics - clippy::manual_assert + clippy::manual_assert, + // + clippy::option_if_let_else, + clippy::use_self, + clippy::wildcard_imports, + clippy::enum_glob_use, + clippy::missing_errors_doc, )] //!
diff --git a/src/raw_sql.rs b/src/raw_sql.rs index f0ef1efea..d5d3360c0 100644 --- a/src/raw_sql.rs +++ b/src/raw_sql.rs @@ -14,7 +14,7 @@ pub struct RawSqlQueryBuilder { impl RawSqlQueryBuilder { #[expect( clippy::needless_pass_by_value, - reason = "Query builders are all zero size types" + reason = "Query builders are all zero-sized types" )] pub fn new(backend: T) -> Self { let (placeholder, numbered) = backend.placeholder(); From 64d3e4be94939e76c2301dbb8598ac3d1c1be69b Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 00:58:49 +0800 Subject: [PATCH 30/38] Panics docs --- src/query/condition.rs | 6 ++++++ src/query/insert.rs | 4 ++++ src/query/select.rs | 4 ++++ src/query/with.rs | 13 +++++++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/query/condition.rs b/src/query/condition.rs index feba273b2..eb0b23dfc 100644 --- a/src/query/condition.rs +++ b/src/query/condition.rs @@ -651,6 +651,9 @@ impl ConditionHolder { } } + /// # Panics + /// + /// Panics if you mixed `and_where`/`or_where` and `cond_where` in statements. pub fn add_and_or(&mut self, condition: LogicalChainOper) { match &mut self.contents { ConditionHolderContents::Empty => { @@ -663,6 +666,9 @@ impl ConditionHolder { } } + /// # Panics + /// + /// Panics if you mixed `and_where`/`or_where` and `cond_where` in statements. pub fn add_condition(&mut self, mut addition: Condition) { match std::mem::take(&mut self.contents) { ConditionHolderContents::Empty => { diff --git a/src/query/insert.rs b/src/query/insert.rs index 9a5dca8a0..3929302ca 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -381,6 +381,10 @@ impl InsertStatement { /// assert_eq!(query.sql, new_query.sql); /// assert_eq!(query.values, new_query.values); /// ``` + /// + /// # Panics + /// + /// Panics if the length of columns and the lengh of values mismatch. pub fn values_panic(&mut self, values: I) -> &mut Self where I: IntoIterator, diff --git a/src/query/select.rs b/src/query/select.rs index bf7982d06..173c98d97 100644 --- a/src/query/select.rs +++ b/src/query/select.rs @@ -921,6 +921,10 @@ impl SelectStatement { /// r#"SELECT * FROM (VALUES (1, 'hello'), (2, 'world')) AS "x""# /// ); /// ``` + /// + /// # Panics + /// + /// Panics if `value_tuples` is empty. pub fn from_values(&mut self, value_tuples: I, alias: A) -> &mut Self where I: IntoIterator, diff --git a/src/query/with.rs b/src/query/with.rs index 32d72d41e..76d1cb5e1 100644 --- a/src/query/with.rs +++ b/src/query/with.rs @@ -202,8 +202,12 @@ pub struct Search { } impl Search { - /// Create a complete [Search] specification from the [`SearchOrder`] and a [`SelectExpr`]. The - /// given [`SelectExpr`] must have an alias specified. + /// Create a complete [Search] specification from the [`SearchOrder`] and a [`SelectExpr`]. + /// + /// # Panics + /// + /// Panics if the given [`SelectExpr`] doesn't have an alias specified. + /// pub fn new_from_order_and_expr(order: SearchOrder, expr: EXPR) -> Self where EXPR: Into, @@ -233,6 +237,11 @@ impl Search { /// /// The alias of the given [`SelectExpr`] will be the name of the order column generated by this /// clause. + /// + /// # Panics + /// + /// Panics if the given [`SelectExpr`] doesn't have an alias specified. + /// pub fn expr(&mut self, expr: EXPR) -> &mut Self where EXPR: Into, From 3824f3acf622c3dfe345af170c00380b31fc7ea8 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 01:14:00 +0800 Subject: [PATCH 31/38] Fmt --- src/query/insert.rs | 7 +------ src/query/with.rs | 2 -- src/types.rs | 4 ++-- tests/postgres/query.rs | 7 ++----- tests/sqlite/query.rs | 7 ++----- 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/query/insert.rs b/src/query/insert.rs index 3929302ca..15389ed84 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -202,12 +202,7 @@ impl InsertStatement { /// let query = Query::insert() /// .into_table(Glyph::Table) /// .columns([Glyph::Image]) - /// .select_from( - /// Query::select() - /// .expr(Font::Name) - /// .from(Font::Table) - /// .take(), - /// ) + /// .select_from(Query::select().expr(Font::Name).from(Font::Table).take()) /// .unwrap() /// .take(); /// diff --git a/src/query/with.rs b/src/query/with.rs index 76d1cb5e1..8c8d4d374 100644 --- a/src/query/with.rs +++ b/src/query/with.rs @@ -207,7 +207,6 @@ impl Search { /// # Panics /// /// Panics if the given [`SelectExpr`] doesn't have an alias specified. - /// pub fn new_from_order_and_expr(order: SearchOrder, expr: EXPR) -> Self where EXPR: Into, @@ -241,7 +240,6 @@ impl Search { /// # Panics /// /// Panics if the given [`SelectExpr`] doesn't have an alias specified. - /// pub fn expr(&mut self, expr: EXPR) -> &mut Self where EXPR: Into, diff --git a/src/types.rs b/src/types.rs index e505dd99b..dac020e2d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,6 +1,6 @@ //! Base types used throughout sea-query. -use crate::{expr::*, query::*, FunctionCall, ValueTuple, Values}; +use crate::{FunctionCall, ValueTuple, Values, expr::*, query::*}; use std::{borrow::Cow, fmt::Debug, iter::Flatten}; #[cfg(feature = "backend-postgres")] @@ -831,8 +831,8 @@ where #[cfg(test)] mod tests { pub use crate::{tests_cfg::*, *}; - use pretty_assertions::assert_eq; pub use Character as CharReexport; + use pretty_assertions::assert_eq; #[test] fn test_identifier() { diff --git a/tests/postgres/query.rs b/tests/postgres/query.rs index 09a37ed11..499d9facc 100644 --- a/tests/postgres/query.rs +++ b/tests/postgres/query.rs @@ -841,11 +841,8 @@ fn select_48a() { .from(Glyph::Table) .cond_where( Cond::all().add_option(Some( - Expr::tuple([ - Expr::col(Glyph::Aspect), - Expr::value(String::from("100")), - ]) - .in_tuples([(8, String::from("100"))]), + Expr::tuple([Expr::col(Glyph::Aspect), Expr::value(String::from("100"))]) + .in_tuples([(8, String::from("100"))]), )), ) .to_string(PostgresQueryBuilder); diff --git a/tests/sqlite/query.rs b/tests/sqlite/query.rs index 8d82e3196..a82c2d4e6 100644 --- a/tests/sqlite/query.rs +++ b/tests/sqlite/query.rs @@ -756,11 +756,8 @@ fn select_48a() { .from(Glyph::Table) .cond_where( Cond::all().add_option(Some( - Expr::tuple([ - Expr::col(Glyph::Aspect), - Expr::value(String::from("100")), - ]) - .in_tuples([(8, String::from("100"))]), + Expr::tuple([Expr::col(Glyph::Aspect), Expr::value(String::from("100"))]) + .in_tuples([(8, String::from("100"))]), )), ) .to_string(SqliteQueryBuilder); From b8c95c0f35dfa000d7c8e2ec967002e1cbd04fd2 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 01:34:22 +0800 Subject: [PATCH 32/38] More panics docs --- src/value.rs | 4 ++++ src/value/with_array.rs | 9 ++++++--- src/value/with_bigdecimal.rs | 8 +++++++- src/value/with_chrono.rs | 27 ++++++++++++++++++++++++--- src/value/with_ipnetwork.rs | 8 +++++++- src/value/with_jiff.rs | 19 +++++++++++++++++-- src/value/with_json.rs | 7 +++++++ src/value/with_mac_address.rs | 3 +++ src/value/with_rust_decimal.rs | 6 ++++++ src/value/with_time.rs | 15 +++++++++++++++ src/value/with_uuid.rs | 4 ++++ 11 files changed, 100 insertions(+), 10 deletions(-) diff --git a/src/value.rs b/src/value.rs index bd3211e8b..d134e760b 100644 --- a/src/value.rs +++ b/src/value.rs @@ -481,6 +481,10 @@ impl Value { /// let n = v.dummy_value(); /// assert_eq!(n, Value::Int(Some(0))); /// ``` + /// + /// # Panics + /// + /// Panics if parse "0.0.0.0" to [`IpNetwork`] fails. #[expect(clippy::default_trait_access, reason = "Consistency")] pub fn dummy_value(&self) -> Self { match self { diff --git a/src/value/with_array.rs b/src/value/with_array.rs index ef198974f..4410cb5c3 100644 --- a/src/value/with_array.rs +++ b/src/value/with_array.rs @@ -83,7 +83,7 @@ where fn from(x: Vec) -> Value { Value::Array( T::array_type(), - Some(Box::new(x.into_iter().map(|e| e.into()).collect())), + Some(Box::new(x.into_iter().map(Into::into).collect())), ) } } @@ -104,7 +104,7 @@ where fn try_from(v: Value) -> Result { match v { Value::Array(ty, Some(v)) if T::array_type() == ty => { - Ok(v.into_iter().map(|e| e.unwrap()).collect()) + Ok(v.into_iter().map(super::Value::unwrap).collect()) } _ => Err(ValueTypeErr), } @@ -129,9 +129,12 @@ impl Value { matches!(self, Self::Array(_, _)) } + /// # Panics + /// + /// Panics if self is not [`Value::Array`] pub fn as_ref_array(&self) -> Option<&Vec> { match self { - Self::Array(_, v) => v.as_ref().map(|v| v.as_ref()), + Self::Array(_, v) => v.as_ref().map(AsRef::as_ref), _ => panic!("not Value::Array"), } } diff --git a/src/value/with_bigdecimal.rs b/src/value/with_bigdecimal.rs index 9a7ee4264..75e9d4f39 100644 --- a/src/value/with_bigdecimal.rs +++ b/src/value/with_bigdecimal.rs @@ -7,13 +7,19 @@ impl Value { matches!(self, Self::BigDecimal(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::BigDecimal`] pub fn as_ref_big_decimal(&self) -> Option<&BigDecimal> { match self { - Self::BigDecimal(v) => v.as_ref().map(|x| x.as_ref()), + Self::BigDecimal(v) => v.as_ref().map(AsRef::as_ref), _ => panic!("not Value::BigDecimal"), } } + /// # Panics + /// + /// Panics if the conversion to [`f64`] fails pub fn big_decimal_to_f64(&self) -> Option { use bigdecimal::ToPrimitive; self.as_ref_big_decimal().map(|d| d.to_f64().unwrap()) diff --git a/src/value/with_chrono.rs b/src/value/with_chrono.rs index 9e95f5c76..a251c3288 100644 --- a/src/value/with_chrono.rs +++ b/src/value/with_chrono.rs @@ -130,6 +130,9 @@ impl Value { matches!(self, Self::ChronoDateTimeLocal(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::ChronoDate`] pub fn as_ref_chrono_date(&self) -> Option<&NaiveDate> { match self { Self::ChronoDate(v) => v.as_ref(), @@ -137,6 +140,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::ChronoTime`] pub fn as_ref_chrono_time(&self) -> Option<&NaiveTime> { match self { Self::ChronoTime(v) => v.as_ref(), @@ -144,6 +150,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::ChronoDateTime`] pub fn as_ref_chrono_date_time(&self) -> Option<&NaiveDateTime> { match self { Self::ChronoDateTime(v) => v.as_ref(), @@ -151,6 +160,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::ChronoDateTimeUtc`] pub fn as_ref_chrono_date_time_utc(&self) -> Option<&DateTime> { match self { Self::ChronoDateTimeUtc(v) => v.as_ref(), @@ -158,6 +170,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::ChronoDateTimeWithTimeZone`] pub fn as_ref_chrono_date_time_with_time_zone(&self) -> Option<&DateTime> { match self { Self::ChronoDateTimeWithTimeZone(v) => v.as_ref(), @@ -165,6 +180,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::ChronoDateTimeLocal`] pub fn as_ref_chrono_date_time_local(&self) -> Option<&DateTime> { match self { Self::ChronoDateTimeLocal(v) => v.as_ref(), @@ -172,11 +190,14 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not a time value from [`chrono`] crate pub fn chrono_as_naive_utc_in_string(&self) -> Option { match self { - Self::ChronoDate(v) => v.as_ref().map(|v| v.to_string()), - Self::ChronoTime(v) => v.as_ref().map(|v| v.to_string()), - Self::ChronoDateTime(v) => v.as_ref().map(|v| v.to_string()), + Self::ChronoDate(v) => v.as_ref().map(ToString::to_string), + Self::ChronoTime(v) => v.as_ref().map(ToString::to_string), + Self::ChronoDateTime(v) => v.as_ref().map(ToString::to_string), Self::ChronoDateTimeUtc(v) => v.as_ref().map(|v| v.naive_utc().to_string()), Self::ChronoDateTimeLocal(v) => v.as_ref().map(|v| v.naive_utc().to_string()), Self::ChronoDateTimeWithTimeZone(v) => v.as_ref().map(|v| v.naive_utc().to_string()), diff --git a/src/value/with_ipnetwork.rs b/src/value/with_ipnetwork.rs index 42eaffed0..440c1979b 100644 --- a/src/value/with_ipnetwork.rs +++ b/src/value/with_ipnetwork.rs @@ -7,6 +7,9 @@ impl Value { matches!(self, Self::IpNetwork(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::IpNetwork`] pub fn as_ref_ipnetwork(&self) -> Option<&IpNetwork> { match self { Self::IpNetwork(v) => v.as_ref(), @@ -14,9 +17,12 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::IpNetwork`] pub fn as_ipaddr(&self) -> Option { match self { - Self::IpNetwork(v) => v.as_ref().map(|v| v.network()), + Self::IpNetwork(v) => v.as_ref().map(ipnetwork::IpNetwork::network), _ => panic!("not Value::IpNetwork"), } } diff --git a/src/value/with_jiff.rs b/src/value/with_jiff.rs index c072f8f07..dbcae754d 100644 --- a/src/value/with_jiff.rs +++ b/src/value/with_jiff.rs @@ -55,6 +55,9 @@ impl Value { matches!(self, Self::JiffZoned(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::JiffDate`] pub fn as_ref_jiff_date(&self) -> Option<&civil::Date> { match self { Self::JiffDate(v) => v.as_ref(), @@ -62,6 +65,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::JiffTime`] pub fn as_ref_jiff_time(&self) -> Option<&civil::Time> { match self { Self::JiffTime(v) => v.as_ref(), @@ -69,6 +75,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::JiffDateTime`] pub fn as_ref_jiff_date_time(&self) -> Option<&civil::DateTime> { match self { Self::JiffDateTime(v) => v.as_deref(), @@ -76,6 +85,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::JiffTimestamp`] pub fn as_ref_jiff_timestamp(&self) -> Option<&Timestamp> { match self { Self::JiffTimestamp(v) => v.as_deref(), @@ -83,6 +95,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if self is not [`Value::JiffZoned`] pub fn as_ref_jiff_zoned(&self) -> Option<&Zoned> { match self { Self::JiffZoned(v) => v.as_deref(), @@ -99,8 +114,8 @@ impl Value { #[cfg(test)] pub(crate) fn jiff_value_to_string(&self) -> Option { match self { - Self::JiffDate(v) => v.as_ref().map(|v| v.to_string()), - Self::JiffTime(v) => v.as_ref().map(|v| v.to_string()), + Self::JiffDate(v) => v.as_ref().map(ToString::to_string), + Self::JiffTime(v) => v.as_ref().map(ToString::to_string), Self::JiffDateTime(v) => v .as_ref() .map(|v| v.strftime(JIFF_DATE_TIME_FMT_STR).to_string()), diff --git a/src/value/with_json.rs b/src/value/with_json.rs index 7b4cf4ba6..90c7b7deb 100644 --- a/src/value/with_json.rs +++ b/src/value/with_json.rs @@ -7,6 +7,9 @@ impl Value { matches!(self, Self::Json(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::Json`] pub fn as_ref_json(&self) -> Option<&Json> { match self { Self::Json(v) => v.as_ref(), @@ -16,6 +19,10 @@ impl Value { } /// Convert value to json value +/// +/// # Panics +/// +/// Panics if value is [`Value::Bytes`] and it's not valid utf-8 #[allow(clippy::many_single_char_names)] pub fn sea_value_to_json_value(value: &Value) -> Json { match value { diff --git a/src/value/with_mac_address.rs b/src/value/with_mac_address.rs index 834695b31..7816ce717 100644 --- a/src/value/with_mac_address.rs +++ b/src/value/with_mac_address.rs @@ -7,6 +7,9 @@ impl Value { matches!(self, Self::MacAddress(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::MacAddress`] pub fn as_ref_mac_address(&self) -> Option<&MacAddress> { match self { Self::MacAddress(v) => v.as_ref(), diff --git a/src/value/with_rust_decimal.rs b/src/value/with_rust_decimal.rs index 7733a8ebd..18152ee80 100644 --- a/src/value/with_rust_decimal.rs +++ b/src/value/with_rust_decimal.rs @@ -7,6 +7,9 @@ impl Value { matches!(self, Self::Decimal(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::Decimal`] pub fn as_ref_decimal(&self) -> Option<&Decimal> { match self { Self::Decimal(v) => v.as_ref(), @@ -14,6 +17,9 @@ impl Value { } } + /// # Panics + /// + /// Panics if the conversion to [`f64`] fails pub fn decimal_to_f64(&self) -> Option { use rust_decimal::prelude::ToPrimitive; diff --git a/src/value/with_time.rs b/src/value/with_time.rs index 5ea29c6f1..b4f33e52f 100644 --- a/src/value/with_time.rs +++ b/src/value/with_time.rs @@ -42,6 +42,9 @@ impl Value { matches!(self, Self::TimeDate(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::TimeDate`] pub fn as_ref_time_date(&self) -> Option<&time::Date> { match self { Self::TimeDate(v) => v.as_ref(), @@ -55,6 +58,9 @@ impl Value { matches!(self, Self::TimeTime(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::TimeTime`] pub fn as_ref_time_time(&self) -> Option<&time::Time> { match self { Self::TimeTime(v) => v.as_ref(), @@ -68,6 +74,9 @@ impl Value { matches!(self, Self::TimeDateTime(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::TimeDateTime`] pub fn as_ref_time_date_time(&self) -> Option<&PrimitiveDateTime> { match self { Self::TimeDateTime(v) => v.as_ref(), @@ -81,6 +90,9 @@ impl Value { matches!(self, Self::TimeDateTimeWithTimeZone(_)) } + /// # Panics + /// + /// Panics if self is not [`Value::TimeDateTimeWithTimeZone`] pub fn as_ref_time_date_time_with_time_zone(&self) -> Option<&OffsetDateTime> { match self { Self::TimeDateTimeWithTimeZone(v) => v.as_ref(), @@ -90,6 +102,9 @@ impl Value { } impl Value { + /// # Panics + /// + /// Panics if self is not a time value from [`time`] crate pub fn time_as_naive_utc_in_string(&self) -> Option { match self { Self::TimeDate(v) => v diff --git a/src/value/with_uuid.rs b/src/value/with_uuid.rs index c12a8b102..53807b755 100644 --- a/src/value/with_uuid.rs +++ b/src/value/with_uuid.rs @@ -48,6 +48,10 @@ impl Value { pub fn is_uuid(&self) -> bool { matches!(self, Self::Uuid(_)) } + + /// # Panics + /// + /// Panics if self is not [`Value::Uuid`] pub fn as_ref_uuid(&self) -> Option<&Uuid> { match self { Self::Uuid(v) => v.as_ref(), From 97d3995933c4eb5b7824fd10051ed78d6b9ab62a Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 01:38:21 +0800 Subject: [PATCH 33/38] ref_option --- src/value/hashable_value.rs | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/value/hashable_value.rs b/src/value/hashable_value.rs index e51a9234d..34430456a 100644 --- a/src/value/hashable_value.rs +++ b/src/value/hashable_value.rs @@ -17,14 +17,14 @@ impl PartialEq for Value { (Self::SmallUnsigned(l), Self::SmallUnsigned(r)) => l == r, (Self::Unsigned(l), Self::Unsigned(r)) => l == r, (Self::BigUnsigned(l), Self::BigUnsigned(r)) => l == r, - (Self::Float(l), Self::Float(r)) => cmp_f32(l, r), - (Self::Double(l), Self::Double(r)) => cmp_f64(l, r), + (Self::Float(l), Self::Float(r)) => cmp_f32(l.as_ref(), r.as_ref()), + (Self::Double(l), Self::Double(r)) => cmp_f64(l.as_ref(), r.as_ref()), (Self::String(l), Self::String(r)) => l == r, (Self::Char(l), Self::Char(r)) => l == r, (Self::Bytes(l), Self::Bytes(r)) => l == r, #[cfg(feature = "with-json")] - (Self::Json(l), Self::Json(r)) => cmp_json(l, r), + (Self::Json(l), Self::Json(r)) => cmp_json(l.as_ref(), r.as_ref()), #[cfg(feature = "with-chrono")] (Self::ChronoDate(l), Self::ChronoDate(r)) => l == r, @@ -74,7 +74,7 @@ impl PartialEq for Value { } #[cfg(feature = "postgres-vector")] - (Self::Vector(l), Self::Vector(r)) => cmp_vector(l, r), + (Self::Vector(l), Self::Vector(r)) => cmp_vector(l.as_ref(), r.as_ref()), #[cfg(feature = "with-ipnetwork")] (Self::IpNetwork(l), Self::IpNetwork(r)) => l == r, @@ -102,14 +102,14 @@ impl Hash for Value { Value::SmallUnsigned(v) => v.hash(state), Value::Unsigned(v) => v.hash(state), Value::BigUnsigned(v) => v.hash(state), - Value::Float(v) => hash_f32(v, state), - Value::Double(v) => hash_f64(v, state), + Value::Float(v) => hash_f32(v.as_ref(), state), + Value::Double(v) => hash_f64(v.as_ref(), state), Value::String(v) => v.hash(state), Value::Char(v) => v.hash(state), Value::Bytes(v) => v.hash(state), #[cfg(feature = "with-json")] - Value::Json(value) => hash_json(value, state), + Value::Json(value) => hash_json(value.as_ref(), state), #[cfg(feature = "with-chrono")] Value::ChronoDate(naive_date) => naive_date.hash(state), @@ -160,7 +160,7 @@ impl Hash for Value { } #[cfg(feature = "postgres-vector")] - Value::Vector(vector) => hash_vector(vector, state), + Value::Vector(vector) => hash_vector(vector.as_ref(), state), #[cfg(feature = "with-ipnetwork")] Value::IpNetwork(ip_network) => ip_network.hash(state), @@ -171,21 +171,21 @@ impl Hash for Value { } } -fn hash_f32(v: &Option, state: &mut H) { +fn hash_f32(v: Option<&f32>, state: &mut H) { match v { Some(v) => OrderedFloat(*v).hash(state), None => "null".hash(state), } } -fn hash_f64(v: &Option, state: &mut H) { +fn hash_f64(v: Option<&f64>, state: &mut H) { match v { Some(v) => OrderedFloat(*v).hash(state), None => "null".hash(state), } } -fn cmp_f32(l: &Option, r: &Option) -> bool { +fn cmp_f32(l: Option<&f32>, r: Option<&f32>) -> bool { match (l, r) { (Some(l), Some(r)) => OrderedFloat(*l).eq(&OrderedFloat(*r)), (None, None) => true, @@ -193,7 +193,7 @@ fn cmp_f32(l: &Option, r: &Option) -> bool { } } -fn cmp_f64(l: &Option, r: &Option) -> bool { +fn cmp_f64(l: Option<&f64>, r: Option<&f64>) -> bool { match (l, r) { (Some(l), Some(r)) => OrderedFloat(*l).eq(&OrderedFloat(*r)), (None, None) => true, @@ -202,7 +202,7 @@ fn cmp_f64(l: &Option, r: &Option) -> bool { } #[cfg(feature = "with-json")] -fn hash_json(v: &Option, state: &mut H) { +fn hash_json(v: Option<&Json>, state: &mut H) { match v { Some(v) => serde_json::to_string(v).unwrap().hash(state), None => "null".hash(state), @@ -210,7 +210,7 @@ fn hash_json(v: &Option, state: &mut H) { } #[cfg(feature = "with-json")] -fn cmp_json(l: &Option, r: &Option) -> bool { +fn cmp_json(l: Option<&Json>, r: Option<&Json>) -> bool { match (l, r) { (Some(l), Some(r)) => serde_json::to_string(l) .unwrap() @@ -221,11 +221,11 @@ fn cmp_json(l: &Option, r: &Option) -> bool { } #[cfg(feature = "postgres-vector")] -fn hash_vector(v: &Option, state: &mut H) { +fn hash_vector(v: Option<&pgvector::Vector>, state: &mut H) { match v { Some(v) => { - for &value in v.as_slice().iter() { - hash_f32(&Some(value), state); + for &value in v.as_slice() { + hash_f32(Some(&value), state); } } None => "null".hash(state), @@ -233,7 +233,7 @@ fn hash_vector(v: &Option, state: &mut H) { } #[cfg(feature = "postgres-vector")] -fn cmp_vector(l: &Option, r: &Option) -> bool { +fn cmp_vector(l: Option<&pgvector::Vector>, r: Option<&pgvector::Vector>) -> bool { match (l, r) { (Some(l), Some(r)) => { let (l, r) = (l.as_slice(), r.as_slice()); @@ -241,7 +241,7 @@ fn cmp_vector(l: &Option, r: &Option) -> boo return false; } for (l, r) in l.iter().zip(r.iter()) { - if !cmp_f32(&Some(*l), &Some(*r)) { + if !cmp_f32(Some(l), Some(r)) { return false; } } From 2653ebd1c05c69ec7ee556c746edccad7484fde6 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 01:38:38 +0800 Subject: [PATCH 34/38] same match arms --- src/tests_cfg.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tests_cfg.rs b/src/tests_cfg.rs index 256249cf8..ff1d290db 100644 --- a/src/tests_cfg.rs +++ b/src/tests_cfg.rs @@ -30,9 +30,8 @@ pub type Char = Character; impl Iden for Character { fn unquoted(&self) -> &str { match self { - Self::Table => "character", Self::Id => "id", - Self::Character => "character", + Self::Character | Self::Table => "character", Self::FontSize => "font_size", Self::SizeW => "size_w", Self::SizeH => "size_h", From c3f2be9559e37a70ec5600fe5d4ccc4d220f1c74 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 01:54:30 +0800 Subject: [PATCH 35/38] Fix --- src/token.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/token.rs b/src/token.rs index c4d60aba3..bebb91456 100644 --- a/src/token.rs +++ b/src/token.rs @@ -136,9 +136,9 @@ impl<'a> Tokenizer<'a> { } } if a == b { - Some(Token::Quoted(&self.input[a..b])) - } else { None + } else { + Some(Token::Quoted(&self.input[a..b])) } } @@ -274,10 +274,10 @@ impl Token<'_> { pub fn as_str(&self) -> &str { match self { - Token::Quoted(string) - | Token::Unquoted(string) - | Token::Space(string) - | Token::Punctuation(string) => string, + Self::Quoted(string) + | Self::Unquoted(string) + | Self::Space(string) + | Self::Punctuation(string) => string, } } From b4e5e1e39bf05f8f115b3f782d6a798a3739b938 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 02:15:30 +0800 Subject: [PATCH 36/38] Fix test --- src/query/insert.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/query/insert.rs b/src/query/insert.rs index 15389ed84..09fb00a1a 100644 --- a/src/query/insert.rs +++ b/src/query/insert.rs @@ -202,7 +202,12 @@ impl InsertStatement { /// let query = Query::insert() /// .into_table(Glyph::Table) /// .columns([Glyph::Image]) - /// .select_from(Query::select().expr(Font::Name).from(Font::Table).take()) + /// .select_from( + /// Query::select() + /// .expr(Expr::col(Font::Name)) + /// .from(Font::Table) + /// .take(), + /// ) /// .unwrap() /// .take(); /// From a704d785add8bf195fbf19b4e2000d52108f398d Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 03:44:05 +0800 Subject: [PATCH 37/38] Revert change of partition_by_custom --- src/query/window.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/query/window.rs b/src/query/window.rs index 420ce6193..4921837fc 100644 --- a/src/query/window.rs +++ b/src/query/window.rs @@ -103,7 +103,8 @@ impl WindowStatement { } /// Construct a new [`WindowStatement`] with PARTITION BY custom - pub fn partition_by_custom(col: &T) -> Self + #[expect(clippy::needless_pass_by_value, reason = "This needs more discussion")] + pub fn partition_by_custom(col: T) -> Self where T: ToString, { From eabb972b95f8dc5375aca52574c9e680ae8862a5 Mon Sep 17 00:00:00 2001 From: Huliiiii <134658521+Huliiiiii@users.noreply.github.com> Date: Wed, 13 Aug 2025 21:15:03 +0800 Subject: [PATCH 38/38] Workflow --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5b8ac56d0..1cb5eb128 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -55,7 +55,7 @@ jobs: with: toolchain: stable components: clippy - - run: cargo clippy --features=all-features --workspace -- -D warnings + - run: cargo clippy --features=all-features --workspace -- -D warnings -A clippy::semicolon_if_nothing_returned - run: cargo clippy --manifest-path sea-query-sqlx/Cargo.toml --workspace --features runtime-async-std-rustls --features=with-chrono,with-json,with-rust_decimal,with-bigdecimal,with-uuid,with-time,with-ipnetwork,with-mac_address,postgres-array,postgres-vector -- -D warnings - run: cargo clippy --manifest-path sea-query-rusqlite/Cargo.toml --all-features --workspace -- -D warnings - run: cargo clippy --manifest-path sea-query-postgres/Cargo.toml --all-features --workspace -- -D warnings