feat: implement username exists for postgres via sqlx

This commit is contained in:
realaravinth 2022-05-11 13:09:37 +05:30
parent e244713ad7
commit 79cc28bfd8
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88

View file

@ -138,6 +138,24 @@ impl MCDatabase for Database {
.map_err(map_register_err)?;
Ok(())
}
/// check if username exists
async fn username_exists(&self, username: &str) -> DBResult<bool> {
let res = sqlx::query!(
"SELECT EXISTS (SELECT 1 from mcaptcha_users WHERE name = $1)",
username,
)
.fetch_one(&self.pool)
.await
.map_err(map_register_err)?;
let mut resp = false;
if let Some(x) = res.exists {
resp = x;
}
Ok(resp)
}
}
fn now_unix_time_stamp() -> i64 {