diff --git a/sea-orm-macros/src/strum/helpers/mod.rs b/sea-orm-macros/src/strum/helpers/mod.rs index 77049eb4b..5f076579b 100644 --- a/sea-orm-macros/src/strum/helpers/mod.rs +++ b/sea-orm-macros/src/strum/helpers/mod.rs @@ -1,4 +1,3 @@ -pub use self::case_style::CaseStyleHelpers; pub use self::type_props::HasTypeProperties; pub use self::variant_props::HasStrumVariantProperties; diff --git a/src/database/db_connection.rs b/src/database/db_connection.rs index 29815ec9f..d7f3fbce2 100644 --- a/src/database/db_connection.rs +++ b/src/database/db_connection.rs @@ -19,23 +19,23 @@ use std::sync::Arc; pub enum DatabaseConnection { /// Create a MYSQL database connection and pool #[cfg(feature = "sqlx-mysql")] - SqlxMySqlPoolConnection(crate::SqlxMySqlPoolConnection), + SqlxMySqlPoolConnection(crate::driver::SqlxMySqlPoolConnection), /// Create a PostgreSQL database connection and pool #[cfg(feature = "sqlx-postgres")] - SqlxPostgresPoolConnection(crate::SqlxPostgresPoolConnection), + SqlxPostgresPoolConnection(crate::driver::SqlxPostgresPoolConnection), /// Create a SQLite database connection and pool #[cfg(feature = "sqlx-sqlite")] - SqlxSqlitePoolConnection(crate::SqlxSqlitePoolConnection), + SqlxSqlitePoolConnection(crate::driver::SqlxSqlitePoolConnection), /// Create a Mock database connection useful for testing #[cfg(feature = "mock")] - MockDatabaseConnection(Arc), + MockDatabaseConnection(Arc), /// Create a Proxy database connection useful for proxying #[cfg(feature = "proxy")] - ProxyDatabaseConnection(Arc), + ProxyDatabaseConnection(Arc), /// The connection to the database has been severed Disconnected, @@ -74,9 +74,9 @@ pub(crate) enum InnerConnection { #[cfg(feature = "sqlx-sqlite")] Sqlite(PoolConnection), #[cfg(feature = "mock")] - Mock(Arc), + Mock(Arc), #[cfg(feature = "proxy")] - Proxy(Arc), + Proxy(Arc), } impl std::fmt::Debug for DatabaseConnection { @@ -397,7 +397,7 @@ impl DatabaseConnection { /// # Panics /// /// Panics if [DbConn] is not a mock connection. - pub fn as_mock_connection(&self) -> &crate::MockDatabaseConnection { + pub fn as_mock_connection(&self) -> &crate::driver::MockDatabaseConnection { match self { DatabaseConnection::MockDatabaseConnection(mock_conn) => mock_conn, _ => panic!("Not mock connection"), @@ -426,7 +426,7 @@ impl DatabaseConnection { /// # Panics /// /// Panics if [DbConn] is not a proxy connection. - pub fn as_proxy_connection(&self) -> &crate::ProxyDatabaseConnection { + pub fn as_proxy_connection(&self) -> &crate::driver::ProxyDatabaseConnection { match self { DatabaseConnection::ProxyDatabaseConnection(proxy_conn) => proxy_conn, _ => panic!("Not proxy connection"), diff --git a/src/database/mock.rs b/src/database/mock.rs index f038d8933..de11c7ea1 100644 --- a/src/database/mock.rs +++ b/src/database/mock.rs @@ -1,7 +1,9 @@ +#![allow(clippy::unwrap_used, clippy::expect_used)] use crate::{ - error::*, DatabaseConnection, DbBackend, EntityTrait, ExecResult, ExecResultHolder, Iden, - IdenStatic, Iterable, MockDatabaseConnection, MockDatabaseTrait, ModelTrait, QueryResult, - QueryResultRow, SelectA, SelectB, Statement, + driver::{MockDatabaseConnection, MockDatabaseTrait}, + error::*, + DatabaseConnection, DbBackend, EntityTrait, ExecResult, ExecResultHolder, Iden, IdenStatic, + Iterable, ModelTrait, QueryResult, QueryResultRow, SelectA, SelectB, Statement, }; use sea_query::{Value, ValueType, Values}; use std::{collections::BTreeMap, sync::Arc}; diff --git a/src/database/mod.rs b/src/database/mod.rs index a844d1c85..aa6541d4e 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -71,19 +71,19 @@ impl Database { #[cfg(feature = "sqlx-mysql")] if DbBackend::MySql.is_prefix_of(&opt.url) { - return crate::SqlxMySqlConnector::connect(opt).await; + return crate::driver::SqlxMySqlConnector::connect(opt).await; } #[cfg(feature = "sqlx-postgres")] if DbBackend::Postgres.is_prefix_of(&opt.url) { - return crate::SqlxPostgresConnector::connect(opt).await; + return crate::driver::SqlxPostgresConnector::connect(opt).await; } #[cfg(feature = "sqlx-sqlite")] if DbBackend::Sqlite.is_prefix_of(&opt.url) { - return crate::SqlxSqliteConnector::connect(opt).await; + return crate::driver::SqlxSqliteConnector::connect(opt).await; } #[cfg(feature = "mock")] - if crate::MockDatabaseConnector::accepts(&opt.url) { - return crate::MockDatabaseConnector::connect(&opt.url).await; + if crate::driver::MockDatabaseConnector::accepts(&opt.url) { + return crate::driver::MockDatabaseConnector::connect(&opt.url).await; } Err(conn_err(format!( @@ -101,19 +101,19 @@ impl Database { ) -> Result { match db_type { DbBackend::MySql => { - return crate::ProxyDatabaseConnector::connect( + return crate::driver::ProxyDatabaseConnector::connect( DbBackend::MySql, proxy_func_arc.to_owned(), ); } DbBackend::Postgres => { - return crate::ProxyDatabaseConnector::connect( + return crate::driver::ProxyDatabaseConnector::connect( DbBackend::Postgres, proxy_func_arc.to_owned(), ); } DbBackend::Sqlite => { - return crate::ProxyDatabaseConnector::connect( + return crate::driver::ProxyDatabaseConnector::connect( DbBackend::Sqlite, proxy_func_arc.to_owned(), ); diff --git a/src/database/stream/query.rs b/src/database/stream/query.rs index 30642bde0..8af12d3e4 100644 --- a/src/database/stream/query.rs +++ b/src/database/stream/query.rs @@ -89,14 +89,14 @@ impl #[cfg(feature = "mock")] impl From<( - Arc, + Arc, Statement, Option, )> for QueryStream { fn from( (conn, stmt, metric_callback): ( - Arc, + Arc, Statement, Option, ), @@ -108,14 +108,14 @@ impl #[cfg(feature = "proxy")] impl From<( - Arc, + Arc, Statement, Option, )> for QueryStream { fn from( (conn, stmt, metric_callback): ( - Arc, + Arc, Statement, Option, ), diff --git a/src/database/transaction.rs b/src/database/transaction.rs index 3216ffd99..15d157201 100644 --- a/src/database/transaction.rs +++ b/src/database/transaction.rs @@ -1,10 +1,10 @@ +#[cfg(feature = "sqlx-dep")] +use crate::driver::{sqlx_error_to_exec_err, sqlx_error_to_query_err}; use crate::{ debug_print, error::*, AccessMode, ConnectionTrait, DbBackend, DbErr, ExecResult, InnerConnection, IsolationLevel, QueryResult, Statement, StreamTrait, TransactionStream, TransactionTrait, }; -#[cfg(feature = "sqlx-dep")] -use crate::{sqlx_error_to_exec_err, sqlx_error_to_query_err}; use futures::lock::Mutex; #[cfg(feature = "sqlx-dep")] use sqlx::{pool::PoolConnection, TransactionManager}; @@ -81,7 +81,7 @@ impl DatabaseTransaction { #[cfg(feature = "mock")] pub(crate) async fn new_mock( - inner: Arc, + inner: Arc, metric_callback: Option, ) -> Result { let backend = inner.get_database_backend(); @@ -97,7 +97,7 @@ impl DatabaseTransaction { #[cfg(feature = "proxy")] pub(crate) async fn new_proxy( - inner: Arc, + inner: Arc, metric_callback: Option, ) -> Result { let backend = inner.get_database_backend(); diff --git a/src/driver/mock.rs b/src/driver/mock.rs index af3145cbb..70d34ba3d 100644 --- a/src/driver/mock.rs +++ b/src/driver/mock.rs @@ -84,15 +84,15 @@ impl MockDatabaseConnector { } #[cfg(feature = "sqlx-mysql")] - if crate::SqlxMySqlConnector::accepts(string) { + if crate::driver::SqlxMySqlConnector::accepts(string) { return connect_mock_db!(DbBackend::MySql); } #[cfg(feature = "sqlx-postgres")] - if crate::SqlxPostgresConnector::accepts(string) { + if crate::driver::SqlxPostgresConnector::accepts(string) { return connect_mock_db!(DbBackend::Postgres); } #[cfg(feature = "sqlx-sqlite")] - if crate::SqlxSqliteConnector::accepts(string) { + if crate::driver::SqlxSqliteConnector::accepts(string) { return connect_mock_db!(DbBackend::Sqlite); } connect_mock_db!(DbBackend::Postgres) @@ -100,6 +100,8 @@ impl MockDatabaseConnector { } impl MockDatabaseConnection { + /// # Panics + /// /// Create a connection to the [MockDatabase] pub fn new(m: M) -> Self where @@ -116,6 +118,8 @@ impl MockDatabaseConnection { &self.mocker } + /// # Panics + /// /// Get the [DatabaseBackend](crate::DatabaseBackend) being used by the [MockDatabase] pub fn get_database_backend(&self) -> DbBackend { self.mocker diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index 51a1842a7..01d615886 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -36,6 +36,7 @@ impl std::fmt::Debug for SqlxMySqlPoolConnection { impl SqlxMySqlConnector { /// Check if the URI provided corresponds to `mysql://` for a MySQL database + #[allow(unused_variables)] pub fn accepts(string: &str) -> bool { string.starts_with("mysql://") && string.parse::().is_ok() } @@ -65,16 +66,6 @@ impl SqlxMySqlConnector { } } -impl SqlxMySqlConnector { - /// Instantiate a sqlx pool connection to a [DatabaseConnection] - pub fn from_sqlx_mysql_pool(pool: MySqlPool) -> DatabaseConnection { - DatabaseConnection::SqlxMySqlPoolConnection(SqlxMySqlPoolConnection { - pool, - metric_callback: None, - }) - } -} - impl SqlxMySqlPoolConnection { /// Execute a [Statement] on a MySQL backend #[instrument(level = "trace")] diff --git a/src/driver/sqlx_postgres.rs b/src/driver/sqlx_postgres.rs index 1214f6c29..656692701 100644 --- a/src/driver/sqlx_postgres.rs +++ b/src/driver/sqlx_postgres.rs @@ -36,6 +36,7 @@ impl std::fmt::Debug for SqlxPostgresPoolConnection { impl SqlxPostgresConnector { /// Check if the URI provided corresponds to `postgres://` for a PostgreSQL database + #[allow(unused_variables)] pub fn accepts(string: &str) -> bool { string.starts_with("postgres://") && string.parse::().is_ok() } @@ -80,16 +81,6 @@ impl SqlxPostgresConnector { } } -impl SqlxPostgresConnector { - /// Instantiate a sqlx pool connection to a [DatabaseConnection] - pub fn from_sqlx_postgres_pool(pool: PgPool) -> DatabaseConnection { - DatabaseConnection::SqlxPostgresPoolConnection(SqlxPostgresPoolConnection { - pool, - metric_callback: None, - }) - } -} - impl SqlxPostgresPoolConnection { /// Execute a [Statement] on a PostgreSQL backend #[instrument(level = "trace")] diff --git a/src/driver/sqlx_sqlite.rs b/src/driver/sqlx_sqlite.rs index 8a9924cf5..9ab2571fd 100644 --- a/src/driver/sqlx_sqlite.rs +++ b/src/driver/sqlx_sqlite.rs @@ -36,6 +36,7 @@ impl std::fmt::Debug for SqlxSqlitePoolConnection { impl SqlxSqliteConnector { /// Check if the URI provided corresponds to `sqlite:` for a SQLite database + #[allow(unused_variables)] pub fn accepts(string: &str) -> bool { string.starts_with("sqlite:") && string.parse::().is_ok() } @@ -72,16 +73,6 @@ impl SqlxSqliteConnector { } } -impl SqlxSqliteConnector { - /// Instantiate a sqlx pool connection to a [DatabaseConnection] - pub fn from_sqlx_sqlite_pool(pool: SqlitePool) -> DatabaseConnection { - DatabaseConnection::SqlxSqlitePoolConnection(SqlxSqlitePoolConnection { - pool, - metric_callback: None, - }) - } -} - impl SqlxSqlitePoolConnection { /// Execute a [Statement] on a SQLite backend #[instrument(level = "trace")] diff --git a/src/entity/active_model.rs b/src/entity/active_model.rs index c0e344840..7ec8cb205 100644 --- a/src/entity/active_model.rs +++ b/src/entity/active_model.rs @@ -1,3 +1,4 @@ +#![allow(clippy::unwrap_used, clippy::expect_used)] use crate::{ error::*, ConnectionTrait, DeleteResult, EntityTrait, Iterable, PrimaryKeyToColumn, Value, }; diff --git a/src/lib.rs b/src/lib.rs index 4026b5636..65e0d1cac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -345,6 +345,7 @@ pub mod tests_cfg; mod util; pub use database::*; +#[allow(unused_imports)] pub use driver::*; pub use entity::*; pub use error::*; diff --git a/src/query/combine.rs b/src/query/combine.rs index 61d957f74..621690961 100644 --- a/src/query/combine.rs +++ b/src/query/combine.rs @@ -2,6 +2,7 @@ use crate::{ ColumnTrait, EntityTrait, IdenStatic, Iterable, QueryTrait, Select, SelectTwo, SelectTwoMany, }; use core::marker::PhantomData; +#[allow(unused_imports)] pub use sea_query::JoinType; use sea_query::{Alias, ColumnRef, Iden, Order, SeaRc, SelectExpr, SelectStatement, SimpleExpr}; diff --git a/src/query/json.rs b/src/query/json.rs index da91fb3b6..901ce358d 100644 --- a/src/query/json.rs +++ b/src/query/json.rs @@ -1,3 +1,4 @@ +#![allow(clippy::unwrap_used, clippy::expect_used)] use crate::{error::*, FromQueryResult, QueryResult}; use serde_json::Map; pub use serde_json::Value as JsonValue; diff --git a/src/query/mod.rs b/src/query/mod.rs index 559eba176..227ba48c0 100644 --- a/src/query/mod.rs +++ b/src/query/mod.rs @@ -15,7 +15,6 @@ pub use combine::{SelectA, SelectB}; pub use delete::*; pub use helper::*; pub use insert::*; -pub use join::*; #[cfg(feature = "with-json")] pub use json::*; pub use loader::*; diff --git a/src/query/select.rs b/src/query/select.rs index f747fb582..4ac04aeb9 100644 --- a/src/query/select.rs +++ b/src/query/select.rs @@ -1,7 +1,6 @@ use crate::{ColumnTrait, EntityTrait, Iterable, QueryFilter, QueryOrder, QuerySelect, QueryTrait}; use core::fmt::Debug; use core::marker::PhantomData; -pub use sea_query::JoinType; use sea_query::{Expr, IntoColumnRef, SelectStatement, SimpleExpr}; /// Defines a structure to perform select operations diff --git a/tests/active_enum_tests.rs b/tests/active_enum_tests.rs index 1a38f3b71..81daddd60 100644 --- a/tests/active_enum_tests.rs +++ b/tests/active_enum_tests.rs @@ -1,14 +1,15 @@ pub mod common; -use active_enum::Entity as ActiveEnum; -use active_enum_child::Entity as ActiveEnumChild; +use active_enum::Entity as ActiveEnumEntity; pub use common::{features::*, setup::*, TestContext}; use pretty_assertions::assert_eq; +#[cfg(feature = "sqlx-postgres")] +use sea_orm::QueryTrait; use sea_orm::{ entity::prelude::*, entity::*, sea_query::{BinOper, Expr}, - ActiveEnum as ActiveEnumTrait, DatabaseConnection, QueryTrait, + ActiveEnum as ActiveEnumTrait, DatabaseConnection, }; #[sea_orm_macros::test] @@ -146,6 +147,7 @@ pub async fn insert_active_enum(db: &DatabaseConnection) -> Result<(), DbErr> { let select_with_tea_not_in = Entity::find() .filter(Column::Tea.is_not_null()) .filter(Column::Tea.is_not_in([Tea::BreakfastTea])); + #[cfg(feature = "sqlx-postgres")] assert_eq!( select_with_tea_not_in @@ -162,6 +164,7 @@ pub async fn insert_active_enum(db: &DatabaseConnection) -> Result<(), DbErr> { ] .join(" ") ); + assert_eq!(model, select_with_tea_not_in.one(db).await?.unwrap()); let res = model.delete(db).await?; @@ -338,7 +341,7 @@ pub async fn find_related_active_enum(db: &DatabaseConnection) -> Result<(), DbE }] ); assert_eq!( - ActiveEnum::find() + ActiveEnumEntity::find() .find_with_related(ActiveEnumChild) .all(db) .await?, @@ -359,7 +362,7 @@ pub async fn find_related_active_enum(db: &DatabaseConnection) -> Result<(), DbE )] ); assert_eq!( - ActiveEnum::find() + ActiveEnumEntity::find() .find_also_related(ActiveEnumChild) .all(db) .await?, @@ -464,7 +467,7 @@ pub async fn find_linked_active_enum(db: &DatabaseConnection) -> Result<(), DbEr }] ); assert_eq!( - ActiveEnum::find() + ActiveEnumEntity::find() .find_also_linked(active_enum::ActiveEnumChildLink) .all(db) .await?, @@ -485,7 +488,7 @@ pub async fn find_linked_active_enum(db: &DatabaseConnection) -> Result<(), DbEr )] ); assert_eq!( - ActiveEnum::find() + ActiveEnumEntity::find() .find_with_linked(active_enum::ActiveEnumChildLink) .all(db) .await?, @@ -620,7 +623,7 @@ mod tests { .join(" ") ); - let _select = ActiveEnum::find().find_also_related(ActiveEnumChild); + let _select = ActiveEnumEntity::find().find_also_related(ActiveEnumChild); #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] { assert_eq!( @@ -707,7 +710,7 @@ mod tests { .join(" ") ); - let _select = ActiveEnum::find().find_also_linked(active_enum::ActiveEnumChildLink); + let _select = ActiveEnumEntity::find().find_also_linked(active_enum::ActiveEnumChildLink); #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))] { assert_eq!( diff --git a/tests/common/features/json_vec.rs b/tests/common/features/json_vec.rs index 5eb623496..a1263b79e 100644 --- a/tests/common/features/json_vec.rs +++ b/tests/common/features/json_vec.rs @@ -22,11 +22,7 @@ impl TryGetableFromJson for StringVec {} impl From for Value { fn from(source: StringVec) -> Self { - sea_orm::Value::Json( - serde_json::to_value(&source) - .ok() - .map(|s| std::boxed::Box::new(s)), - ) + sea_orm::Value::Json(serde_json::to_value(source).ok().map(std::boxed::Box::new)) } } diff --git a/tests/common/setup/mod.rs b/tests/common/setup/mod.rs index 2cdc00d21..2385cfb0c 100644 --- a/tests/common/setup/mod.rs +++ b/tests/common/setup/mod.rs @@ -74,7 +74,6 @@ pub async fn tear_down(base_url: &str, db_name: &str) { format!("DROP DATABASE IF EXISTS \"{db_name}\";"), )) .await; - } else { }; } diff --git a/tests/cursor_tests.rs b/tests/cursor_tests.rs index ef8280573..6b90c34f4 100644 --- a/tests/cursor_tests.rs +++ b/tests/cursor_tests.rs @@ -2,9 +2,7 @@ pub mod common; pub use common::{features::*, setup::*, TestContext}; use pretty_assertions::assert_eq; -use sea_orm::{ - entity::prelude::*, DerivePartialModel, FromQueryResult, QueryOrder, QuerySelect, Set, -}; +use sea_orm::{entity::prelude::*, DerivePartialModel, FromQueryResult, QuerySelect, Set}; use serde_json::json; #[sea_orm_macros::test] @@ -18,7 +16,7 @@ async fn main() -> Result<(), DbErr> { create_tables(&ctx.db).await?; create_insert_default(&ctx.db).await?; cursor_pagination(&ctx.db).await?; - schema::create_tables(&ctx.db).await?; + bakery_chain_schema::create_tables(&ctx.db).await?; create_baker_cake(&ctx.db).await?; cursor_related_pagination(&ctx.db).await?; ctx.delete().await; @@ -281,7 +279,8 @@ pub async fn cursor_pagination(db: &DatabaseConnection) -> Result<(), DbErr> { } use common::bakery_chain::{ - baker, bakery, cake, cakes_bakers, schema, Baker, Bakery, Cake, CakesBakers, + baker, bakery, cake, cakes_bakers, schema as bakery_chain_schema, Baker, Bakery, Cake, + CakesBakers, }; fn bakery(i: i32) -> bakery::Model { @@ -318,8 +317,6 @@ fn cakebaker(cake: char, baker: char) -> CakeBakerlite { } pub async fn create_baker_cake(db: &DatabaseConnection) -> Result<(), DbErr> { - use sea_orm::IntoActiveModel; - let mut bakeries: Vec = vec![]; // bakeries named from 1 to 10 for i in 1..=10 { diff --git a/tests/empty_insert_tests.rs b/tests/empty_insert_tests.rs index ea61a37fb..6bc01f3a1 100644 --- a/tests/empty_insert_tests.rs +++ b/tests/empty_insert_tests.rs @@ -9,7 +9,6 @@ pub use sea_orm::{ pub use crud::*; // use common::bakery_chain::*; use sea_orm::{DbConn, TryInsertResult}; -use sea_query::OnConflict; #[sea_orm_macros::test] #[cfg(any( @@ -38,7 +37,7 @@ pub async fn test(db: &DbConn) { assert!(matches!(res, Ok(TryInsertResult::Inserted(_)))); - let double_seaside_bakery = bakery::ActiveModel { + let _double_seaside_bakery = bakery::ActiveModel { name: Set("SeaSide Bakery".to_owned()), profit_margin: Set(10.4), id: Set(1), diff --git a/tests/returning_tests.rs b/tests/returning_tests.rs index bcdcc38d6..68abbf775 100644 --- a/tests/returning_tests.rs +++ b/tests/returning_tests.rs @@ -79,7 +79,7 @@ async fn main() -> Result<(), DbErr> { should_panic(expected = "Database backend doesn't support RETURNING") )] async fn update_many() { - pub use common::{features::*, setup::*, TestContext}; + pub use common::{features::*, TestContext}; use edit_log::*; let run = || async {