(
&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( |
| 62 | "INSERT INTO questions (title, content, tags) |
| 63 | VALUES ($1, $2, $3) |
| 64 | RETURNING id, title, content, tags", |
| 65 | ) |
| 66 | .bind(new_question.title) |
| 67 | .bind(new_question.content) |
| 68 | .bind(new_question.tags) |
| 69 | .map(|row: PgRow| Question { |
| 70 | id: QuestionId(row.get("id")), |
| 71 | title: row.get("title"), |
| 72 | content: row.get("content"), |
| 73 | tags: row.get("tags"), |
| 74 | }) |
| 75 | .fetch_one(&self.connection) |
| 76 | .await |
| 77 | { |
| 78 | Ok(question) => Ok(question), |
| 79 | Err(e) => { |
| 80 | tracing::event!(tracing::Level::ERROR, "{:?}", e); |
| 81 | Err(Error::DatabaseQueryError) |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | pub async fn update_question( |
| 87 | &self, |
no test coverage detected