(
self,
new_question: NewQuestion,
)
| 55 | } |
| 56 | |
| 57 | pub async fn add_question( |
| 58 | self, |
| 59 | new_question: NewQuestion, |
| 60 | ) -> Result<Question, Error> { |
| 61 | match sqlx::query("INSERT INTO questions (title, content, tags) VALUES ($1, $2, $3) RETURNING id, title, content, tags") |
| 62 | .bind(new_question.title) |
| 63 | .bind(new_question.content) |
| 64 | .bind(new_question.tags) |
| 65 | .map(|row: PgRow| Question { |
| 66 | id: QuestionId(row.get("id")), |
| 67 | title: row.get("title"), |
| 68 | content: row.get("content"), |
| 69 | tags: row.get("tags"), |
| 70 | }) |
| 71 | .fetch_one(&self.connection) |
| 72 | .await { |
| 73 | Ok(question) => Ok(question), |
| 74 | Err(e) => { |
| 75 | tracing::event!(tracing::Level::ERROR, "{:?}", e); |
| 76 | Err(Error::DatabaseQueryError) |
| 77 | }, |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | pub async fn update_question( |
| 82 | self, |
no test coverage detected