25 lines
529 B
Rust
25 lines
529 B
Rust
use anyhow::Result;
|
|
use sqlx::{Pool, Postgres, postgres::PgPoolOptions};
|
|
|
|
pub mod auth;
|
|
pub mod tables;
|
|
pub type CurrDb = Postgres;
|
|
pub type CurrPool = Pool<CurrDb>;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Database {
|
|
pool: CurrPool,
|
|
}
|
|
|
|
impl Database {
|
|
pub async fn connect() -> Result<Self> {
|
|
let url = "postgres://postgres:postgres@127.0.0.1:5432/persmgr";
|
|
let pool = PgPoolOptions::new().connect(url).await?;
|
|
Ok(Self { pool })
|
|
}
|
|
|
|
pub fn pool(&self) -> &CurrPool {
|
|
&self.pool
|
|
}
|
|
}
|