diff options
author | 2024-11-14 21:43:54 +0000 | |
---|---|---|
committer | 2024-11-14 21:43:54 +0000 | |
commit | 67b54449a1bbde257e9454419e7bb70ebc515c0f (patch) | |
tree | e23710c2d1f5d219205f26af727b478e455a0071 /src/db/comments.rs | |
parent | 469a3ad33914f7eff6edc9ca7fabb12f2950da84 (diff) | |
download | critch-67b54449a1bbde257e9454419e7bb70ebc515c0f.tar.gz critch-67b54449a1bbde257e9454419e7bb70ebc515c0f.tar.bz2 critch-67b54449a1bbde257e9454419e7bb70ebc515c0f.zip |
Diffstat (limited to 'src/db/comments.rs')
-rw-r--r-- | src/db/comments.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/db/comments.rs b/src/db/comments.rs index ec07aa0..3c14852 100644 --- a/src/db/comments.rs +++ b/src/db/comments.rs @@ -13,13 +13,13 @@ impl Comments { pub async fn create(&self, comment: Comment) -> Result<i32> { let comment_id = sqlx::query!( - r#"insert into comments (text, artwork_id) values ($1, $2) returning id"#, + r#"insert into comments (text, artwork_id) values ($1, $2) returning comment_id"#, comment.text, comment.artwork_id ) .fetch_one(&self.0) .await? - .id; + .comment_id; for in_reply_to_id in comment.in_reply_to_ids { sqlx::query!("insert into comment_relations (artwork_id, in_reply_to_id, comment_id) values ($1, $2, $3)", comment.artwork_id, in_reply_to_id, comment_id).execute(&self.0).await?; } @@ -35,8 +35,11 @@ impl Comments { } pub async fn read_thread(&self, artwork_id: i32) -> Result<Vec<Comment>> { - Ok(sqlx::query_as("select * from comments") - .fetch_all(&self.0) - .await?) + Ok( + sqlx::query_as("select * from comments where artwork_id = $1") + .bind(artwork_id) + .fetch_all(&self.0) + .await?, + ) } } |