cargo fmt
This commit is contained in:
parent
883bd1605d
commit
6ff5a32b7a
@ -116,9 +116,7 @@ impl EntityWriter {
|
||||
Self::gen_impl_relation_trait(entity),
|
||||
];
|
||||
code_blocks.extend(Self::gen_impl_related(entity));
|
||||
code_blocks.extend(vec![
|
||||
Self::gen_impl_active_model_behavior(),
|
||||
]);
|
||||
code_blocks.extend(vec![Self::gen_impl_active_model_behavior()]);
|
||||
code_blocks
|
||||
}
|
||||
|
||||
|
@ -79,11 +79,7 @@ impl MockDatabaseTrait for MockDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
fn query(
|
||||
&mut self,
|
||||
counter: usize,
|
||||
statement: Statement,
|
||||
) -> Result<Vec<QueryResult>, DbErr> {
|
||||
fn query(&mut self, counter: usize, statement: Statement) -> Result<Vec<QueryResult>, DbErr> {
|
||||
self.transaction_log.push(Transaction::one(statement));
|
||||
if counter < self.query_results.len() {
|
||||
Ok(std::mem::take(&mut self.query_results[counter])
|
||||
|
@ -29,6 +29,9 @@ impl Database {
|
||||
if crate::MockDatabaseConnector::accepts(string) {
|
||||
return crate::MockDatabaseConnector::connect(string).await;
|
||||
}
|
||||
Err(DbErr::Conn(format!("The connection string '{}' has no supporting driver.", string)))
|
||||
Err(DbErr::Conn(format!(
|
||||
"The connection string '{}' has no supporting driver.",
|
||||
string
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,9 @@ impl SqlxMySqlPoolConnection {
|
||||
Err(err) => Err(sqlx_error_to_exec_err(err)),
|
||||
}
|
||||
} else {
|
||||
Err(DbErr::Exec("Failed to acquire connection from pool.".to_owned()))
|
||||
Err(DbErr::Exec(
|
||||
"Failed to acquire connection from pool.".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +68,9 @@ impl SqlxMySqlPoolConnection {
|
||||
},
|
||||
}
|
||||
} else {
|
||||
Err(DbErr::Query("Failed to acquire connection from pool.".to_owned()))
|
||||
Err(DbErr::Query(
|
||||
"Failed to acquire connection from pool.".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +84,9 @@ impl SqlxMySqlPoolConnection {
|
||||
Err(err) => Err(sqlx_error_to_query_err(err)),
|
||||
}
|
||||
} else {
|
||||
Err(DbErr::Query("Failed to acquire connection from pool.".to_owned()))
|
||||
Err(DbErr::Query(
|
||||
"Failed to acquire connection from pool.".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,9 @@ impl SqlxSqlitePoolConnection {
|
||||
Err(err) => Err(sqlx_error_to_exec_err(err)),
|
||||
}
|
||||
} else {
|
||||
Err(DbErr::Exec("Failed to acquire connection from pool.".to_owned()))
|
||||
Err(DbErr::Exec(
|
||||
"Failed to acquire connection from pool.".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +68,9 @@ impl SqlxSqlitePoolConnection {
|
||||
},
|
||||
}
|
||||
} else {
|
||||
Err(DbErr::Query("Failed to acquire connection from pool.".to_owned()))
|
||||
Err(DbErr::Query(
|
||||
"Failed to acquire connection from pool.".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +84,9 @@ impl SqlxSqlitePoolConnection {
|
||||
Err(err) => Err(sqlx_error_to_query_err(err)),
|
||||
}
|
||||
} else {
|
||||
Err(DbErr::Query("Failed to acquire connection from pool.".to_owned()))
|
||||
Err(DbErr::Query(
|
||||
"Failed to acquire connection from pool.".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +227,11 @@ where
|
||||
let model: Option<E::Model> = found?;
|
||||
match model {
|
||||
Some(model) => Ok(model.into_active_model()),
|
||||
None => Err(DbErr::Exec(format!("Failed to find inserted item: {} {}", E::default().to_string(), res.last_insert_id))),
|
||||
None => Err(DbErr::Exec(format!(
|
||||
"Failed to find inserted item: {} {}",
|
||||
E::default().to_string(),
|
||||
res.last_insert_id
|
||||
))),
|
||||
}
|
||||
} else {
|
||||
Ok(A::default())
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{EntityTrait, DbErr, QueryFilter, QueryResult, Related, Select};
|
||||
use crate::{DbErr, EntityTrait, QueryFilter, QueryResult, Related, Select};
|
||||
pub use sea_query::Value;
|
||||
use std::fmt::Debug;
|
||||
|
||||
|
@ -62,10 +62,7 @@ async fn exec_delete_only(
|
||||
}
|
||||
|
||||
// Only Statement impl Send
|
||||
async fn exec_delete(
|
||||
statement: Statement,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<DeleteResult, DbErr> {
|
||||
async fn exec_delete(statement: Statement, db: &DatabaseConnection) -> Result<DeleteResult, DbErr> {
|
||||
let result = db.execute(statement).await?;
|
||||
Ok(DeleteResult {
|
||||
rows_affected: result.rows_affected(),
|
||||
|
@ -40,10 +40,7 @@ impl Inserter {
|
||||
}
|
||||
|
||||
// Only Statement impl Send
|
||||
async fn exec_insert(
|
||||
statement: Statement,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<InsertResult, DbErr> {
|
||||
async fn exec_insert(statement: Statement, db: &DatabaseConnection) -> Result<InsertResult, DbErr> {
|
||||
let result = db.execute(statement).await?;
|
||||
// TODO: Postgres instead use query_one + returning clause
|
||||
Ok(InsertResult {
|
||||
|
@ -56,12 +56,14 @@ macro_rules! try_getable_all {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
QueryResultRow::SqlxMySql(row) => {
|
||||
use sqlx::Row;
|
||||
row.try_get(column.as_str()).map_err(crate::sqlx_error_to_query_err)
|
||||
row.try_get(column.as_str())
|
||||
.map_err(crate::sqlx_error_to_query_err)
|
||||
}
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
QueryResultRow::SqlxSqlite(row) => {
|
||||
use sqlx::Row;
|
||||
row.try_get(column.as_str()).map_err(crate::sqlx_error_to_query_err)
|
||||
row.try_get(column.as_str())
|
||||
.map_err(crate::sqlx_error_to_query_err)
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?),
|
||||
@ -109,7 +111,8 @@ macro_rules! try_getable_mysql {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
QueryResultRow::SqlxMySql(row) => {
|
||||
use sqlx::Row;
|
||||
row.try_get(column.as_str()).map_err(crate::sqlx_error_to_query_err)
|
||||
row.try_get(column.as_str())
|
||||
.map_err(crate::sqlx_error_to_query_err)
|
||||
}
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
QueryResultRow::SqlxSqlite(_) => {
|
||||
@ -172,14 +175,18 @@ impl TryGetable for Decimal {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
QueryResultRow::SqlxMySql(row) => {
|
||||
use sqlx::Row;
|
||||
row.try_get(column.as_str()).map_err(crate::sqlx_error_to_query_err)
|
||||
row.try_get(column.as_str())
|
||||
.map_err(crate::sqlx_error_to_query_err)
|
||||
}
|
||||
#[cfg(feature = "sqlx-sqlite")]
|
||||
QueryResultRow::SqlxSqlite(row) => {
|
||||
use sqlx::Row;
|
||||
let val: f64 = row.try_get(column.as_str()).map_err(crate::sqlx_error_to_query_err)?;
|
||||
let val: f64 = row
|
||||
.try_get(column.as_str())
|
||||
.map_err(crate::sqlx_error_to_query_err)?;
|
||||
use rust_decimal::prelude::FromPrimitive;
|
||||
Decimal::from_f64(val).ok_or_else(|| DbErr::Query("Failed to convert f64 into Decimal".to_owned()))
|
||||
Decimal::from_f64(val)
|
||||
.ok_or_else(|| DbErr::Query("Failed to convert f64 into Decimal".to_owned()))
|
||||
}
|
||||
#[cfg(feature = "mock")]
|
||||
QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?),
|
||||
|
@ -18,10 +18,7 @@ impl<'a, A: 'a> UpdateOne<A>
|
||||
where
|
||||
A: ActiveModelTrait,
|
||||
{
|
||||
pub fn exec(
|
||||
self,
|
||||
db: &'a DatabaseConnection,
|
||||
) -> impl Future<Output = Result<A, DbErr>> + 'a {
|
||||
pub fn exec(self, db: &'a DatabaseConnection) -> impl Future<Output = Result<A, DbErr>> + 'a {
|
||||
// so that self is dropped before entering await
|
||||
exec_update_and_return_original(self.query, self.model, db)
|
||||
}
|
||||
@ -74,10 +71,7 @@ where
|
||||
}
|
||||
|
||||
// Only Statement impl Send
|
||||
async fn exec_update(
|
||||
statement: Statement,
|
||||
db: &DatabaseConnection,
|
||||
) -> Result<UpdateResult, DbErr> {
|
||||
async fn exec_update(statement: Statement, db: &DatabaseConnection) -> Result<UpdateResult, DbErr> {
|
||||
let result = db.execute(statement).await?;
|
||||
Ok(UpdateResult {
|
||||
rows_affected: result.rows_affected(),
|
||||
|
@ -215,5 +215,5 @@ pub use sea_orm_macros::{
|
||||
};
|
||||
pub use sea_query;
|
||||
pub use sea_query::Iden;
|
||||
pub use strum::EnumIter;
|
||||
pub use strum;
|
||||
pub use strum::EnumIter;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{FromQueryResult, DbErr, QueryResult, QueryResultRow};
|
||||
use crate::{DbErr, FromQueryResult, QueryResult, QueryResultRow};
|
||||
use serde_json::Map;
|
||||
pub use serde_json::Value as JsonValue;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user