* feat: Introducing feature "sqlx-error" Purpose of this feature is to not convert errors given from sqlx into strings to ease further analysis of the error and react to it accordingly. This implementation uses a feature switch and an additional error kind to avoid interfering with existing implementations without this feature enabled. See discussion https://github.com/SeaQL/sea-orm/discussions/709 * fix: Align feature "sqlx-error" with merged Migration error kind Due to the merge, an other error kind had been introduced and the DbErr became Eq and Clone, however Eq cannot easily be derived from, so I went back to PartialEq, and since the sqlx error does not implement clone, this was converted into an Arc, to allow cloning of the new kind too. * fix: Repairing failing jobs Several jobs had failed as I missed to correct the return values of a few methods in transaction.rs and had a wrong understanding of map_err at that point. * feat: realigning with latest changes in sea-orm, different approach Instead of the former approach to introduce a new error kind, now the existing error types get extended, for now only Exec and Query, because these are the most relevant for the requirement context. Afterwards it might still be possible to add some further detail information. See discussion https://github.com/SeaQL/sea-orm/discussions/709 * Update src/driver/sqlx_mysql.rs Integrating fixes done by @Sculas Co-authored-by: Sculas <contact@sculas.xyz> * Update src/driver/sqlx_postgres.rs Integrating fixes done by @Sculas Co-authored-by: Sculas <contact@sculas.xyz> * Update src/driver/sqlx_sqlite.rs Integrating fixes done by @Sculas Co-authored-by: Sculas <contact@sculas.xyz> * feat: reworking feature with thiserror Following the latest suggestions I changed the implementation to utilize `thiserror`. Now there are more error kinds to be able to see the different kinds directly in src/error.rs To ensure the behaviour is as expected, I also introduce a further test, which checks for a uniqueness failure. Co-authored-by: Sculas <contact@sculas.xyz>
63 lines
1.7 KiB
Rust
63 lines
1.7 KiB
Rust
pub mod create_baker;
|
|
pub mod create_cake;
|
|
pub mod create_lineitem;
|
|
pub mod create_order;
|
|
pub mod deletes;
|
|
pub mod error;
|
|
pub mod updates;
|
|
|
|
pub use create_baker::*;
|
|
pub use create_cake::*;
|
|
pub use create_lineitem::*;
|
|
pub use create_order::*;
|
|
pub use deletes::*;
|
|
pub use error::*;
|
|
pub use updates::*;
|
|
|
|
pub use super::common::bakery_chain::*;
|
|
use sea_orm::{entity::*, DbConn};
|
|
|
|
pub async fn test_create_bakery(db: &DbConn) {
|
|
let seaside_bakery = bakery::ActiveModel {
|
|
name: Set("SeaSide Bakery".to_owned()),
|
|
profit_margin: Set(10.4),
|
|
..Default::default()
|
|
};
|
|
let res = Bakery::insert(seaside_bakery)
|
|
.exec(db)
|
|
.await
|
|
.expect("could not insert bakery");
|
|
|
|
let bakery: Option<bakery::Model> = Bakery::find_by_id(res.last_insert_id)
|
|
.one(db)
|
|
.await
|
|
.expect("could not find bakery");
|
|
|
|
assert!(bakery.is_some());
|
|
let bakery_model = bakery.unwrap();
|
|
assert_eq!(bakery_model.name, "SeaSide Bakery");
|
|
assert!((bakery_model.profit_margin - 10.4).abs() < f64::EPSILON);
|
|
}
|
|
|
|
pub async fn test_create_customer(db: &DbConn) {
|
|
let customer_kate = customer::ActiveModel {
|
|
name: Set("Kate".to_owned()),
|
|
notes: Set(Some("Loves cheese cake".to_owned())),
|
|
..Default::default()
|
|
};
|
|
let res = Customer::insert(customer_kate)
|
|
.exec(db)
|
|
.await
|
|
.expect("could not insert customer");
|
|
|
|
let customer: Option<customer::Model> = Customer::find_by_id(res.last_insert_id)
|
|
.one(db)
|
|
.await
|
|
.expect("could not find customer");
|
|
|
|
assert!(customer.is_some());
|
|
let customer_model = customer.unwrap();
|
|
assert_eq!(customer_model.name, "Kate");
|
|
assert_eq!(customer_model.notes, Some("Loves cheese cake".to_owned()));
|
|
}
|