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

Method add_answer

ch_10/src/store.rs:158–194  ·  view source on GitHub ↗
(
        self,
        new_answer: NewAnswer,
        account_id: AccountId,
    )

Source from the content-addressed store, hash-verified

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

Callers 1

add_answerFunction · 0.45

Calls 2

AnswerIdClass · 0.50
QuestionIdClass · 0.50

Tested by

no test coverage detected