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

Method add_question

ch_09/src/store.rs:81–105  ·  view source on GitHub ↗
(
        self,
        new_question: NewQuestion,
        account_id: AccountId,
    )

Source from the content-addressed store, hash-verified

79 }
80
81 pub async fn add_question(
82 self,
83 new_question: NewQuestion,
84 account_id: AccountId,
85 ) -> Result<Question, Error> {
86 match sqlx::query("INSERT INTO questions (title, content, tags, account_id) VALUES ($1, $2, $3, $4) RETURNING id, title, content, tags")
87 .bind(new_question.title)
88 .bind(new_question.content)
89 .bind(new_question.tags)
90 .bind(account_id.0)
91 .map(|row: PgRow| Question {
92 id: QuestionId(row.get("id")),
93 title: row.get("title"),
94 content: row.get("content"),
95 tags: row.get("tags"),
96 })
97 .fetch_one(&self.connection)
98 .await {
99 Ok(question) => Ok(question),
100 Err(error) => {
101 tracing::event!(tracing::Level::ERROR, "{:?}", error);
102 Err(Error::DatabaseQueryError(error))
103 },
104 }
105 }
106
107 pub async fn update_question(
108 self,

Callers 1

add_questionFunction · 0.45

Calls 1

QuestionIdClass · 0.50

Tested by

no test coverage detected