mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-03-29 04:38:59 +03:00
feat: implement username exists for postgres via sqlx
This commit is contained in:
parent
e244713ad7
commit
79cc28bfd8
1 changed files with 18 additions and 0 deletions
|
@ -138,6 +138,24 @@ impl MCDatabase for Database {
|
||||||
.map_err(map_register_err)?;
|
.map_err(map_register_err)?;
|
||||||
Ok(())
|
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 {
|
fn now_unix_time_stamp() -> i64 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue