Removing on_conflict as it may not work with table triggers (user_fast, etc)
This commit is contained in:
parent
60730e81d9
commit
db7027a367
5 changed files with 51 additions and 34 deletions
|
@ -170,13 +170,15 @@ impl Comment {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
|
pub fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
|
||||||
use crate::schema::comment::dsl::*;
|
let existing = Self::read_from_apub_id(
|
||||||
insert_into(comment)
|
conn,
|
||||||
.values(comment_form)
|
comment_form.ap_id.as_ref().unwrap_or(&"none".to_string()),
|
||||||
.on_conflict(ap_id)
|
);
|
||||||
.do_update()
|
match existing {
|
||||||
.set(comment_form)
|
Err(NotFound {}) => Ok(Self::create(conn, &comment_form)?),
|
||||||
.get_result::<Self>(conn)
|
Ok(p) => Ok(Self::update(conn, p.id, &comment_form)?),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,13 +166,18 @@ impl Community {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
|
pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
|
||||||
use crate::schema::community::dsl::*;
|
let existing = Self::read_from_actor_id(
|
||||||
insert_into(community)
|
conn,
|
||||||
.values(community_form)
|
community_form
|
||||||
.on_conflict(actor_id)
|
.actor_id
|
||||||
.do_update()
|
.as_ref()
|
||||||
.set(community_form)
|
.unwrap_or(&"none".to_string()),
|
||||||
.get_result::<Self>(conn)
|
);
|
||||||
|
match existing {
|
||||||
|
Err(NotFound {}) => Ok(Self::create(conn, &community_form)?),
|
||||||
|
Ok(p) => Ok(Self::update(conn, p.id, &community_form)?),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,13 +179,15 @@ impl Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
|
pub fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
|
||||||
use crate::schema::post::dsl::*;
|
let existing = Self::read_from_apub_id(
|
||||||
insert_into(post)
|
conn,
|
||||||
.values(post_form)
|
post_form.ap_id.as_ref().unwrap_or(&"none".to_string()),
|
||||||
.on_conflict(ap_id)
|
);
|
||||||
.do_update()
|
match existing {
|
||||||
.set(post_form)
|
Err(NotFound {}) => Ok(Self::create(conn, &post_form)?),
|
||||||
.get_result::<Self>(conn)
|
Ok(p) => Ok(Self::update(conn, p.id, &post_form)?),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,13 +124,18 @@ impl PrivateMessage {
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
private_message_form: &PrivateMessageForm,
|
private_message_form: &PrivateMessageForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::private_message::dsl::*;
|
let existing = Self::read_from_apub_id(
|
||||||
insert_into(private_message)
|
conn,
|
||||||
.values(private_message_form)
|
private_message_form
|
||||||
.on_conflict(ap_id)
|
.ap_id
|
||||||
.do_update()
|
.as_ref()
|
||||||
.set(private_message_form)
|
.unwrap_or(&"none".to_string()),
|
||||||
.get_result::<Self>(conn)
|
);
|
||||||
|
match existing {
|
||||||
|
Err(NotFound {}) => Ok(Self::create(conn, &private_message_form)?),
|
||||||
|
Ok(p) => Ok(Self::update(conn, p.id, &private_message_form)?),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -161,12 +161,15 @@ impl User_ {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn upsert(conn: &PgConnection, user_form: &UserForm) -> Result<User_, Error> {
|
pub fn upsert(conn: &PgConnection, user_form: &UserForm) -> Result<User_, Error> {
|
||||||
insert_into(user_)
|
let existing = Self::read_from_actor_id(
|
||||||
.values(user_form)
|
conn,
|
||||||
.on_conflict(actor_id)
|
user_form.actor_id.as_ref().unwrap_or(&"none".to_string()),
|
||||||
.do_update()
|
);
|
||||||
.set(user_form)
|
match existing {
|
||||||
.get_result::<Self>(conn)
|
Err(NotFound {}) => Ok(Self::create(conn, &user_form)?),
|
||||||
|
Ok(p) => Ok(Self::update(conn, p.id, &user_form)?),
|
||||||
|
Err(e) => Err(e),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue