fix lints and warnings
also clean up impl_into_active_value macro
This commit is contained in:
parent
904700cf56
commit
bdd9133aa6
@ -81,7 +81,7 @@ impl Relation {
|
||||
let module_name = if let Some(module_name) = self.get_module_name() {
|
||||
format!("super::{}::", module_name)
|
||||
} else {
|
||||
format!("")
|
||||
String::new()
|
||||
};
|
||||
let ref_entity = format!("{}Entity", module_name);
|
||||
match self.rel_type {
|
||||
|
@ -108,15 +108,14 @@ impl EntityTransformer {
|
||||
.get_indexes()
|
||||
.iter()
|
||||
.filter(|index| index.is_primary_key())
|
||||
.map(|index| {
|
||||
.flat_map(|index| {
|
||||
index
|
||||
.get_index_spec()
|
||||
.get_column_names()
|
||||
.into_iter()
|
||||
.map(|name| PrimaryKey { name })
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.flatten(),
|
||||
}),
|
||||
);
|
||||
let entity = Entity {
|
||||
table_name: table_name.clone(),
|
||||
|
@ -220,7 +220,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
|
||||
let field_type = &field.ty;
|
||||
let temp = quote! { #field_type }
|
||||
.to_string() //E.g.: "Option < String >"
|
||||
.replace(" ", "");
|
||||
.replace(' ', "");
|
||||
let temp = if temp.starts_with("Option<") {
|
||||
nullable = true;
|
||||
&temp[7..(temp.len() - 1)]
|
||||
|
@ -636,10 +636,10 @@ where
|
||||
}
|
||||
|
||||
macro_rules! impl_into_active_value {
|
||||
($ty: ty, $fn: ident) => {
|
||||
($ty: ty) => {
|
||||
impl IntoActiveValue<$ty> for $ty {
|
||||
fn into_active_value(self) -> ActiveValue<$ty> {
|
||||
$fn(self)
|
||||
Set(self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -663,55 +663,55 @@ macro_rules! impl_into_active_value {
|
||||
};
|
||||
}
|
||||
|
||||
impl_into_active_value!(bool, Set);
|
||||
impl_into_active_value!(i8, Set);
|
||||
impl_into_active_value!(i16, Set);
|
||||
impl_into_active_value!(i32, Set);
|
||||
impl_into_active_value!(i64, Set);
|
||||
impl_into_active_value!(u8, Set);
|
||||
impl_into_active_value!(u16, Set);
|
||||
impl_into_active_value!(u32, Set);
|
||||
impl_into_active_value!(u64, Set);
|
||||
impl_into_active_value!(f32, Set);
|
||||
impl_into_active_value!(f64, Set);
|
||||
impl_into_active_value!(&'static str, Set);
|
||||
impl_into_active_value!(String, Set);
|
||||
impl_into_active_value!(bool);
|
||||
impl_into_active_value!(i8);
|
||||
impl_into_active_value!(i16);
|
||||
impl_into_active_value!(i32);
|
||||
impl_into_active_value!(i64);
|
||||
impl_into_active_value!(u8);
|
||||
impl_into_active_value!(u16);
|
||||
impl_into_active_value!(u32);
|
||||
impl_into_active_value!(u64);
|
||||
impl_into_active_value!(f32);
|
||||
impl_into_active_value!(f64);
|
||||
impl_into_active_value!(&'static str);
|
||||
impl_into_active_value!(String);
|
||||
|
||||
#[cfg(feature = "with-json")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "with-json")))]
|
||||
impl_into_active_value!(crate::prelude::Json, Set);
|
||||
impl_into_active_value!(crate::prelude::Json);
|
||||
|
||||
#[cfg(feature = "with-chrono")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
|
||||
impl_into_active_value!(crate::prelude::Date, Set);
|
||||
impl_into_active_value!(crate::prelude::Date);
|
||||
|
||||
#[cfg(feature = "with-chrono")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
|
||||
impl_into_active_value!(crate::prelude::Time, Set);
|
||||
impl_into_active_value!(crate::prelude::Time);
|
||||
|
||||
#[cfg(feature = "with-chrono")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
|
||||
impl_into_active_value!(crate::prelude::DateTime, Set);
|
||||
impl_into_active_value!(crate::prelude::DateTime);
|
||||
|
||||
#[cfg(feature = "with-chrono")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
|
||||
impl_into_active_value!(crate::prelude::DateTimeWithTimeZone, Set);
|
||||
impl_into_active_value!(crate::prelude::DateTimeWithTimeZone);
|
||||
|
||||
#[cfg(feature = "with-chrono")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
|
||||
impl_into_active_value!(crate::prelude::DateTimeUtc, Set);
|
||||
impl_into_active_value!(crate::prelude::DateTimeUtc);
|
||||
|
||||
#[cfg(feature = "with-chrono")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "with-chrono")))]
|
||||
impl_into_active_value!(crate::prelude::DateTimeLocal, Set);
|
||||
impl_into_active_value!(crate::prelude::DateTimeLocal);
|
||||
|
||||
#[cfg(feature = "with-rust_decimal")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "with-rust_decimal")))]
|
||||
impl_into_active_value!(crate::prelude::Decimal, Set);
|
||||
impl_into_active_value!(crate::prelude::Decimal);
|
||||
|
||||
#[cfg(feature = "with-uuid")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "with-uuid")))]
|
||||
impl_into_active_value!(crate::prelude::Uuid, Set);
|
||||
impl_into_active_value!(crate::prelude::Uuid);
|
||||
|
||||
impl<V> Default for ActiveValue<V>
|
||||
where
|
||||
|
@ -61,14 +61,14 @@ impl Deleter {
|
||||
}
|
||||
}
|
||||
|
||||
async fn exec_delete_only<'a, C>(query: DeleteStatement, db: &'a C) -> Result<DeleteResult, DbErr>
|
||||
async fn exec_delete_only<C>(query: DeleteStatement, db: &C) -> Result<DeleteResult, DbErr>
|
||||
where
|
||||
C: ConnectionTrait,
|
||||
{
|
||||
Deleter::new(query).exec(db).await
|
||||
}
|
||||
|
||||
async fn exec_delete<'a, C>(statement: Statement, db: &'a C) -> Result<DeleteResult, DbErr>
|
||||
async fn exec_delete<C>(statement: Statement, db: &C) -> Result<DeleteResult, DbErr>
|
||||
where
|
||||
C: ConnectionTrait,
|
||||
{
|
||||
|
@ -7,6 +7,7 @@ pub struct ExecResult {
|
||||
}
|
||||
|
||||
/// Holds a result depending on the database backend chosen by the feature flag
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum ExecResultHolder {
|
||||
/// Holds the result of executing an operation on a MySQL database
|
||||
|
@ -102,10 +102,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
async fn exec_insert<'a, A, C>(
|
||||
async fn exec_insert<A, C>(
|
||||
primary_key: Option<ValueTuple>,
|
||||
statement: Statement,
|
||||
db: &'a C,
|
||||
db: &C,
|
||||
) -> Result<InsertResult<A>, DbErr>
|
||||
where
|
||||
C: ConnectionTrait,
|
||||
@ -136,10 +136,10 @@ where
|
||||
Ok(InsertResult { last_insert_id })
|
||||
}
|
||||
|
||||
async fn exec_insert_with_returning<'a, A, C>(
|
||||
async fn exec_insert_with_returning<A, C>(
|
||||
primary_key: Option<ValueTuple>,
|
||||
mut insert_statement: InsertStatement,
|
||||
db: &'a C,
|
||||
db: &C,
|
||||
) -> Result<<A::Entity as EntityTrait>::Model, DbErr>
|
||||
where
|
||||
<A::Entity as EntityTrait>::Model: IntoActiveModel<A>,
|
||||
|
@ -9,6 +9,7 @@ pub struct QueryResult {
|
||||
pub(crate) row: QueryResultRow,
|
||||
}
|
||||
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
pub(crate) enum QueryResultRow {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
SqlxMySql(sqlx::mysql::MySqlRow),
|
||||
|
@ -419,7 +419,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn into_selector_raw<'a, C>(self, db: &C) -> SelectorRaw<S>
|
||||
fn into_selector_raw<C>(self, db: &C) -> SelectorRaw<S>
|
||||
where
|
||||
C: ConnectionTrait,
|
||||
{
|
||||
|
@ -73,17 +73,17 @@ impl Updater {
|
||||
}
|
||||
}
|
||||
|
||||
async fn exec_update_only<'a, C>(query: UpdateStatement, db: &'a C) -> Result<UpdateResult, DbErr>
|
||||
async fn exec_update_only<C>(query: UpdateStatement, db: &C) -> Result<UpdateResult, DbErr>
|
||||
where
|
||||
C: ConnectionTrait,
|
||||
{
|
||||
Updater::new(query).exec(db).await
|
||||
}
|
||||
|
||||
async fn exec_update_and_return_updated<'a, A, C>(
|
||||
async fn exec_update_and_return_updated<A, C>(
|
||||
mut query: UpdateStatement,
|
||||
model: A,
|
||||
db: &'a C,
|
||||
db: &C,
|
||||
) -> Result<<A::Entity as EntityTrait>::Model, DbErr>
|
||||
where
|
||||
A: ActiveModelTrait,
|
||||
@ -136,9 +136,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
async fn exec_update<'a, C>(
|
||||
async fn exec_update<C>(
|
||||
statement: Statement,
|
||||
db: &'a C,
|
||||
db: &C,
|
||||
check_record_exists: bool,
|
||||
) -> Result<UpdateResult, DbErr>
|
||||
where
|
||||
|
@ -166,6 +166,7 @@ impl FromQueryResult for JsonValue {
|
||||
}
|
||||
Ok(JsonValue::Object(map))
|
||||
}
|
||||
#[allow(unreachable_patterns)]
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ pub async fn left_join() {
|
||||
"home": "0395555555",
|
||||
"address": "12 Test St, Testville, Vic, Australia"
|
||||
})),
|
||||
bakery_id: Set(Some(bakery.id.clone())),
|
||||
bakery_id: Set(Some(bakery.id)),
|
||||
..Default::default()
|
||||
}
|
||||
.insert(&ctx.db)
|
||||
@ -124,8 +124,8 @@ pub async fn right_join() {
|
||||
.expect("could not insert customer");
|
||||
|
||||
let _order = order::ActiveModel {
|
||||
bakery_id: Set(bakery.id.clone()),
|
||||
customer_id: Set(customer_kate.id.clone()),
|
||||
bakery_id: Set(bakery.id),
|
||||
customer_id: Set(customer_kate.id),
|
||||
total: Set(dec!(15.10)),
|
||||
placed_at: Set(Utc::now().naive_utc()),
|
||||
|
||||
@ -135,7 +135,8 @@ pub async fn right_join() {
|
||||
.await
|
||||
.expect("could not insert order");
|
||||
|
||||
#[derive(Debug, FromQueryResult)]
|
||||
#[derive(FromQueryResult)]
|
||||
#[allow(dead_code)]
|
||||
struct SelectResult {
|
||||
name: String,
|
||||
order_total: Option<Decimal>,
|
||||
@ -210,8 +211,8 @@ pub async fn inner_join() {
|
||||
.expect("could not insert customer");
|
||||
|
||||
let kate_order_1 = order::ActiveModel {
|
||||
bakery_id: Set(bakery.id.clone()),
|
||||
customer_id: Set(customer_kate.id.clone()),
|
||||
bakery_id: Set(bakery.id),
|
||||
customer_id: Set(customer_kate.id),
|
||||
total: Set(dec!(15.10)),
|
||||
placed_at: Set(Utc::now().naive_utc()),
|
||||
|
||||
@ -222,8 +223,8 @@ pub async fn inner_join() {
|
||||
.expect("could not insert order");
|
||||
|
||||
let kate_order_2 = order::ActiveModel {
|
||||
bakery_id: Set(bakery.id.clone()),
|
||||
customer_id: Set(customer_kate.id.clone()),
|
||||
bakery_id: Set(bakery.id),
|
||||
customer_id: Set(customer_kate.id),
|
||||
total: Set(dec!(100.00)),
|
||||
placed_at: Set(Utc::now().naive_utc()),
|
||||
|
||||
@ -253,13 +254,13 @@ pub async fn inner_join() {
|
||||
|
||||
assert_eq!(results.len(), 2);
|
||||
assert!((&results)
|
||||
.into_iter()
|
||||
.iter()
|
||||
.any(|result| result.name == customer_kate.name.clone()
|
||||
&& result.order_total == Some(kate_order_1.total.clone())));
|
||||
&& result.order_total == Some(kate_order_1.total)));
|
||||
assert!((&results)
|
||||
.into_iter()
|
||||
.iter()
|
||||
.any(|result| result.name == customer_kate.name.clone()
|
||||
&& result.order_total == Some(kate_order_2.total.clone())));
|
||||
&& result.order_total == Some(kate_order_2.total)));
|
||||
|
||||
ctx.delete().await;
|
||||
}
|
||||
@ -292,8 +293,8 @@ pub async fn group_by() {
|
||||
.expect("could not insert customer");
|
||||
|
||||
let kate_order_1 = order::ActiveModel {
|
||||
bakery_id: Set(bakery.id.clone()),
|
||||
customer_id: Set(customer_kate.id.clone()),
|
||||
bakery_id: Set(bakery.id),
|
||||
customer_id: Set(customer_kate.id),
|
||||
total: Set(dec!(99.95)),
|
||||
placed_at: Set(Utc::now().naive_utc()),
|
||||
|
||||
@ -304,8 +305,8 @@ pub async fn group_by() {
|
||||
.expect("could not insert order");
|
||||
|
||||
let kate_order_2 = order::ActiveModel {
|
||||
bakery_id: Set(bakery.id.clone()),
|
||||
customer_id: Set(customer_kate.id.clone()),
|
||||
bakery_id: Set(bakery.id),
|
||||
customer_id: Set(customer_kate.id),
|
||||
total: Set(dec!(200.00)),
|
||||
placed_at: Set(Utc::now().naive_utc()),
|
||||
|
||||
@ -345,15 +346,15 @@ pub async fn group_by() {
|
||||
assert_eq!(result.number_orders, Some(2));
|
||||
assert_eq!(
|
||||
result.total_spent,
|
||||
Some(kate_order_1.total.clone() + kate_order_2.total.clone())
|
||||
Some(kate_order_1.total + kate_order_2.total)
|
||||
);
|
||||
assert_eq!(
|
||||
result.min_spent,
|
||||
Some(kate_order_1.total.clone().min(kate_order_2.total.clone()))
|
||||
Some(kate_order_1.total.min(kate_order_2.total))
|
||||
);
|
||||
assert_eq!(
|
||||
result.max_spent,
|
||||
Some(kate_order_1.total.clone().max(kate_order_2.total.clone()))
|
||||
Some(kate_order_1.total.max(kate_order_2.total))
|
||||
);
|
||||
ctx.delete().await;
|
||||
}
|
||||
@ -387,8 +388,8 @@ pub async fn having() {
|
||||
.expect("could not insert customer");
|
||||
|
||||
let kate_order_1 = order::ActiveModel {
|
||||
bakery_id: Set(bakery.id.clone()),
|
||||
customer_id: Set(customer_kate.id.clone()),
|
||||
bakery_id: Set(bakery.id),
|
||||
customer_id: Set(customer_kate.id),
|
||||
total: Set(dec!(100.00)),
|
||||
placed_at: Set(Utc::now().naive_utc()),
|
||||
|
||||
@ -399,8 +400,8 @@ pub async fn having() {
|
||||
.expect("could not insert order");
|
||||
|
||||
let _kate_order_2 = order::ActiveModel {
|
||||
bakery_id: Set(bakery.id.clone()),
|
||||
customer_id: Set(customer_kate.id.clone()),
|
||||
bakery_id: Set(bakery.id),
|
||||
customer_id: Set(customer_kate.id),
|
||||
total: Set(dec!(12.00)),
|
||||
placed_at: Set(Utc::now().naive_utc()),
|
||||
|
||||
@ -419,8 +420,8 @@ pub async fn having() {
|
||||
.expect("could not insert customer");
|
||||
|
||||
let _bob_order_1 = order::ActiveModel {
|
||||
bakery_id: Set(bakery.id.clone()),
|
||||
customer_id: Set(customer_bob.id.clone()),
|
||||
bakery_id: Set(bakery.id),
|
||||
customer_id: Set(customer_bob.id),
|
||||
total: Set(dec!(50.0)),
|
||||
placed_at: Set(Utc::now().naive_utc()),
|
||||
|
||||
@ -431,8 +432,8 @@ pub async fn having() {
|
||||
.expect("could not insert order");
|
||||
|
||||
let _bob_order_2 = order::ActiveModel {
|
||||
bakery_id: Set(bakery.id.clone()),
|
||||
customer_id: Set(customer_bob.id.clone()),
|
||||
bakery_id: Set(bakery.id),
|
||||
customer_id: Set(customer_bob.id),
|
||||
total: Set(dec!(50.0)),
|
||||
placed_at: Set(Utc::now().naive_utc()),
|
||||
|
||||
@ -463,7 +464,7 @@ pub async fn having() {
|
||||
|
||||
assert_eq!(results.len(), 1);
|
||||
assert_eq!(results[0].name, customer_kate.name.clone());
|
||||
assert_eq!(results[0].order_total, Some(kate_order_1.total.clone()));
|
||||
assert_eq!(results[0].order_total, Some(kate_order_1.total));
|
||||
|
||||
ctx.delete().await;
|
||||
}
|
||||
@ -514,7 +515,6 @@ pub async fn linked() -> Result<(), DbErr> {
|
||||
let bob_cakes_bakers = cakes_bakers::ActiveModel {
|
||||
cake_id: Set(mud_cake_res.last_insert_id as i32),
|
||||
baker_id: Set(baker_bob_res.last_insert_id as i32),
|
||||
..Default::default()
|
||||
};
|
||||
CakesBakers::insert(bob_cakes_bakers).exec(&ctx.db).await?;
|
||||
|
||||
@ -540,7 +540,6 @@ pub async fn linked() -> Result<(), DbErr> {
|
||||
let bobby_cakes_bakers = cakes_bakers::ActiveModel {
|
||||
cake_id: Set(cheese_cake_res.last_insert_id as i32),
|
||||
baker_id: Set(baker_bobby_res.last_insert_id as i32),
|
||||
..Default::default()
|
||||
};
|
||||
CakesBakers::insert(bobby_cakes_bakers)
|
||||
.exec(&ctx.db)
|
||||
@ -557,7 +556,6 @@ pub async fn linked() -> Result<(), DbErr> {
|
||||
let bobby_cakes_bakers = cakes_bakers::ActiveModel {
|
||||
cake_id: Set(chocolate_cake_res.last_insert_id as i32),
|
||||
baker_id: Set(baker_bobby_res.last_insert_id as i32),
|
||||
..Default::default()
|
||||
};
|
||||
CakesBakers::insert(bobby_cakes_bakers)
|
||||
.exec(&ctx.db)
|
||||
|
@ -76,7 +76,6 @@ async fn seed_data(db: &DatabaseConnection) {
|
||||
let cake_baker = cakes_bakers::ActiveModel {
|
||||
cake_id: Set(cake_insert_res.last_insert_id as i32),
|
||||
baker_id: Set(baker_1.id.clone().unwrap()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let cake_baker_res = CakesBakers::insert(cake_baker.clone())
|
||||
@ -181,7 +180,7 @@ async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model>
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|b| LeastSalesBakerResult {
|
||||
id: b.id.clone(),
|
||||
id: b.id,
|
||||
cakes_sold: b.cakes_sold_opt.unwrap_or_default().into(),
|
||||
})
|
||||
.collect();
|
||||
@ -201,7 +200,7 @@ async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option<cak
|
||||
price: Set(dec!(8.00)),
|
||||
gluten_free: Set(false),
|
||||
serial: Set(Uuid::new_v4()),
|
||||
bakery_id: Set(Some(baker.bakery_id.clone().unwrap())),
|
||||
bakery_id: Set(Some(baker.bakery_id.unwrap())),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@ -213,7 +212,6 @@ async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option<cak
|
||||
let cake_baker = cakes_bakers::ActiveModel {
|
||||
cake_id: Set(cake_insert_res.last_insert_id as i32),
|
||||
baker_id: Set(baker.id),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let cake_baker_res = CakesBakers::insert(cake_baker.clone())
|
||||
|
@ -331,14 +331,14 @@ pub async fn transaction_closure_rollback() -> Result<(), DbErr> {
|
||||
id: Set(1),
|
||||
name: Set("Duplicated primary key".to_owned()),
|
||||
profit_margin: Set(20.0),
|
||||
..Default::default()
|
||||
}
|
||||
.insert(txn)
|
||||
.await?; // Throw error and rollback
|
||||
|
||||
// This line won't be reached
|
||||
assert!(false);
|
||||
unreachable!();
|
||||
|
||||
#[allow(unreachable_code)]
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user