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