Remove Debug trait bounds
This commit is contained in:
parent
0abe9c9657
commit
dcfba6f685
@ -4,7 +4,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use sea_query::{Expr, IntoColumnRef, SimpleExpr, ValueTuple};
|
use sea_query::{Expr, IntoColumnRef, SimpleExpr, ValueTuple};
|
||||||
use std::{collections::BTreeMap, fmt::Debug, str::FromStr};
|
use std::{collections::HashMap, str::FromStr};
|
||||||
|
|
||||||
/// A trait for basic Dataloader
|
/// A trait for basic Dataloader
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@ -20,9 +20,7 @@ pub trait LoaderTrait {
|
|||||||
C: ConnectionTrait,
|
C: ConnectionTrait,
|
||||||
R: EntityTrait,
|
R: EntityTrait,
|
||||||
R::Model: Send + Sync,
|
R::Model: Send + Sync,
|
||||||
<<R as EntityTrait>::Column as FromStr>::Err: Debug,
|
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>;
|
||||||
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>,
|
|
||||||
<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::Err: Debug;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Used to eager load has_many relations
|
/// Used to eager load has_many relations
|
||||||
@ -32,9 +30,7 @@ pub trait LoaderTrait {
|
|||||||
C: ConnectionTrait,
|
C: ConnectionTrait,
|
||||||
R: EntityTrait,
|
R: EntityTrait,
|
||||||
R::Model: Send + Sync,
|
R::Model: Send + Sync,
|
||||||
<<R as EntityTrait>::Column as FromStr>::Err: Debug,
|
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>;
|
||||||
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>,
|
|
||||||
<<<<Self as LoaderTrait>::Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::Err: Debug;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
@ -50,9 +46,7 @@ where
|
|||||||
C: ConnectionTrait,
|
C: ConnectionTrait,
|
||||||
R: EntityTrait,
|
R: EntityTrait,
|
||||||
R::Model: Send + Sync,
|
R::Model: Send + Sync,
|
||||||
<<R as EntityTrait>::Column as FromStr>::Err: Debug,
|
|
||||||
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>,
|
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>,
|
||||||
<<<M as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::Err: Debug,
|
|
||||||
{
|
{
|
||||||
let rel_def = <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as Related<R>>::to();
|
let rel_def = <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as Related<R>>::to();
|
||||||
|
|
||||||
@ -75,9 +69,9 @@ where
|
|||||||
|
|
||||||
let data = stmt.all(db).await?;
|
let data = stmt.all(db).await?;
|
||||||
|
|
||||||
let mut hashmap: BTreeMap<String, <R as EntityTrait>::Model> = data.into_iter().fold(
|
let mut hashmap: HashMap<String, <R as EntityTrait>::Model> = data.into_iter().fold(
|
||||||
BTreeMap::<String, <R as EntityTrait>::Model>::new(),
|
HashMap::<String, <R as EntityTrait>::Model>::new(),
|
||||||
|mut acc: BTreeMap<String, <R as EntityTrait>::Model>,
|
|mut acc: HashMap<String, <R as EntityTrait>::Model>,
|
||||||
value: <R as EntityTrait>::Model| {
|
value: <R as EntityTrait>::Model| {
|
||||||
{
|
{
|
||||||
let key = extract_key(&rel_def.to_col, &value);
|
let key = extract_key(&rel_def.to_col, &value);
|
||||||
@ -102,9 +96,7 @@ where
|
|||||||
C: ConnectionTrait,
|
C: ConnectionTrait,
|
||||||
R: EntityTrait,
|
R: EntityTrait,
|
||||||
R::Model: Send + Sync,
|
R::Model: Send + Sync,
|
||||||
<<R as EntityTrait>::Column as FromStr>::Err: Debug,
|
|
||||||
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>,
|
<<Self as LoaderTrait>::Model as ModelTrait>::Entity: Related<R>,
|
||||||
<<<M as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::Err: Debug,
|
|
||||||
{
|
{
|
||||||
let rel_def = <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as Related<R>>::to();
|
let rel_def = <<<Self as LoaderTrait>::Model as ModelTrait>::Entity as Related<R>>::to();
|
||||||
|
|
||||||
@ -127,9 +119,9 @@ where
|
|||||||
|
|
||||||
let data = stmt.all(db).await?;
|
let data = stmt.all(db).await?;
|
||||||
|
|
||||||
let mut hashmap: BTreeMap<String, Vec<<R as EntityTrait>::Model>> =
|
let mut hashmap: HashMap<String, Vec<<R as EntityTrait>::Model>> =
|
||||||
keys.iter()
|
keys.iter()
|
||||||
.fold(BTreeMap::new(), |mut acc, key: &ValueTuple| {
|
.fold(HashMap::new(), |mut acc, key: &ValueTuple| {
|
||||||
acc.insert(format!("{:?}", key), Vec::new());
|
acc.insert(format!("{:?}", key), Vec::new());
|
||||||
|
|
||||||
acc
|
acc
|
||||||
@ -162,7 +154,6 @@ where
|
|||||||
fn extract_key<Model>(target_col: &Identity, model: &Model) -> ValueTuple
|
fn extract_key<Model>(target_col: &Identity, model: &Model) -> ValueTuple
|
||||||
where
|
where
|
||||||
Model: ModelTrait,
|
Model: ModelTrait,
|
||||||
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::Err: Debug,
|
|
||||||
{
|
{
|
||||||
match target_col {
|
match target_col {
|
||||||
Identity::Unary(a) => {
|
Identity::Unary(a) => {
|
||||||
@ -170,7 +161,7 @@ where
|
|||||||
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
||||||
&a.to_string(),
|
&a.to_string(),
|
||||||
)
|
)
|
||||||
.expect("Failed at mapping string to column A:1");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column A:1"));
|
||||||
ValueTuple::One(model.get(column_a))
|
ValueTuple::One(model.get(column_a))
|
||||||
}
|
}
|
||||||
Identity::Binary(a, b) => {
|
Identity::Binary(a, b) => {
|
||||||
@ -178,12 +169,12 @@ where
|
|||||||
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
||||||
&a.to_string(),
|
&a.to_string(),
|
||||||
)
|
)
|
||||||
.expect("Failed at mapping string to column A:2");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column A:2"));
|
||||||
let column_b =
|
let column_b =
|
||||||
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
||||||
&b.to_string(),
|
&b.to_string(),
|
||||||
)
|
)
|
||||||
.expect("Failed at mapping string to column B:2");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column B:2"));
|
||||||
ValueTuple::Two(model.get(column_a), model.get(column_b))
|
ValueTuple::Two(model.get(column_a), model.get(column_b))
|
||||||
}
|
}
|
||||||
Identity::Ternary(a, b, c) => {
|
Identity::Ternary(a, b, c) => {
|
||||||
@ -191,17 +182,17 @@ where
|
|||||||
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
||||||
&a.to_string(),
|
&a.to_string(),
|
||||||
)
|
)
|
||||||
.expect("Failed at mapping string to column A:3");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column A:3"));
|
||||||
let column_b =
|
let column_b =
|
||||||
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
||||||
&b.to_string(),
|
&b.to_string(),
|
||||||
)
|
)
|
||||||
.expect("Failed at mapping string to column B:3");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column B:3"));
|
||||||
let column_c =
|
let column_c =
|
||||||
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
<<<Model as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::from_str(
|
||||||
&c.to_string(),
|
&c.to_string(),
|
||||||
)
|
)
|
||||||
.expect("Failed at mapping string to column C:3");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column C:3"));
|
||||||
ValueTuple::Three(
|
ValueTuple::Three(
|
||||||
model.get(column_a),
|
model.get(column_a),
|
||||||
model.get(column_b),
|
model.get(column_b),
|
||||||
@ -214,13 +205,12 @@ where
|
|||||||
fn prepare_condition<M>(col: &Identity, keys: &[ValueTuple]) -> Condition
|
fn prepare_condition<M>(col: &Identity, keys: &[ValueTuple]) -> Condition
|
||||||
where
|
where
|
||||||
M: ModelTrait,
|
M: ModelTrait,
|
||||||
<<<M as ModelTrait>::Entity as EntityTrait>::Column as FromStr>::Err: Debug,
|
|
||||||
{
|
{
|
||||||
match col {
|
match col {
|
||||||
Identity::Unary(column_a) => {
|
Identity::Unary(column_a) => {
|
||||||
let column_a: <M::Entity as EntityTrait>::Column =
|
let column_a: <M::Entity as EntityTrait>::Column =
|
||||||
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_a.to_string())
|
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_a.to_string())
|
||||||
.expect("Failed at mapping string to column *A:1");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column *A:1"));
|
||||||
Condition::all().add(ColumnTrait::is_in(
|
Condition::all().add(ColumnTrait::is_in(
|
||||||
&column_a,
|
&column_a,
|
||||||
keys.iter().cloned().flatten(),
|
keys.iter().cloned().flatten(),
|
||||||
@ -229,10 +219,10 @@ where
|
|||||||
Identity::Binary(column_a, column_b) => {
|
Identity::Binary(column_a, column_b) => {
|
||||||
let column_a: <M::Entity as EntityTrait>::Column =
|
let column_a: <M::Entity as EntityTrait>::Column =
|
||||||
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_a.to_string())
|
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_a.to_string())
|
||||||
.expect("Failed at mapping string to column *A:2");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column *A:2"));
|
||||||
let column_b: <M::Entity as EntityTrait>::Column =
|
let column_b: <M::Entity as EntityTrait>::Column =
|
||||||
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_b.to_string())
|
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_b.to_string())
|
||||||
.expect("Failed at mapping string to column *B:2");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column *B:2"));
|
||||||
Condition::all().add(
|
Condition::all().add(
|
||||||
Expr::tuple([
|
Expr::tuple([
|
||||||
SimpleExpr::Column(column_a.into_column_ref()),
|
SimpleExpr::Column(column_a.into_column_ref()),
|
||||||
@ -244,13 +234,13 @@ where
|
|||||||
Identity::Ternary(column_a, column_b, column_c) => {
|
Identity::Ternary(column_a, column_b, column_c) => {
|
||||||
let column_a: <M::Entity as EntityTrait>::Column =
|
let column_a: <M::Entity as EntityTrait>::Column =
|
||||||
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_a.to_string())
|
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_a.to_string())
|
||||||
.expect("Failed at mapping string to column *A:3");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column *A:3"));
|
||||||
let column_b: <M::Entity as EntityTrait>::Column =
|
let column_b: <M::Entity as EntityTrait>::Column =
|
||||||
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_b.to_string())
|
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_b.to_string())
|
||||||
.expect("Failed at mapping string to column *B:3");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column *B:3"));
|
||||||
let column_c: <M::Entity as EntityTrait>::Column =
|
let column_c: <M::Entity as EntityTrait>::Column =
|
||||||
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_c.to_string())
|
<<M::Entity as EntityTrait>::Column as FromStr>::from_str(&column_c.to_string())
|
||||||
.expect("Failed at mapping string to column *C:3");
|
.unwrap_or_else(|_| panic!("Failed at mapping string to column *C:3"));
|
||||||
Condition::all().add(
|
Condition::all().add(
|
||||||
Expr::tuple([
|
Expr::tuple([
|
||||||
SimpleExpr::Column(column_a.into_column_ref()),
|
SimpleExpr::Column(column_a.into_column_ref()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user