(
self,
question: Question,
id: i32,
)
| 79 | } |
| 80 | |
| 81 | pub async fn update_question( |
| 82 | self, |
| 83 | question: Question, |
| 84 | id: i32, |
| 85 | ) -> Result<Question, Error> { |
| 86 | match sqlx::query( |
| 87 | "UPDATE questions SET title = $1, content = $2, tags = $3 |
| 88 | WHERE id = $4 |
| 89 | RETURNING id, title, content, tags", |
| 90 | ) |
| 91 | .bind(question.title) |
| 92 | .bind(question.content) |
| 93 | .bind(question.tags) |
| 94 | .bind(id) |
| 95 | .map(|row: PgRow| Question { |
| 96 | id: QuestionId(row.get("id")), |
| 97 | title: row.get("title"), |
| 98 | content: row.get("content"), |
| 99 | tags: row.get("tags"), |
| 100 | }) |
| 101 | .fetch_one(&self.connection) |
| 102 | .await |
| 103 | { |
| 104 | Ok(question) => Ok(question), |
| 105 | Err(e) => { |
| 106 | tracing::event!(tracing::Level::ERROR, "{:?}", e); |
| 107 | Err(Error::DatabaseQueryError) |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | pub async fn delete_question(self, id: i32) -> Result<bool, Error> { |
| 113 | match sqlx::query("DELETE FROM questions WHERE id = $1") |
no test coverage detected