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

Method add_answer

ch_09/src/store.rs:161–197  ·  view source on GitHub ↗
(
        self,
        new_answer: NewAnswer,
        account_id: AccountId,
    )

Source from the content-addressed store, hash-verified

159 }
160
161 pub async fn add_answer(
162 self,
163 new_answer: NewAnswer,
164 account_id: AccountId,
165 ) -> Result<Answer, Error> {
166 match sqlx::query(
167 "INSERT INTO answers (content, corresponding_question, account_id) VALUES ($1, $2, $3)",
168 )
169 .bind(new_answer.content)
170 .bind(new_answer.question_id.0)
171 .bind(account_id.0)
172 .map(|row: PgRow| Answer {
173 id: AnswerId(row.get("id")),
174 content: row.get("content"),
175 question_id: QuestionId(row.get("question_id")),
176 })
177 .fetch_one(&self.connection)
178 .await
179 {
180 Ok(answer) => Ok(answer),
181 Err(error) => {
182 tracing::event!(
183 tracing::Level::ERROR,
184 code = error
185 .as_database_error()
186 .unwrap()
187 .code()
188 .unwrap()
189 .parse::<i32>()
190 .unwrap(),
191 db_message = error.as_database_error().unwrap().message(),
192 constraint = error.as_database_error().unwrap().constraint().unwrap()
193 );
194 Err(Error::DatabaseQueryError(error))
195 }
196 }
197 }
198
199 pub async fn add_account(
200 self,

Callers 1

add_answerFunction · 0.45

Calls 2

AnswerIdClass · 0.50
QuestionIdClass · 0.50

Tested by

no test coverage detected