feat: impl def_email for sqlx postgres

This commit is contained in:
realaravinth 2022-05-26 20:35:38 +05:30
parent 6e45c643b1
commit 38d518d843
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88

View file

@ -155,6 +155,23 @@ impl MCDatabase for Database {
Ok(resp)
}
/// get user email
async fn get_email(&self, username: &str) -> DBResult<Option<String>> {
struct Email {
email: Option<String>,
}
let res = sqlx::query_as!(
Email,
"SELECT email FROM mcaptcha_users WHERE name = $1",
username
)
.fetch_one(&self.pool)
.await
.map_err(|e| map_row_not_found_err(e, DBError::AccountNotFound))?;
Ok(res.email)
}
/// check if email exists
async fn email_exists(&self, email: &str) -> DBResult<bool> {
let res = sqlx::query!(