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

Method add_answer

ch_07/src/store.rs:134–157  ·  view source on GitHub ↗
(
        &self,
        new_answer: NewAnswer,
    )

Source from the content-addressed store, hash-verified

132 }
133
134 pub async fn add_answer(
135 &self,
136 new_answer: NewAnswer,
137 ) -> Result<Answer, Error> {
138 match sqlx::query(
139 "INSERT INTO answers (content, question_id) VALUES ($1, $2)",
140 )
141 .bind(new_answer.content)
142 .bind(new_answer.question_id.0)
143 .map(|row: PgRow| Answer {
144 id: AnswerId(row.get("id")),
145 content: row.get("content"),
146 question_id: QuestionId(row.get("question_id")),
147 })
148 .fetch_one(&self.connection)
149 .await
150 {
151 Ok(answer) => Ok(answer),
152 Err(e) => {
153 tracing::event!(tracing::Level::ERROR, "{:?}", e);
154 Err(Error::DatabaseQueryError)
155 }
156 }
157 }
158}

Callers 1

add_answerFunction · 0.45

Calls 2

AnswerIdClass · 0.50
QuestionIdClass · 0.50

Tested by

no test coverage detected