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

Method add_question

ch_07/src/store.rs:57–84  ·  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(
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,

Callers 1

add_questionFunction · 0.45

Calls 1

QuestionIdClass · 0.50

Tested by

no test coverage detected