From 11781082ba52806d4e33957069d2979bf16de1a4 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 28 Sep 2021 19:00:55 +0800 Subject: [PATCH 01/17] Throw error if none of the db rows are affected --- src/error.rs | 2 ++ src/executor/insert.rs | 4 ++-- src/executor/update.rs | 5 +++++ tests/crud/updates.rs | 13 +++++++++---- tests/uuid_tests.rs | 17 ++++++++++++++++- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/error.rs b/src/error.rs index 09f80b0a..f8aff775 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,7 @@ pub enum DbErr { Conn(String), Exec(String), Query(String), + RecordNotFound(String), } impl std::error::Error for DbErr {} @@ -13,6 +14,7 @@ impl std::fmt::Display for DbErr { Self::Conn(s) => write!(f, "Connection Error: {}", s), Self::Exec(s) => write!(f, "Execution Error: {}", s), Self::Query(s) => write!(f, "Query Error: {}", s), + Self::RecordNotFound(s) => write!(f, "RecordNotFound Error: {}", s), } } } diff --git a/src/executor/insert.rs b/src/executor/insert.rs index d580f110..a44867f7 100644 --- a/src/executor/insert.rs +++ b/src/executor/insert.rs @@ -1,6 +1,6 @@ use crate::{ - error::*, ActiveModelTrait, DatabaseConnection, DbBackend, EntityTrait, Insert, PrimaryKeyTrait, - Statement, TryFromU64, + error::*, ActiveModelTrait, DatabaseConnection, DbBackend, EntityTrait, Insert, + PrimaryKeyTrait, Statement, TryFromU64, }; use sea_query::InsertStatement; use std::{future::Future, marker::PhantomData}; diff --git a/src/executor/update.rs b/src/executor/update.rs index 6c7a9873..c6668d6b 100644 --- a/src/executor/update.rs +++ b/src/executor/update.rs @@ -73,6 +73,11 @@ where // Only Statement impl Send async fn exec_update(statement: Statement, db: &DatabaseConnection) -> Result { let result = db.execute(statement).await?; + if result.rows_affected() <= 0 { + return Err(DbErr::RecordNotFound( + "None of the database rows are affected".to_owned(), + )); + } Ok(UpdateResult { rows_affected: result.rows_affected(), }) diff --git a/tests/crud/updates.rs b/tests/crud/updates.rs index c2048f9b..262031ef 100644 --- a/tests/crud/updates.rs +++ b/tests/crud/updates.rs @@ -1,5 +1,6 @@ pub use super::*; use rust_decimal_macros::dec; +use sea_orm::DbErr; use uuid::Uuid; pub async fn test_update_cake(db: &DbConn) { @@ -119,10 +120,14 @@ pub async fn test_update_deleted_customer(db: &DbConn) { ..Default::default() }; - let _customer_update_res: customer::ActiveModel = customer - .update(db) - .await - .expect("could not update customer"); + let customer_update_res = customer.update(db).await; + + assert_eq!( + customer_update_res, + Err(DbErr::RecordNotFound( + "None of the database rows are affected".to_owned() + )) + ); assert_eq!(Customer::find().count(db).await.unwrap(), init_n_customers); diff --git a/tests/uuid_tests.rs b/tests/uuid_tests.rs index e58daca4..052f57d7 100644 --- a/tests/uuid_tests.rs +++ b/tests/uuid_tests.rs @@ -1,7 +1,7 @@ pub mod common; pub use common::{bakery_chain::*, setup::*, TestContext}; -use sea_orm::{entity::prelude::*, DatabaseConnection, IntoActiveModel}; +use sea_orm::{entity::prelude::*, DatabaseConnection, IntoActiveModel, Set}; #[sea_orm_macros::test] #[cfg(any( @@ -40,5 +40,20 @@ pub async fn create_metadata(db: &DatabaseConnection) -> Result<(), DbErr> { } ); + let update_res = Metadata::update(metadata::ActiveModel { + value: Set("0.22".to_owned()), + ..metadata.clone().into_active_model() + }) + .filter(metadata::Column::Uuid.eq(Uuid::default())) + .exec(db) + .await; + + assert_eq!( + update_res, + Err(DbErr::RecordNotFound( + "None of the database rows are affected".to_owned() + )) + ); + Ok(()) } From 966f7ff9a85fcb133fb863ca1af709da5ed2c7fb Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Tue, 28 Sep 2021 19:06:02 +0800 Subject: [PATCH 02/17] Fix clippy warning --- src/executor/update.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/executor/update.rs b/src/executor/update.rs index c6668d6b..7cb60f3e 100644 --- a/src/executor/update.rs +++ b/src/executor/update.rs @@ -73,7 +73,7 @@ where // Only Statement impl Send async fn exec_update(statement: Statement, db: &DatabaseConnection) -> Result { let result = db.execute(statement).await?; - if result.rows_affected() <= 0 { + if result.rows_affected() == 0 { return Err(DbErr::RecordNotFound( "None of the database rows are affected".to_owned(), )); From f4218dec56b0745b75f88171ee7e0202115e9397 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Thu, 30 Sep 2021 12:47:01 +0800 Subject: [PATCH 03/17] Test mock connection --- src/executor/update.rs | 105 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/src/executor/update.rs b/src/executor/update.rs index 7cb60f3e..bcbafefc 100644 --- a/src/executor/update.rs +++ b/src/executor/update.rs @@ -82,3 +82,108 @@ async fn exec_update(statement: Statement, db: &DatabaseConnection) -> Result Result<(), DbErr> { + let db = MockDatabase::new(DbBackend::Postgres) + .append_query_results(vec![ + vec![cake::Model { + id: 1, + name: "Cheese Cake".to_owned(), + }], + vec![], + vec![], + ]) + .append_exec_results(vec![ + MockExecResult { + last_insert_id: 0, + rows_affected: 1, + }, + MockExecResult { + last_insert_id: 0, + rows_affected: 0, + }, + MockExecResult { + last_insert_id: 0, + rows_affected: 0, + }, + ]) + .into_connection(); + + let model = cake::Model { + id: 1, + name: "New York Cheese".to_owned(), + }; + + assert_eq!( + cake::ActiveModel { + name: Set("Cheese Cake".to_owned()), + ..model.into_active_model() + } + .update(&db) + .await?, + cake::Model { + id: 1, + name: "Cheese Cake".to_owned(), + } + .into_active_model() + ); + + let model = cake::Model { + id: 2, + name: "New York Cheese".to_owned(), + }; + + assert_eq!( + cake::ActiveModel { + name: Set("Cheese Cake".to_owned()), + ..model.clone().into_active_model() + } + .update(&db) + .await, + Err(DbErr::RecordNotFound( + "None of the database rows are affected".to_owned() + )) + ); + + assert_eq!( + cake::Entity::update(cake::ActiveModel { + name: Set("Cheese Cake".to_owned()), + ..model.into_active_model() + }) + .exec(&db) + .await, + Err(DbErr::RecordNotFound( + "None of the database rows are affected".to_owned() + )) + ); + + assert_eq!( + db.into_transaction_log(), + vec![ + Transaction::from_sql_and_values( + DbBackend::Postgres, + r#"UPDATE "cake" SET "name" = $1 WHERE "cake"."id" = $2"#, + vec!["Cheese Cake".into(), 1i32.into()] + ), + Transaction::from_sql_and_values( + DbBackend::Postgres, + r#"UPDATE "cake" SET "name" = $1 WHERE "cake"."id" = $2"#, + vec!["Cheese Cake".into(), 2i32.into()] + ), + Transaction::from_sql_and_values( + DbBackend::Postgres, + r#"UPDATE "cake" SET "name" = $1 WHERE "cake"."id" = $2"#, + vec!["Cheese Cake".into(), 2i32.into()] + ), + ] + ); + + Ok(()) + } +} From 602690e9a7c8c281cc33a185234fe1ee09492c47 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Thu, 30 Sep 2021 19:16:55 +0800 Subject: [PATCH 04/17] Remove unneeded --- src/executor/update.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/executor/update.rs b/src/executor/update.rs index bcbafefc..2bc5ed80 100644 --- a/src/executor/update.rs +++ b/src/executor/update.rs @@ -91,14 +91,6 @@ mod tests { #[smol_potat::test] async fn update_record_not_found_1() -> Result<(), DbErr> { let db = MockDatabase::new(DbBackend::Postgres) - .append_query_results(vec![ - vec![cake::Model { - id: 1, - name: "Cheese Cake".to_owned(), - }], - vec![], - vec![], - ]) .append_exec_results(vec![ MockExecResult { last_insert_id: 0, From 91fb97c12ae1e4ce4ebf87977f960198f475e365 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Mon, 4 Oct 2021 11:18:42 +0800 Subject: [PATCH 05/17] `Update::many()` will not raise `DbErr::RecordNotFound` error --- src/executor/update.rs | 65 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/src/executor/update.rs b/src/executor/update.rs index 2bc5ed80..b564165c 100644 --- a/src/executor/update.rs +++ b/src/executor/update.rs @@ -7,9 +7,10 @@ use std::future::Future; #[derive(Clone, Debug)] pub struct Updater { query: UpdateStatement, + check_record_exists: bool, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct UpdateResult { pub rows_affected: u64, } @@ -39,7 +40,15 @@ where impl Updater { pub fn new(query: UpdateStatement) -> Self { - Self { query } + Self { + query, + check_record_exists: false, + } + } + + pub fn check_record_exists(mut self) -> Self { + self.check_record_exists = true; + self } pub fn exec( @@ -47,7 +56,7 @@ impl Updater { db: &DatabaseConnection, ) -> impl Future> + '_ { let builder = db.get_database_backend(); - exec_update(builder.build(&self.query), db) + exec_update(builder.build(&self.query), db, self.check_record_exists) } } @@ -66,14 +75,18 @@ async fn exec_update_and_return_original( where A: ActiveModelTrait, { - Updater::new(query).exec(db).await?; + Updater::new(query).check_record_exists().exec(db).await?; Ok(model) } // Only Statement impl Send -async fn exec_update(statement: Statement, db: &DatabaseConnection) -> Result { +async fn exec_update( + statement: Statement, + db: &DatabaseConnection, + check_record_exists: bool, +) -> Result { let result = db.execute(statement).await?; - if result.rows_affected() == 0 { + if check_record_exists && result.rows_affected() == 0 { return Err(DbErr::RecordNotFound( "None of the database rows are affected".to_owned(), )); @@ -87,6 +100,7 @@ async fn exec_update(statement: Statement, db: &DatabaseConnection) -> Result Result<(), DbErr> { @@ -104,6 +118,14 @@ mod tests { last_insert_id: 0, rows_affected: 0, }, + MockExecResult { + last_insert_id: 0, + rows_affected: 0, + }, + MockExecResult { + last_insert_id: 0, + rows_affected: 0, + }, ]) .into_connection(); @@ -145,6 +167,18 @@ mod tests { assert_eq!( cake::Entity::update(cake::ActiveModel { + name: Set("Cheese Cake".to_owned()), + ..model.clone().into_active_model() + }) + .exec(&db) + .await, + Err(DbErr::RecordNotFound( + "None of the database rows are affected".to_owned() + )) + ); + + assert_eq!( + Update::one(cake::ActiveModel { name: Set("Cheese Cake".to_owned()), ..model.into_active_model() }) @@ -155,6 +189,15 @@ mod tests { )) ); + assert_eq!( + Update::many(cake::Entity) + .col_expr(cake::Column::Name, Expr::value("Cheese Cake".to_owned())) + .filter(cake::Column::Id.eq(2)) + .exec(&db) + .await, + Ok(UpdateResult { rows_affected: 0 }) + ); + assert_eq!( db.into_transaction_log(), vec![ @@ -173,6 +216,16 @@ mod tests { r#"UPDATE "cake" SET "name" = $1 WHERE "cake"."id" = $2"#, vec!["Cheese Cake".into(), 2i32.into()] ), + Transaction::from_sql_and_values( + DbBackend::Postgres, + r#"UPDATE "cake" SET "name" = $1 WHERE "cake"."id" = $2"#, + vec!["Cheese Cake".into(), 2i32.into()] + ), + Transaction::from_sql_and_values( + DbBackend::Postgres, + r#"UPDATE "cake" SET "name" = $1 WHERE "cake"."id" = $2"#, + vec!["Cheese Cake".into(), 2i32.into()] + ), ] ); From af93ea44ad970cd04476730b80cb613f7471ca8c Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Mon, 4 Oct 2021 12:10:06 +0800 Subject: [PATCH 06/17] Fix clippy warnings --- src/executor/query.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/executor/query.rs b/src/executor/query.rs index 0248fa5c..e6c2d124 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -126,12 +126,12 @@ macro_rules! try_getable_unsigned { ( $type: ty ) => { impl TryGetable for $type { fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { - let column = format!("{}{}", pre, col); + let _column = format!("{}{}", pre, col); match &res.row { #[cfg(feature = "sqlx-mysql")] QueryResultRow::SqlxMySql(row) => { use sqlx::Row; - row.try_get::, _>(column.as_str()) + row.try_get::, _>(_column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) .and_then(|opt| opt.ok_or(TryGetError::Null)) } @@ -142,13 +142,13 @@ macro_rules! try_getable_unsigned { #[cfg(feature = "sqlx-sqlite")] QueryResultRow::SqlxSqlite(row) => { use sqlx::Row; - row.try_get::, _>(column.as_str()) + row.try_get::, _>(_column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) .and_then(|opt| opt.ok_or(TryGetError::Null)) } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(_column.as_str()).map_err(|e| { debug_print!("{:#?}", e.to_string()); TryGetError::Null }), @@ -162,12 +162,12 @@ macro_rules! try_getable_mysql { ( $type: ty ) => { impl TryGetable for $type { fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { - let column = format!("{}{}", pre, col); + let _column = format!("{}{}", pre, col); match &res.row { #[cfg(feature = "sqlx-mysql")] QueryResultRow::SqlxMySql(row) => { use sqlx::Row; - row.try_get::, _>(column.as_str()) + row.try_get::, _>(_column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) .and_then(|opt| opt.ok_or(TryGetError::Null)) } @@ -181,7 +181,7 @@ macro_rules! try_getable_mysql { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(_column.as_str()).map_err(|e| { debug_print!("{:#?}", e.to_string()); TryGetError::Null }), @@ -195,7 +195,7 @@ macro_rules! try_getable_postgres { ( $type: ty ) => { impl TryGetable for $type { fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result { - let column = format!("{}{}", pre, col); + let _column = format!("{}{}", pre, col); match &res.row { #[cfg(feature = "sqlx-mysql")] QueryResultRow::SqlxMySql(_) => { @@ -204,7 +204,7 @@ macro_rules! try_getable_postgres { #[cfg(feature = "sqlx-postgres")] QueryResultRow::SqlxPostgres(row) => { use sqlx::Row; - row.try_get::, _>(column.as_str()) + row.try_get::, _>(_column.as_str()) .map_err(|e| TryGetError::DbErr(crate::sqlx_error_to_query_err(e))) .and_then(|opt| opt.ok_or(TryGetError::Null)) } @@ -214,7 +214,7 @@ macro_rules! try_getable_postgres { } #[cfg(feature = "mock")] #[allow(unused_variables)] - QueryResultRow::Mock(row) => row.try_get(column.as_str()).map_err(|e| { + QueryResultRow::Mock(row) => row.try_get(_column.as_str()).map_err(|e| { debug_print!("{:#?}", e.to_string()); TryGetError::Null }), From b74b1f343f6e8090029db381018aba30f71e764f Mon Sep 17 00:00:00 2001 From: "baoyachi. Aka Rust Hairy crabs" Date: Mon, 4 Oct 2021 12:57:34 +0800 Subject: [PATCH 07/17] Add debug_query and debug_query_stmt macro (#189) --- src/query/mod.rs | 2 + src/query/util.rs | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/query/util.rs diff --git a/src/query/mod.rs b/src/query/mod.rs index 54cc12dd..5d2be142 100644 --- a/src/query/mod.rs +++ b/src/query/mod.rs @@ -8,6 +8,7 @@ mod json; mod select; mod traits; mod update; +mod util; pub use combine::{SelectA, SelectB}; pub use delete::*; @@ -19,5 +20,6 @@ pub use json::*; pub use select::*; pub use traits::*; pub use update::*; +pub use util::*; pub use crate::{InsertResult, Statement, UpdateResult, Value, Values}; diff --git a/src/query/util.rs b/src/query/util.rs new file mode 100644 index 00000000..7e771f7c --- /dev/null +++ b/src/query/util.rs @@ -0,0 +1,112 @@ +use crate::{DatabaseConnection, DbBackend, QueryTrait, Statement}; + +#[derive(Debug)] +pub struct DebugQuery<'a, Q, T> { + pub query: &'a Q, + pub value: T, +} + +macro_rules! debug_query_build { + ($impl_obj:ty, $db_expr:expr) => { + impl<'a, Q> DebugQuery<'a, Q, $impl_obj> + where + Q: QueryTrait, + { + pub fn build(&self) -> Statement { + let func = $db_expr; + let db_backend = func(self); + self.query.build(db_backend) + } + } + }; +} + +debug_query_build!(DbBackend, |x: &DebugQuery<_, DbBackend>| x.value); +debug_query_build!(&DbBackend, |x: &DebugQuery<_, &DbBackend>| *x.value); +debug_query_build!( + DatabaseConnection, + |x: &DebugQuery<_, DatabaseConnection>| x.value.get_database_backend() +); +debug_query_build!( + &DatabaseConnection, + |x: &DebugQuery<_, &DatabaseConnection>| x.value.get_database_backend() +); + +/// Helper to get a `Statement` from an object that impl `QueryTrait`. +/// +/// # Example +/// +/// ``` +/// # #[cfg(feature = "mock")] +/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend}; +/// # +/// # let conn = MockDatabase::new(DbBackend::Postgres) +/// # .into_connection(); +/// # +/// use sea_orm::{entity::*, query::*, tests_cfg::cake, debug_query_stmt}; +/// +/// let c = cake::Entity::insert( +/// cake::ActiveModel { +/// id: ActiveValue::set(1), +/// name: ActiveValue::set("Apple Pie".to_owned()), +/// }); +/// +/// let raw_sql = debug_query_stmt!(&c, &conn).to_string(); +/// assert_eq!(raw_sql, r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#); +/// +/// let raw_sql = debug_query_stmt!(&c, conn).to_string(); +/// assert_eq!(raw_sql, r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#); +/// +/// let raw_sql = debug_query_stmt!(&c, DbBackend::MySql).to_string(); +/// assert_eq!(raw_sql, r#"INSERT INTO `cake` (`id`, `name`) VALUES (1, 'Apple Pie')"#); +/// +/// let raw_sql = debug_query_stmt!(&c, &DbBackend::MySql).to_string(); +/// assert_eq!(raw_sql, r#"INSERT INTO `cake` (`id`, `name`) VALUES (1, 'Apple Pie')"#); +/// +/// ``` +#[macro_export] +macro_rules! debug_query_stmt { + ($query:expr,$value:expr) => { + $crate::DebugQuery { + query: $query, + value: $value, + } + .build(); + }; +} + +/// Helper to get a raw SQL string from an object that impl `QueryTrait`. +/// +/// # Example +/// +/// ``` +/// # #[cfg(feature = "mock")] +/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend}; +/// # +/// # let conn = MockDatabase::new(DbBackend::Postgres) +/// # .into_connection(); +/// # +/// use sea_orm::{entity::*, query::*, tests_cfg::cake,debug_query}; +/// +/// let c = cake::Entity::insert( +/// cake::ActiveModel { +/// id: ActiveValue::set(1), +/// name: ActiveValue::set("Apple Pie".to_owned()), +/// }); +/// +/// let raw_sql = debug_query!(&c, &conn); +/// assert_eq!(raw_sql, r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#); +/// +/// let raw_sql = debug_query!(&c, conn); +/// assert_eq!(raw_sql, r#"INSERT INTO "cake" ("id", "name") VALUES (1, 'Apple Pie')"#); +/// +/// let raw_sql = debug_query!(&c, DbBackend::Sqlite); +/// assert_eq!(raw_sql, r#"INSERT INTO `cake` (`id`, `name`) VALUES (1, 'Apple Pie')"#); +/// +/// ``` +#[macro_export] +macro_rules! debug_query { + ($query:expr,$value:expr) => { + $crate::debug_query_stmt!($query, $value).to_string(); + }; +} From 4fd5d56dbf1bc95b6219219231e27098bfed9d9e Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Mon, 4 Oct 2021 13:13:36 +0800 Subject: [PATCH 08/17] cargo +nightly fmt --- src/docs.rs | 2 +- src/entity/model.rs | 10 ++++------ src/executor/query.rs | 2 +- src/executor/select.rs | 9 ++++----- src/lib.rs | 2 +- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/docs.rs b/src/docs.rs index bab054ef..4d1226c3 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -163,4 +163,4 @@ //! }, //! ) //! } -//! ``` \ No newline at end of file +//! ``` diff --git a/src/entity/model.rs b/src/entity/model.rs index 318b8e70..cd96b22e 100644 --- a/src/entity/model.rs +++ b/src/entity/model.rs @@ -69,12 +69,10 @@ pub trait FromQueryResult: Sized { /// /// assert_eq!( /// res, - /// vec![ - /// SelectResult { - /// name: "Chocolate Forest".to_owned(), - /// num_of_cakes: 2, - /// }, - /// ] + /// vec![SelectResult { + /// name: "Chocolate Forest".to_owned(), + /// num_of_cakes: 2, + /// },] /// ); /// # /// # Ok(()) diff --git a/src/executor/query.rs b/src/executor/query.rs index e6c2d124..a164e911 100644 --- a/src/executor/query.rs +++ b/src/executor/query.rs @@ -326,7 +326,7 @@ pub trait TryGetableMany: Sized { /// # ]]) /// # .into_connection(); /// # - /// use sea_orm::{entity::*, query::*, tests_cfg::cake, EnumIter, DeriveIden, TryGetableMany}; + /// use sea_orm::{entity::*, query::*, tests_cfg::cake, DeriveIden, EnumIter, TryGetableMany}; /// /// #[derive(EnumIter, DeriveIden)] /// enum ResultCol { diff --git a/src/executor/select.rs b/src/executor/select.rs index bb386722..0db698f0 100644 --- a/src/executor/select.rs +++ b/src/executor/select.rs @@ -207,10 +207,7 @@ where /// .all(&db) /// .await?; /// - /// assert_eq!( - /// res, - /// vec![("Chocolate Forest".to_owned(), 2i64)] - /// ); + /// assert_eq!(res, vec![("Chocolate Forest".to_owned(), 2i64)]); /// # /// # Ok(()) /// # }); @@ -222,7 +219,9 @@ where /// vec![ /// r#"SELECT "cake"."name" AS "cake_name", COUNT("cake"."id") AS "num_of_cakes""#, /// r#"FROM "cake" GROUP BY "cake"."name""#, - /// ].join(" ").as_str(), + /// ] + /// .join(" ") + /// .as_str(), /// vec![] /// )] /// ); diff --git a/src/lib.rs b/src/lib.rs index 910044a5..6ddc442c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -265,6 +265,7 @@ )] mod database; +mod docs; mod driver; pub mod entity; pub mod error; @@ -273,7 +274,6 @@ pub mod query; pub mod schema; #[doc(hidden)] pub mod tests_cfg; -mod docs; mod util; pub use database::*; From 632290469b649d40b45760ff00f687a1467c5508 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Mon, 4 Oct 2021 21:01:02 +0800 Subject: [PATCH 09/17] Fixup --- src/query/util.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/query/util.rs b/src/query/util.rs index 7e771f7c..545f8376 100644 --- a/src/query/util.rs +++ b/src/query/util.rs @@ -1,4 +1,4 @@ -use crate::{DatabaseConnection, DbBackend, QueryTrait, Statement}; +use crate::{database::*, QueryTrait, Statement}; #[derive(Debug)] pub struct DebugQuery<'a, Q, T> { @@ -38,7 +38,7 @@ debug_query_build!( /// /// ``` /// # #[cfg(feature = "mock")] -/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend}; +/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, DbBackend}; /// # /// # let conn = MockDatabase::new(DbBackend::Postgres) /// # .into_connection(); @@ -81,7 +81,7 @@ macro_rules! debug_query_stmt { /// /// ``` /// # #[cfg(feature = "mock")] -/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, Transaction, DbBackend}; +/// # use sea_orm::{error::*, tests_cfg::*, MockDatabase, MockExecResult, DbBackend}; /// # /// # let conn = MockDatabase::new(DbBackend::Postgres) /// # .into_connection(); From 8990261d703cbeecb6e1292efd7e58f50d060eaf Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Wed, 6 Oct 2021 12:28:46 +0800 Subject: [PATCH 10/17] Bind null custom types --- Cargo.toml | 2 +- tests/common/bakery_chain/metadata.rs | 4 ++-- tests/common/setup/schema.rs | 4 ++-- tests/parallel_tests.rs | 12 ++++++------ tests/uuid_tests.rs | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a4466152..b9675c38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ futures-util = { version = "^0.3" } log = { version = "^0.4", optional = true } rust_decimal = { version = "^1", optional = true } sea-orm-macros = { version = "^0.2.4", path = "sea-orm-macros", optional = true } -sea-query = { version = "^0.16.5", features = ["thread-safe"] } +sea-query = { version = "^0.17.0", features = ["thread-safe"] } sea-strum = { version = "^0.21", features = ["derive", "sea-orm"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1", optional = true } diff --git a/tests/common/bakery_chain/metadata.rs b/tests/common/bakery_chain/metadata.rs index de513a22..2c297cd3 100644 --- a/tests/common/bakery_chain/metadata.rs +++ b/tests/common/bakery_chain/metadata.rs @@ -10,8 +10,8 @@ pub struct Model { pub key: String, pub value: String, pub bytes: Vec, - pub date: Date, - pub time: Time, + pub date: Option, + pub time: Option