feat: stuff

This commit is contained in:
DJMrTV 2025-02-27 21:49:37 +01:00
commit 6d58fd47a1
11 changed files with 244 additions and 366 deletions

View file

@ -0,0 +1,29 @@
use crate::Pool;
pub async fn next_pid(pool: &Pool) -> i32{
loop {
let next_pid = sqlx::query!("SELECT nextval('pid_counter') as pid")
.fetch_one(pool)
.await
.expect("unable to get next pid")
.pid
.expect("unable to get next pid") as i32;
let already_exists = sqlx::query!(
"SELECT EXISTS(select 1 from users where pid = $1)",
next_pid
).fetch_one(pool)
.await
.ok()
.map(|v| v.exists)
.flatten()
.unwrap_or(true);
if !already_exists{
break next_pid;
}
}
}