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