MCPcopy Create free account
hub / github.com/Rust-Web-Development/code / add_question

Method add_question

ch_08/src/store.rs:57–79  ·  view source on GitHub ↗
(
        self,
        new_question: NewQuestion,
    )

Source from the content-addressed store, hash-verified

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,

Callers 1

add_questionFunction · 0.45

Calls 1

QuestionIdClass · 0.50

Tested by

no test coverage detected