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

Method update_question

ch_08/src/store.rs:81–110  ·  view source on GitHub ↗
(
        self,
        question: Question,
        id: i32,
    )

Source from the content-addressed store, hash-verified

79 }
80
81 pub async fn update_question(
82 self,
83 question: Question,
84 id: i32,
85 ) -> Result<Question, Error> {
86 match sqlx::query(
87 "UPDATE questions SET title = $1, content = $2, tags = $3
88 WHERE id = $4
89 RETURNING id, title, content, tags",
90 )
91 .bind(question.title)
92 .bind(question.content)
93 .bind(question.tags)
94 .bind(id)
95 .map(|row: PgRow| Question {
96 id: QuestionId(row.get("id")),
97 title: row.get("title"),
98 content: row.get("content"),
99 tags: row.get("tags"),
100 })
101 .fetch_one(&self.connection)
102 .await
103 {
104 Ok(question) => Ok(question),
105 Err(e) => {
106 tracing::event!(tracing::Level::ERROR, "{:?}", e);
107 Err(Error::DatabaseQueryError)
108 }
109 }
110 }
111
112 pub async fn delete_question(self, id: i32) -> Result<bool, Error> {
113 match sqlx::query("DELETE FROM questions WHERE id = $1")

Callers 1

update_questionFunction · 0.45

Calls 1

QuestionIdClass · 0.50

Tested by

no test coverage detected