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

Method add_answer

ch_08/src/store.rs:126–149  ·  view source on GitHub ↗
(
        &self,
        new_answer: NewAnswer,
    )

Source from the content-addressed store, hash-verified

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

Callers 1

add_answerFunction · 0.45

Calls 2

AnswerIdClass · 0.50
QuestionIdClass · 0.50

Tested by

no test coverage detected