I'm not happy. It kinda sucks right now. I hope I can fix it~~~~~ But for now I must move to my laptop
58 lines
979 B
Rust
58 lines
979 B
Rust
use sqlx::{
|
|
query,
|
|
Database,
|
|
Pool,
|
|
Postgres,
|
|
pool::PoolOptions,
|
|
postgres::{
|
|
PgConnectOptions,
|
|
PgSslMode,
|
|
},
|
|
Result,
|
|
};
|
|
use std::string::ToString;
|
|
|
|
pub struct Db<Db: Database> {
|
|
pool: Pool<Db>
|
|
}
|
|
|
|
#[non_exhaustive]
|
|
enum Role {
|
|
Owner,
|
|
Participant
|
|
}
|
|
|
|
impl ToString for Role {
|
|
fn to_string(&self) -> String {
|
|
match *self {
|
|
Role::Owner => "owner".to_string(),
|
|
Role::Participant => "participant".to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct Session {
|
|
sessionuri: Uri,
|
|
label: Option<String>,
|
|
participants: Vec<Participant>,
|
|
}
|
|
|
|
impl Db<Postgres> {
|
|
async fn connect() -> Result<Self> {
|
|
let conn = PgConnectOptions::new()
|
|
.host("localhost")
|
|
.port(5432)
|
|
.username("postgres")
|
|
.password("062217")
|
|
.database("anisky")
|
|
.ssl_mode(PgSslMode::Disable);
|
|
|
|
let pool = match PoolOptions::new().connect_with(conn).await {
|
|
Ok(p) => p,
|
|
Err(e) => return Err(e),
|
|
};
|
|
|
|
Ok(Db { pool })
|
|
}
|
|
//
|
|
}
|