(
&self,
new_answer: NewAnswer,
)
| 124 | } |
| 125 | |
| 126 | pub async fn add_answer( |
| 127 | &self, |
| 128 | new_answer: NewAnswer, |
| 129 | ) -> Result<Answer, Error> { |
| 130 | match sqlx::query( |
| 131 | "INSERT INTO answers (content, question_id) VALUES ($1, $2)", |
| 132 | ) |
| 133 | .bind(new_answer.content) |
| 134 | .bind(new_answer.question_id.0) |
| 135 | .map(|row: PgRow| Answer { |
| 136 | id: AnswerId(row.get("id")), |
| 137 | content: row.get("content"), |
| 138 | question_id: QuestionId(row.get("question_id")), |
| 139 | }) |
| 140 | .fetch_one(&self.connection) |
| 141 | .await |
| 142 | { |
| 143 | Ok(answer) => Ok(answer), |
| 144 | Err(e) => { |
| 145 | tracing::event!(tracing::Level::ERROR, "{:?}", e); |
| 146 | Err(Error::DatabaseQueryError) |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | } |
no test coverage detected