cargo fmt
This commit is contained in:
parent
883bd1605d
commit
6ff5a32b7a
@ -116,9 +116,7 @@ impl EntityWriter {
|
|||||||
Self::gen_impl_relation_trait(entity),
|
Self::gen_impl_relation_trait(entity),
|
||||||
];
|
];
|
||||||
code_blocks.extend(Self::gen_impl_related(entity));
|
code_blocks.extend(Self::gen_impl_related(entity));
|
||||||
code_blocks.extend(vec![
|
code_blocks.extend(vec![Self::gen_impl_active_model_behavior()]);
|
||||||
Self::gen_impl_active_model_behavior(),
|
|
||||||
]);
|
|
||||||
code_blocks
|
code_blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,11 +79,7 @@ impl MockDatabaseTrait for MockDatabase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query(
|
fn query(&mut self, counter: usize, statement: Statement) -> Result<Vec<QueryResult>, DbErr> {
|
||||||
&mut self,
|
|
||||||
counter: usize,
|
|
||||||
statement: Statement,
|
|
||||||
) -> Result<Vec<QueryResult>, DbErr> {
|
|
||||||
self.transaction_log.push(Transaction::one(statement));
|
self.transaction_log.push(Transaction::one(statement));
|
||||||
if counter < self.query_results.len() {
|
if counter < self.query_results.len() {
|
||||||
Ok(std::mem::take(&mut self.query_results[counter])
|
Ok(std::mem::take(&mut self.query_results[counter])
|
||||||
|
@ -29,6 +29,9 @@ impl Database {
|
|||||||
if crate::MockDatabaseConnector::accepts(string) {
|
if crate::MockDatabaseConnector::accepts(string) {
|
||||||
return crate::MockDatabaseConnector::connect(string).await;
|
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)),
|
Err(err) => Err(sqlx_error_to_exec_err(err)),
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
} 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)),
|
Err(err) => Err(sqlx_error_to_query_err(err)),
|
||||||
}
|
}
|
||||||
} else {
|
} 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)),
|
Err(err) => Err(sqlx_error_to_exec_err(err)),
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
} 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)),
|
Err(err) => Err(sqlx_error_to_query_err(err)),
|
||||||
}
|
}
|
||||||
} else {
|
} 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?;
|
let model: Option<E::Model> = found?;
|
||||||
match model {
|
match model {
|
||||||
Some(model) => Ok(model.into_active_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 {
|
} else {
|
||||||
Ok(A::default())
|
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;
|
pub use sea_query::Value;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
@ -62,10 +62,7 @@ async fn exec_delete_only(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only Statement impl Send
|
// Only Statement impl Send
|
||||||
async fn exec_delete(
|
async fn exec_delete(statement: Statement, db: &DatabaseConnection) -> Result<DeleteResult, DbErr> {
|
||||||
statement: Statement,
|
|
||||||
db: &DatabaseConnection,
|
|
||||||
) -> Result<DeleteResult, DbErr> {
|
|
||||||
let result = db.execute(statement).await?;
|
let result = db.execute(statement).await?;
|
||||||
Ok(DeleteResult {
|
Ok(DeleteResult {
|
||||||
rows_affected: result.rows_affected(),
|
rows_affected: result.rows_affected(),
|
||||||
|
@ -40,10 +40,7 @@ impl Inserter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only Statement impl Send
|
// Only Statement impl Send
|
||||||
async fn exec_insert(
|
async fn exec_insert(statement: Statement, db: &DatabaseConnection) -> Result<InsertResult, DbErr> {
|
||||||
statement: Statement,
|
|
||||||
db: &DatabaseConnection,
|
|
||||||
) -> Result<InsertResult, DbErr> {
|
|
||||||
let result = db.execute(statement).await?;
|
let result = db.execute(statement).await?;
|
||||||
// TODO: Postgres instead use query_one + returning clause
|
// TODO: Postgres instead use query_one + returning clause
|
||||||
Ok(InsertResult {
|
Ok(InsertResult {
|
||||||
|
@ -56,12 +56,14 @@ macro_rules! try_getable_all {
|
|||||||
#[cfg(feature = "sqlx-mysql")]
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
QueryResultRow::SqlxMySql(row) => {
|
QueryResultRow::SqlxMySql(row) => {
|
||||||
use sqlx::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")]
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
QueryResultRow::SqlxSqlite(row) => {
|
QueryResultRow::SqlxSqlite(row) => {
|
||||||
use sqlx::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")]
|
#[cfg(feature = "mock")]
|
||||||
QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?),
|
QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?),
|
||||||
@ -109,7 +111,8 @@ macro_rules! try_getable_mysql {
|
|||||||
#[cfg(feature = "sqlx-mysql")]
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
QueryResultRow::SqlxMySql(row) => {
|
QueryResultRow::SqlxMySql(row) => {
|
||||||
use sqlx::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")]
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
QueryResultRow::SqlxSqlite(_) => {
|
QueryResultRow::SqlxSqlite(_) => {
|
||||||
@ -172,14 +175,18 @@ impl TryGetable for Decimal {
|
|||||||
#[cfg(feature = "sqlx-mysql")]
|
#[cfg(feature = "sqlx-mysql")]
|
||||||
QueryResultRow::SqlxMySql(row) => {
|
QueryResultRow::SqlxMySql(row) => {
|
||||||
use sqlx::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")]
|
#[cfg(feature = "sqlx-sqlite")]
|
||||||
QueryResultRow::SqlxSqlite(row) => {
|
QueryResultRow::SqlxSqlite(row) => {
|
||||||
use sqlx::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;
|
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")]
|
#[cfg(feature = "mock")]
|
||||||
QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?),
|
QueryResultRow::Mock(row) => Ok(row.try_get(column.as_str())?),
|
||||||
|
@ -18,10 +18,7 @@ impl<'a, A: 'a> UpdateOne<A>
|
|||||||
where
|
where
|
||||||
A: ActiveModelTrait,
|
A: ActiveModelTrait,
|
||||||
{
|
{
|
||||||
pub fn exec(
|
pub fn exec(self, db: &'a DatabaseConnection) -> impl Future<Output = Result<A, DbErr>> + 'a {
|
||||||
self,
|
|
||||||
db: &'a DatabaseConnection,
|
|
||||||
) -> impl Future<Output = Result<A, DbErr>> + 'a {
|
|
||||||
// so that self is dropped before entering await
|
// so that self is dropped before entering await
|
||||||
exec_update_and_return_original(self.query, self.model, db)
|
exec_update_and_return_original(self.query, self.model, db)
|
||||||
}
|
}
|
||||||
@ -74,10 +71,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only Statement impl Send
|
// Only Statement impl Send
|
||||||
async fn exec_update(
|
async fn exec_update(statement: Statement, db: &DatabaseConnection) -> Result<UpdateResult, DbErr> {
|
||||||
statement: Statement,
|
|
||||||
db: &DatabaseConnection,
|
|
||||||
) -> Result<UpdateResult, DbErr> {
|
|
||||||
let result = db.execute(statement).await?;
|
let result = db.execute(statement).await?;
|
||||||
Ok(UpdateResult {
|
Ok(UpdateResult {
|
||||||
rows_affected: result.rows_affected(),
|
rows_affected: result.rows_affected(),
|
||||||
|
@ -215,5 +215,5 @@ pub use sea_orm_macros::{
|
|||||||
};
|
};
|
||||||
pub use sea_query;
|
pub use sea_query;
|
||||||
pub use sea_query::Iden;
|
pub use sea_query::Iden;
|
||||||
pub use strum::EnumIter;
|
|
||||||
pub use strum;
|
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;
|
use serde_json::Map;
|
||||||
pub use serde_json::Value as JsonValue;
|
pub use serde_json::Value as JsonValue;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user