mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
Move lifetime parameters to associated types
This commit is contained in:
parent
eec238496c
commit
af1bc858ce
13 changed files with 183 additions and 176 deletions
|
@ -152,23 +152,23 @@ where ca.comment_id = c.id"
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for Comment {
|
||||
type InsertForm = CommentInsertForm;
|
||||
type UpdateForm = CommentUpdateForm;
|
||||
impl Crud for Comment {
|
||||
type InsertForm<'a> = &'a CommentInsertForm;
|
||||
type UpdateForm<'a> = &'a CommentUpdateForm;
|
||||
type IdType = CommentId;
|
||||
|
||||
/// This is unimplemented, use [[Comment::create]]
|
||||
async fn create(
|
||||
async fn create<'a>(
|
||||
_pool: &mut DbPool<'_>,
|
||||
_comment_form: &'a Self::InsertForm,
|
||||
_comment_form: Self::InsertForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
comment_id: CommentId,
|
||||
comment_form: &'a Self::UpdateForm,
|
||||
comment_form: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(comment.find(comment_id))
|
||||
|
|
|
@ -9,14 +9,14 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
|||
use diesel_async::RunQueryDsl;
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for CommentReply {
|
||||
type InsertForm = CommentReplyInsertForm;
|
||||
type UpdateForm = CommentReplyUpdateForm;
|
||||
impl Crud for CommentReply {
|
||||
type InsertForm<'a> = &'a CommentReplyInsertForm;
|
||||
type UpdateForm<'a> = &'a CommentReplyUpdateForm;
|
||||
type IdType = CommentReplyId;
|
||||
|
||||
async fn create(
|
||||
async fn create<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
comment_reply_form: &'a Self::InsertForm,
|
||||
comment_reply_form: Self::InsertForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
||||
|
@ -31,10 +31,10 @@ impl<'a> Crud<'a> for CommentReply {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
comment_reply_id: CommentReplyId,
|
||||
comment_reply_form: &'a Self::UpdateForm,
|
||||
comment_reply_form: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(comment_reply.find(comment_reply_id))
|
||||
|
|
|
@ -23,12 +23,12 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
|||
use diesel_async::RunQueryDsl;
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for Community {
|
||||
type InsertForm = CommunityInsertForm;
|
||||
type UpdateForm = CommunityUpdateForm;
|
||||
impl Crud for Community {
|
||||
type InsertForm<'a> = &'a CommunityInsertForm;
|
||||
type UpdateForm<'a> = &'a CommunityUpdateForm;
|
||||
type IdType = CommunityId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
let is_new_community = match &form.actor_id {
|
||||
Some(id) => Community::read_from_apub_id(pool, id).await?.is_none(),
|
||||
None => true,
|
||||
|
@ -52,10 +52,10 @@ impl<'a> Crud<'a> for Community {
|
|||
Ok(community_)
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
community_id: CommunityId,
|
||||
form: &'a Self::UpdateForm,
|
||||
form: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(community::table.find(community_id))
|
||||
|
|
|
@ -65,12 +65,12 @@ impl LocalUser {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for LocalUser {
|
||||
type InsertForm = LocalUserInsertForm;
|
||||
type UpdateForm = LocalUserUpdateForm;
|
||||
impl Crud for LocalUser {
|
||||
type InsertForm<'a> = &'a LocalUserInsertForm;
|
||||
type UpdateForm<'a> = &'a LocalUserUpdateForm;
|
||||
type IdType = LocalUserId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
let mut form_with_encrypted_password = form.clone();
|
||||
let password_hash =
|
||||
|
@ -94,10 +94,10 @@ impl<'a> Crud<'a> for LocalUser {
|
|||
|
||||
Ok(local_user_)
|
||||
}
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
local_user_id: LocalUserId,
|
||||
form: &'a Self::UpdateForm,
|
||||
form: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(local_user.find(local_user_id))
|
||||
|
|
|
@ -38,12 +38,12 @@ use diesel::{dsl::insert_into, result::Error, QueryDsl};
|
|||
use diesel_async::RunQueryDsl;
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModRemovePost {
|
||||
type InsertForm = ModRemovePostForm;
|
||||
type UpdateForm = ModRemovePostForm;
|
||||
impl Crud for ModRemovePost {
|
||||
type InsertForm<'a> = &'a ModRemovePostForm;
|
||||
type UpdateForm<'a> = &'a ModRemovePostForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModRemovePostForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: &'a ModRemovePostForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_remove_post)
|
||||
|
@ -52,7 +52,7 @@ impl<'a> Crud<'a> for ModRemovePost {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModRemovePostForm,
|
||||
|
@ -67,12 +67,12 @@ impl<'a> Crud<'a> for ModRemovePost {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModLockPost {
|
||||
type InsertForm = ModLockPostForm;
|
||||
type UpdateForm = ModLockPostForm;
|
||||
impl Crud for ModLockPost {
|
||||
type InsertForm<'a> = &'a ModLockPostForm;
|
||||
type UpdateForm<'a> = &'a ModLockPostForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModLockPostForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: &'a ModLockPostForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_lock_post)
|
||||
|
@ -81,7 +81,7 @@ impl<'a> Crud<'a> for ModLockPost {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModLockPostForm,
|
||||
|
@ -96,12 +96,12 @@ impl<'a> Crud<'a> for ModLockPost {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModFeaturePost {
|
||||
type InsertForm = ModFeaturePostForm;
|
||||
type UpdateForm = ModFeaturePostForm;
|
||||
impl Crud for ModFeaturePost {
|
||||
type InsertForm<'a> = &'a ModFeaturePostForm;
|
||||
type UpdateForm<'a> = &'a ModFeaturePostForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModFeaturePostForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: &'a ModFeaturePostForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_feature_post)
|
||||
|
@ -110,7 +110,7 @@ impl<'a> Crud<'a> for ModFeaturePost {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModFeaturePostForm,
|
||||
|
@ -125,12 +125,15 @@ impl<'a> Crud<'a> for ModFeaturePost {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModRemoveComment {
|
||||
type InsertForm = ModRemoveCommentForm;
|
||||
type UpdateForm = ModRemoveCommentForm;
|
||||
impl Crud for ModRemoveComment {
|
||||
type InsertForm<'a> = &'a ModRemoveCommentForm;
|
||||
type UpdateForm<'a> = &'a ModRemoveCommentForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModRemoveCommentForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
form: &'a ModRemoveCommentForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_remove_comment)
|
||||
|
@ -139,7 +142,7 @@ impl<'a> Crud<'a> for ModRemoveComment {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModRemoveCommentForm,
|
||||
|
@ -154,12 +157,15 @@ impl<'a> Crud<'a> for ModRemoveComment {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModRemoveCommunity {
|
||||
type InsertForm = ModRemoveCommunityForm;
|
||||
type UpdateForm = ModRemoveCommunityForm;
|
||||
impl Crud for ModRemoveCommunity {
|
||||
type InsertForm<'a> = &'a ModRemoveCommunityForm;
|
||||
type UpdateForm<'a> = &'a ModRemoveCommunityForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModRemoveCommunityForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
form: &'a ModRemoveCommunityForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_remove_community)
|
||||
|
@ -168,7 +174,7 @@ impl<'a> Crud<'a> for ModRemoveCommunity {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModRemoveCommunityForm,
|
||||
|
@ -183,12 +189,15 @@ impl<'a> Crud<'a> for ModRemoveCommunity {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModBanFromCommunity {
|
||||
type InsertForm = ModBanFromCommunityForm;
|
||||
type UpdateForm = ModBanFromCommunityForm;
|
||||
impl Crud for ModBanFromCommunity {
|
||||
type InsertForm<'a> = &'a ModBanFromCommunityForm;
|
||||
type UpdateForm<'a> = &'a ModBanFromCommunityForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModBanFromCommunityForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
form: &'a ModBanFromCommunityForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_ban_from_community)
|
||||
|
@ -197,7 +206,7 @@ impl<'a> Crud<'a> for ModBanFromCommunity {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModBanFromCommunityForm,
|
||||
|
@ -212,12 +221,12 @@ impl<'a> Crud<'a> for ModBanFromCommunity {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModBan {
|
||||
type InsertForm = ModBanForm;
|
||||
type UpdateForm = ModBanForm;
|
||||
impl Crud for ModBan {
|
||||
type InsertForm<'a> = &'a ModBanForm;
|
||||
type UpdateForm<'a> = &'a ModBanForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModBanForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: &'a ModBanForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_ban::dsl::mod_ban;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_ban)
|
||||
|
@ -226,7 +235,7 @@ impl<'a> Crud<'a> for ModBan {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModBanForm,
|
||||
|
@ -241,12 +250,15 @@ impl<'a> Crud<'a> for ModBan {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModHideCommunity {
|
||||
type InsertForm = ModHideCommunityForm;
|
||||
type UpdateForm = ModHideCommunityForm;
|
||||
impl Crud for ModHideCommunity {
|
||||
type InsertForm<'a> = &'a ModHideCommunityForm;
|
||||
type UpdateForm<'a> = &'a ModHideCommunityForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModHideCommunityForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
form: &'a ModHideCommunityForm,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_hide_community)
|
||||
|
@ -255,7 +267,7 @@ impl<'a> Crud<'a> for ModHideCommunity {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModHideCommunityForm,
|
||||
|
@ -270,12 +282,12 @@ impl<'a> Crud<'a> for ModHideCommunity {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModAddCommunity {
|
||||
type InsertForm = ModAddCommunityForm;
|
||||
type UpdateForm = ModAddCommunityForm;
|
||||
impl Crud for ModAddCommunity {
|
||||
type InsertForm<'a> = &'a ModAddCommunityForm;
|
||||
type UpdateForm<'a> = &'a ModAddCommunityForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModAddCommunityForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: &'a ModAddCommunityForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_add_community::dsl::mod_add_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_add_community)
|
||||
|
@ -284,7 +296,7 @@ impl<'a> Crud<'a> for ModAddCommunity {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModAddCommunityForm,
|
||||
|
@ -299,12 +311,12 @@ impl<'a> Crud<'a> for ModAddCommunity {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModTransferCommunity {
|
||||
type InsertForm = ModTransferCommunityForm;
|
||||
type UpdateForm = ModTransferCommunityForm;
|
||||
impl Crud for ModTransferCommunity {
|
||||
type InsertForm<'a> = &'a ModTransferCommunityForm;
|
||||
type UpdateForm<'a> = &'a ModTransferCommunityForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(
|
||||
async fn create<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
form: &'a ModTransferCommunityForm,
|
||||
) -> Result<Self, Error> {
|
||||
|
@ -316,7 +328,7 @@ impl<'a> Crud<'a> for ModTransferCommunity {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModTransferCommunityForm,
|
||||
|
@ -331,12 +343,12 @@ impl<'a> Crud<'a> for ModTransferCommunity {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for ModAdd {
|
||||
type InsertForm = ModAddForm;
|
||||
type UpdateForm = ModAddForm;
|
||||
impl Crud for ModAdd {
|
||||
type InsertForm<'a> = &'a ModAddForm;
|
||||
type UpdateForm<'a> = &'a ModAddForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a ModAddForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: &'a ModAddForm) -> Result<Self, Error> {
|
||||
use crate::schema::mod_add::dsl::mod_add;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(mod_add)
|
||||
|
@ -345,7 +357,7 @@ impl<'a> Crud<'a> for ModAdd {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a ModAddForm,
|
||||
|
@ -360,12 +372,12 @@ impl<'a> Crud<'a> for ModAdd {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for AdminPurgePerson {
|
||||
type InsertForm = AdminPurgePersonForm;
|
||||
type UpdateForm = AdminPurgePersonForm;
|
||||
impl Crud for AdminPurgePerson {
|
||||
type InsertForm<'a> = &'a AdminPurgePersonForm;
|
||||
type UpdateForm<'a> = &'a AdminPurgePersonForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_purge_person)
|
||||
|
@ -374,10 +386,10 @@ impl<'a> Crud<'a> for AdminPurgePerson {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a Self::InsertForm,
|
||||
form: Self::InsertForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
@ -389,12 +401,12 @@ impl<'a> Crud<'a> for AdminPurgePerson {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for AdminPurgeCommunity {
|
||||
type InsertForm = AdminPurgeCommunityForm;
|
||||
type UpdateForm = AdminPurgeCommunityForm;
|
||||
impl Crud for AdminPurgeCommunity {
|
||||
type InsertForm<'a> = &'a AdminPurgeCommunityForm;
|
||||
type UpdateForm<'a> = &'a AdminPurgeCommunityForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_purge_community)
|
||||
|
@ -403,10 +415,10 @@ impl<'a> Crud<'a> for AdminPurgeCommunity {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a Self::InsertForm,
|
||||
form: Self::InsertForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
@ -418,12 +430,12 @@ impl<'a> Crud<'a> for AdminPurgeCommunity {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for AdminPurgePost {
|
||||
type InsertForm = AdminPurgePostForm;
|
||||
type UpdateForm = AdminPurgePostForm;
|
||||
impl Crud for AdminPurgePost {
|
||||
type InsertForm<'a> = &'a AdminPurgePostForm;
|
||||
type UpdateForm<'a> = &'a AdminPurgePostForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_purge_post)
|
||||
|
@ -432,10 +444,10 @@ impl<'a> Crud<'a> for AdminPurgePost {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a Self::InsertForm,
|
||||
form: Self::InsertForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
@ -447,12 +459,12 @@ impl<'a> Crud<'a> for AdminPurgePost {
|
|||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for AdminPurgeComment {
|
||||
type InsertForm = AdminPurgeCommentForm;
|
||||
type UpdateForm = AdminPurgeCommentForm;
|
||||
impl Crud for AdminPurgeComment {
|
||||
type InsertForm<'a> = &'a AdminPurgeCommentForm;
|
||||
type UpdateForm<'a> = &'a AdminPurgeCommentForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(admin_purge_comment)
|
||||
|
@ -461,10 +473,10 @@ impl<'a> Crud<'a> for AdminPurgeComment {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
from_id: i32,
|
||||
form: &'a Self::InsertForm,
|
||||
form: Self::InsertForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
|
|
@ -20,12 +20,12 @@ use diesel_async::RunQueryDsl;
|
|||
use sha2::{Digest, Sha256};
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for PasswordResetRequest {
|
||||
type InsertForm = PasswordResetRequestForm;
|
||||
type UpdateForm = PasswordResetRequestForm;
|
||||
impl Crud for PasswordResetRequest {
|
||||
type InsertForm<'a> = &'a PasswordResetRequestForm;
|
||||
type UpdateForm<'a> = &'a PasswordResetRequestForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(
|
||||
async fn create<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
form: &'a PasswordResetRequestForm,
|
||||
) -> Result<Self, Error> {
|
||||
|
@ -35,7 +35,7 @@ impl<'a> Crud<'a> for PasswordResetRequest {
|
|||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
password_reset_request_id: i32,
|
||||
form: &'a PasswordResetRequestForm,
|
||||
|
|
|
@ -15,11 +15,11 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, Quer
|
|||
use diesel_async::RunQueryDsl;
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for Person {
|
||||
type InsertForm = PersonInsertForm;
|
||||
type UpdateForm = PersonUpdateForm;
|
||||
impl Crud for Person {
|
||||
type InsertForm<'a> = &'a PersonInsertForm;
|
||||
type UpdateForm<'a> = &'a PersonUpdateForm;
|
||||
type IdType = PersonId;
|
||||
async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
|
||||
async fn read<'a>(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
person::table
|
||||
.filter(person::deleted.eq(false))
|
||||
|
@ -28,14 +28,14 @@ impl<'a> Crud<'a> for Person {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a PersonInsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: &'a PersonInsertForm) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(person::table)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
.await
|
||||
}
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
person_id: PersonId,
|
||||
form: &'a PersonUpdateForm,
|
||||
|
|
|
@ -9,14 +9,14 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
|||
use diesel_async::RunQueryDsl;
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for PersonMention {
|
||||
type InsertForm = PersonMentionInsertForm;
|
||||
type UpdateForm = PersonMentionUpdateForm;
|
||||
impl Crud for PersonMention {
|
||||
type InsertForm<'a> = &'a PersonMentionInsertForm;
|
||||
type UpdateForm<'a> = &'a PersonMentionUpdateForm;
|
||||
type IdType = PersonMentionId;
|
||||
|
||||
async fn create(
|
||||
async fn create<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
person_mention_form: &'a Self::InsertForm,
|
||||
person_mention_form: Self::InsertForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
// since the return here isnt utilized, we dont need to do an update
|
||||
|
@ -30,10 +30,10 @@ impl<'a> Crud<'a> for PersonMention {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
person_mention_id: PersonMentionId,
|
||||
person_mention_form: &'a Self::UpdateForm,
|
||||
person_mention_form: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(person_mention.find(person_mention_id))
|
||||
|
|
|
@ -34,12 +34,12 @@ use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextE
|
|||
use diesel_async::RunQueryDsl;
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for Post {
|
||||
type InsertForm = PostInsertForm;
|
||||
type UpdateForm = PostUpdateForm;
|
||||
impl Crud for Post {
|
||||
type InsertForm<'a> = &'a PostInsertForm;
|
||||
type UpdateForm<'a> = &'a PostUpdateForm;
|
||||
type IdType = PostId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(post)
|
||||
.values(form)
|
||||
|
@ -50,10 +50,10 @@ impl<'a> Crud<'a> for Post {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
post_id: PostId,
|
||||
new_post: &'a Self::UpdateForm,
|
||||
new_post: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(post.find(post_id))
|
||||
|
|
|
@ -11,12 +11,12 @@ use lemmy_utils::error::LemmyError;
|
|||
use url::Url;
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for PrivateMessage {
|
||||
type InsertForm = PrivateMessageInsertForm;
|
||||
type UpdateForm = PrivateMessageUpdateForm;
|
||||
impl Crud for PrivateMessage {
|
||||
type InsertForm<'a> = &'a PrivateMessageInsertForm;
|
||||
type UpdateForm<'a> = &'a PrivateMessageUpdateForm;
|
||||
type IdType = PrivateMessageId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(private_message)
|
||||
.values(form)
|
||||
|
@ -27,10 +27,10 @@ impl<'a> Crud<'a> for PrivateMessage {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
private_message_id: PrivateMessageId,
|
||||
form: &'a Self::UpdateForm,
|
||||
form: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(private_message.find(private_message_id))
|
||||
|
|
|
@ -13,12 +13,12 @@ use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
|||
use diesel_async::RunQueryDsl;
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for RegistrationApplication {
|
||||
type InsertForm = RegistrationApplicationInsertForm;
|
||||
type UpdateForm = RegistrationApplicationUpdateForm;
|
||||
impl Crud for RegistrationApplication {
|
||||
type InsertForm<'a> = &'a RegistrationApplicationInsertForm;
|
||||
type UpdateForm<'a> = &'a RegistrationApplicationUpdateForm;
|
||||
type IdType = i32;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
insert_into(registration_application)
|
||||
.values(form)
|
||||
|
@ -26,10 +26,10 @@ impl<'a> Crud<'a> for RegistrationApplication {
|
|||
.await
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
id_: Self::IdType,
|
||||
form: &'a Self::UpdateForm,
|
||||
form: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(registration_application.find(id_))
|
||||
|
|
|
@ -13,12 +13,12 @@ use diesel_async::RunQueryDsl;
|
|||
use url::Url;
|
||||
|
||||
#[async_trait]
|
||||
impl<'a> Crud<'a> for Site {
|
||||
type InsertForm = SiteInsertForm;
|
||||
type UpdateForm = SiteUpdateForm;
|
||||
impl Crud for Site {
|
||||
type InsertForm<'a> = &'a SiteInsertForm;
|
||||
type UpdateForm<'a> = &'a SiteUpdateForm;
|
||||
type IdType = SiteId;
|
||||
|
||||
async fn create(pool: &mut DbPool<'_>, form: &'a Self::InsertForm) -> Result<Self, Error> {
|
||||
async fn create<'a>(pool: &mut DbPool<'_>, form: Self::InsertForm<'a>) -> Result<Self, Error> {
|
||||
let is_new_site = match &form.actor_id {
|
||||
Some(id_) => Site::read_from_apub_id(pool, id_).await?.is_none(),
|
||||
None => true,
|
||||
|
@ -42,10 +42,10 @@ impl<'a> Crud<'a> for Site {
|
|||
Ok(site_)
|
||||
}
|
||||
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
site_id: SiteId,
|
||||
new_site: &'a Self::UpdateForm,
|
||||
new_site: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(site.find(site_id))
|
||||
|
|
|
@ -28,10 +28,15 @@ use std::{hash::Hash, pin::Pin};
|
|||
/// Returned by `diesel::delete`
|
||||
pub type Delete<T> = DeleteStatement<<T as HasTable>::Table, <T as IntoUpdateTarget>::WhereClause>;
|
||||
|
||||
pub type Find<'a, T> = dsl::Find<<T as HasTable>::Table, <T as Crud<'a>>::IdType>;
|
||||
pub type Find<T> = dsl::Find<<T as HasTable>::Table, <T as Crud>::IdType>;
|
||||
|
||||
pub type InsertValues<'a, 'b, T> =
|
||||
<&'a <T as Crud<'b>>::InsertForm as Insertable<<T as HasTable>::Table>>::Values;
|
||||
pub type InsertValues<F, T> =
|
||||
<F as Insertable<T>>::Values;
|
||||
|
||||
pub trait InsertFormBound<'a, T:Table,>: 'a + Send + Sync + Copy + Insertable<T> where
|
||||
InsertValues<Self,T>: 'a,
|
||||
InsertStatement<T, InsertValues<'Self,T>>:
|
||||
LoadQuery<'a, AsyncPgConnection, Self> + 'a + Send,
|
||||
|
||||
// When using `RunQueryDsl::execute`, directly building futures with `Box::pin` and `TryFutureExt::and_then`
|
||||
// instead of `async` + `await` fixes weird compile errors.
|
||||
|
@ -39,33 +44,29 @@ pub type InsertValues<'a, 'b, T> =
|
|||
// When using `RunQueryDsl::first` or 'RunQueryDsl::get_result`, `async` + `await` works, and it must be used otherwise the closure for `and_then`
|
||||
// will both own `conn` and return a future that references it.
|
||||
#[async_trait]
|
||||
pub trait Crud<'a>
|
||||
pub trait Crud
|
||||
where
|
||||
Self: HasTable + Sized + Send,
|
||||
for<'b> Self::Table: FindDsl<<Self as Crud<'b>>::IdType> + 'static,
|
||||
for<'b> Find<'b, Self>: LimitDsl + Send + IntoUpdateTarget + 'static,
|
||||
for<'b> dsl::Limit<Find<'b, Self>>: Send + LoadQuery<'static, AsyncPgConnection, Self> + 'static,
|
||||
Self::Table: FindDsl<Self::IdType> + 'static,
|
||||
Find<Self>: LimitDsl + Send + IntoUpdateTarget + 'static,
|
||||
dsl::Limit<Find<Self>>: Send + LoadQuery<'static, AsyncPgConnection, Self> + 'static,
|
||||
<Self::Table as Table>::PrimaryKey: ExpressionMethods + Send,
|
||||
<<Self::Table as Table>::PrimaryKey as Expression>::SqlType: SqlType + TypedExpressionType,
|
||||
for<'b> Delete<Find<'b, Self>>: ExecuteDsl<AsyncPgConnection> + Send + 'static,
|
||||
for<'b> <Find<'b, Self> as IntoUpdateTarget>::WhereClause: 'static + Send,
|
||||
for<'b> <Find<'b, Self> as HasTable>::Table: 'static + Send,
|
||||
for<'b> &'a <Self as Crud<'b>>::InsertForm: Insertable<Self::Table>,
|
||||
for<'b> InsertValues<'a, 'b, Self>: 'a,
|
||||
for<'b> InsertStatement<Self::Table, InsertValues<'a, 'b, Self>>:
|
||||
LoadQuery<'a, AsyncPgConnection, Self> + 'a + Send,
|
||||
Delete<Find<Self>>: ExecuteDsl<AsyncPgConnection> + Send + 'static,
|
||||
<Find<Self> as IntoUpdateTarget>::WhereClause: 'static + Send,
|
||||
<Find<Self> as HasTable>::Table: 'static + Send,
|
||||
{
|
||||
type InsertForm: 'static + Send + Sync;
|
||||
type UpdateForm: 'static + Send + Sync;
|
||||
type InsertForm<'a>: 'a + Send + Sync + Copy + Insertable<Self::Table>;
|
||||
type UpdateForm<'a>: 'a + Send + Sync + Copy;
|
||||
type IdType: 'static
|
||||
+ Hash
|
||||
+ Eq
|
||||
+ Sized
|
||||
+ Send
|
||||
+ AsExpression<<<Self::Table as Table>::PrimaryKey as Expression>::SqlType>;
|
||||
fn create<'life0, 'life1, 'async_trait>(
|
||||
fn create<'a, 'life0, 'life1, 'async_trait>(
|
||||
pool: &'life0 mut DbPool<'life1>,
|
||||
form: &'a Self::InsertForm,
|
||||
form: Self::InsertForm<'a>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'async_trait>>
|
||||
where
|
||||
'a: 'async_trait,
|
||||
|
@ -81,22 +82,17 @@ where
|
|||
.and_then(move |mut conn| async move { query.get_result::<Self>(&mut *conn).await }),
|
||||
)
|
||||
}
|
||||
async fn read(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<Self, Error>
|
||||
where
|
||||
'a: 'async_trait,
|
||||
{
|
||||
async fn read(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<Self, Error> {
|
||||
let query = Self::table().find(id);
|
||||
let conn = &mut *get_conn(pool).await?;
|
||||
query.first::<Self>(conn).await
|
||||
}
|
||||
/// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
|
||||
async fn update(
|
||||
async fn update<'a>(
|
||||
pool: &mut DbPool<'_>,
|
||||
id: Self::IdType,
|
||||
form: &'a Self::UpdateForm,
|
||||
) -> Result<Self, Error>
|
||||
where
|
||||
'a: 'async_trait;
|
||||
form: Self::UpdateForm<'a>,
|
||||
) -> Result<Self, Error>;
|
||||
/*{
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
diesel::update(Self::table().find(id))
|
||||
|
@ -109,12 +105,11 @@ where
|
|||
id: Self::IdType,
|
||||
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>>
|
||||
where
|
||||
'a: 'async_trait,
|
||||
'life0: 'async_trait,
|
||||
'life1: 'async_trait,
|
||||
Self: Send + 'async_trait,
|
||||
{
|
||||
let query: Delete<Find<'a, Self>> = diesel::delete(Self::table().find(id));
|
||||
let query: Delete<Find<Self>> = diesel::delete(Self::table().find(id));
|
||||
Box::pin(get_conn(pool).and_then(move |mut conn| query.execute(&mut *conn)))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue