| 177 | } |
| 178 | |
| 179 | pub async fn add_account(self, account: Account) -> Result<bool, Error> { |
| 180 | match sqlx::query("INSERT INTO accounts (email, password) VALUES ($1, $2)") |
| 181 | .bind(account.email) |
| 182 | .bind(account.password) |
| 183 | .execute(&self.connection) |
| 184 | .await |
| 185 | { |
| 186 | Ok(_) => Ok(true), |
| 187 | Err(error) => { |
| 188 | tracing::event!( |
| 189 | tracing::Level::ERROR, |
| 190 | code = error |
| 191 | .as_database_error() |
| 192 | .unwrap() |
| 193 | .code() |
| 194 | .unwrap() |
| 195 | .parse::<i32>() |
| 196 | .unwrap(), |
| 197 | db_message = error.as_database_error().unwrap().message(), |
| 198 | constraint = error.as_database_error().unwrap().constraint().unwrap() |
| 199 | ); |
| 200 | Err(Error::DatabaseQueryError(error)) |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | pub async fn get_account(self, email: String) -> Result<Account, Error> { |
| 206 | match sqlx::query("SELECT * from accounts where email = $1") |