data: return newly crated entries in SQL

This commit is contained in:
anna 2022-12-25 05:19:08 +01:00
parent fb8bf0f316
commit 93182705d9
Signed by: fef
GPG key ID: EC22E476DC2D3D84
2 changed files with 13 additions and 11 deletions

View file

@ -28,12 +28,13 @@ impl PgFollowDataSource {
T: Into<NewFollow> + Send,
{
let new = new.into();
let follow: Follow =
sqlx::query_as("INSERT INTO follows (follower_id, followee_id) VALUES ($1, $2)")
.bind(new.follower_id)
.bind(new.followee_id)
.fetch_one(&self.pool)
.await?;
let follow: Follow = sqlx::query_as(
"INSERT INTO follows (follower_id, followee_id) VALUES ($1, $2) RETURNING *",
)
.bind(new.follower_id)
.bind(new.followee_id)
.fetch_one(&self.pool)
.await?;
Ok(follow)
}

View file

@ -30,11 +30,12 @@ impl PgLikeDataSource {
E: Into<Error>,
{
let new = new.try_into().map_err(|e| e.into())?.inner();
let like: Like = sqlx::query_as("INSERT INTO likes (note_id, account_id) VALUES ($1, $2)")
.bind(new.note_id)
.bind(new.account_id)
.fetch_one(&self.pool)
.await?;
let like: Like =
sqlx::query_as("INSERT INTO likes (note_id, account_id) VALUES ($1, $2) RETURNING *")
.bind(new.note_id)
.bind(new.account_id)
.fetch_one(&self.pool)
.await?;
Ok(like)
}