From ceab8620219faa067183862c44a886ea0a064f9d Mon Sep 17 00:00:00 2001 From: dull b Date: Fri, 14 Jul 2023 05:05:09 +0000 Subject: [PATCH] fmt --- crates/db_schema/src/traits.rs | 124 ++++++++++++++++----------------- 1 file changed, 61 insertions(+), 63 deletions(-) diff --git a/crates/db_schema/src/traits.rs b/crates/db_schema/src/traits.rs index 0042956f1..650334940 100644 --- a/crates/db_schema/src/traits.rs +++ b/crates/db_schema/src/traits.rs @@ -1,74 +1,71 @@ use crate::{ newtypes::{CommunityId, DbUrl, PersonId}, - utils::{get_conn, DbPool, DbConn}, + utils::{get_conn, DbConn, DbPool}, }; use diesel::{ associations::HasTable, backend::Backend, deserialize::{FromSqlRow, Queryable}, + dsl, dsl::insert_into, + expression::{ + is_aggregate, + is_contained_in_group_by, + AsExpression, + IsContainedInGroupBy, + ValidGrouping, + }, + expression_methods::ExpressionMethods, pg::Pg, - query_builder::{AsQuery, IntoUpdateTarget, Query, QueryFragment, QueryId,Only}, + query_builder::{AsQuery, IntoUpdateTarget, Only, Query, QueryFragment, QueryId}, + query_dsl::methods::{FilterDsl, LimitDsl, SelectDsl}, + query_source::{AppearsInFromClause, Once}, result::Error, + sql_types::{is_nullable::NotNull, SqlType}, AsChangeset, Column, Expression, Identifiable, Insertable, QuerySource, - Table, - query_dsl::methods::{SelectDsl,LimitDsl,FilterDsl}, - query_source::{Once,AppearsInFromClause}, - expression::{ValidGrouping,is_aggregate, IsContainedInGroupBy,is_contained_in_group_by}, - expression_methods::ExpressionMethods, - sql_types::{SqlType,is_nullable::NotNull}, - expression::AsExpression, SelectableExpression, - dsl, + Table, }; -use diesel_async::{AsyncConnection, RunQueryDsl,methods::LoadQuery}; +use diesel_async::{methods::LoadQuery, AsyncConnection, RunQueryDsl}; use std::hash::Hash; #[async_trait] pub trait Crud where - /*Self: Send + HasTable + Send + 'static + FromSqlRow<::SqlType, Pg>, - Self::Table: Send + FindDsl, - >::Output: LimitDsl + Send, - for<'conn> <>::Output as LimitDsl>::Output: - Send + LoadQuery<'static, DbConn<'conn>, Self> /*+ 'query*/ + Send, - ::SqlType: Send,*/ - - /*Self: Send + 'static + HasTable + Sized, - Self::Table: Send + 'static + AppearsInFromClause, Count = Once> + QueryFragment + HasTable + IntoUpdateTarget::Query as IntoUpdateTarget>::WhereClause> + AppearsInFromClause, - ::Query: IntoUpdateTarget, - //Only: AppearsInFromClause, Count = Once>, - ::PrimaryKey: Send + 'static + QueryFragment + ValidGrouping<(), IsAggregate = is_aggregate::No> + /*IsContainedInGroupBy<::PrimaryKey, Output = is_contained_in_group_by::Yes> +*/ Column
+ AppearsInFromClause> + SelectableExpression> + Expression + Sized, - <::PrimaryKey as Expression>::SqlType: SqlType,*/ - Self: Send + 'static + Sized + HasTable, - Self::Table: FilterDsl::PrimaryKey, Self::IdType>> + Send + Sized + 'static, - ::PrimaryKey, Self::IdType>>>::Output: LimitDsl + Send + Sized + 'static, - //for<'conn> diesel::helper_types::Limit<::PrimaryKey, Self::IdType>>>::Output>: LoadQuery<'static, DbConn<'conn>, Self> + Send + 'static + Sized, + Self::Table: + FilterDsl::PrimaryKey, Self::IdType>> + Send + Sized + 'static, + ::PrimaryKey, Self::IdType>>>::Output: + LimitDsl + Send + Sized + 'static, <::PrimaryKey as Expression>::SqlType: SqlType, ::PrimaryKey: ExpressionMethods + Send + Sized + 'static, - //::AllColumns: Send + Sized + 'static, - //::Query: Send + Sized + 'static, - - //::PrimaryKey, Self::IdType>>>::Output: { type InsertForm; type UpdateForm; - type IdType: Hash + Eq + Send + 'static + Sized + AsExpression<<::PrimaryKey as Expression>::SqlType>; - async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result; /*{ - let conn = &mut get_conn(pool).await?; - insert_into(Self::table()) - .values(form) - .get_result::(conn) - .await - }*/ + type IdType: Hash + + Eq + + Send + + 'static + + Sized + + AsExpression<<::PrimaryKey as Expression>::SqlType>; + async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result; + /*{ + let conn = &mut get_conn(pool).await?; + insert_into(Self::table()) + .values(form) + .get_result::(conn) + .await + }*/ async fn read(pool: &'async_trait mut DbPool<'_>, id: Self::IdType) -> Result - where diesel::helper_types::Limit<::PrimaryKey, Self::IdType>>>::Output>: LoadQuery<'static, DbConn<'async_trait>, Self> + Send + 'static + Sized + where + diesel::helper_types::Limit< + ::PrimaryKey, Self::IdType>>>::Output, + >: LoadQuery<'static, DbConn<'async_trait>, Self> + Send + 'static + Sized, { let col = Self::table().primary_key(); // FindDsl is not used because it uses a private trait @@ -82,15 +79,15 @@ where pool: &mut DbPool<'_>, id: Self::IdType, form: &Self::UpdateForm, - ) -> Result; /*{ - let conn = &mut get_conn(pool).await?; - diesel::update(Self::table().find(id)) - .set(form) - .get_result::(conn) - .await - }*/ - async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result - { + ) -> Result; + /*{ + let conn = &mut get_conn(pool).await?; + diesel::update(Self::table().find(id)) + .set(form) + .get_result::(conn) + .await + }*/ + async fn delete(pool: &mut DbPool<'_>, id: Self::IdType) -> Result { Err(Error::NotFound) /*let conn = &mut get_conn(pool).await?; diesel::delete(Self::table().find(id)).execute(conn).await*/ @@ -108,19 +105,20 @@ where type Form; async fn follow(pool: &mut DbPool<'_>, form: &Self::Form) -> Result where - Self: Sized; /*{ - let conn = &mut get_conn(pool).await?; - insert_into(Self::table()) - .values(form) - .on_conflict(( - Self::TargetColumn::default(), - Self::FollowerColumn::default(), - )) - .do_update() - .set(form) - .get_result::(conn) - .await - }*/ + Self: Sized; + /*{ + let conn = &mut get_conn(pool).await?; + insert_into(Self::table()) + .values(form) + .on_conflict(( + Self::TargetColumn::default(), + Self::FollowerColumn::default(), + )) + .do_update() + .set(form) + .get_result::(conn) + .await + }*/ async fn follow_accepted( pool: &mut DbPool<'_>, community_id: CommunityId,