corund_lib/
db.rs

1use crate::{ryz::res::Res, APPRC};
2use diesel::{connection::SimpleConnection, Connection, PgConnection};
3
4pub type Con = PgConnection;
5
6pub type Id = i32;
7#[allow(dead_code)]
8pub type Sid = String;
9
10pub fn con() -> Res<PgConnection> {
11    let cfg = &APPRC.sql;
12    Ok(PgConnection::establish(&cfg.url)
13        .unwrap_or_else(|_| panic!("cannot connect to db")))
14}
15
16pub fn truncate_tables_if_allowed() {
17    if !APPRC.sql.is_cleaning_allowed {
18        return;
19    }
20    let con = &mut con().unwrap();
21    con.batch_execute(
22        "
23        TRUNCATE user_change, appuser RESTART IDENTITY;
24    ",
25    )
26    .unwrap();
27}