feat: stuff
This commit is contained in:
parent
2e2b01990e
commit
6d58fd47a1
11 changed files with 244 additions and 366 deletions
29
src/nnid/pid_distribution.rs
Normal file
29
src/nnid/pid_distribution.rs
Normal 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue