28 lines
758 B
Rust
28 lines
758 B
Rust
use rocket::async_trait;
|
|
use rocket_db_pools::{rocket::figment::Figment, Config, Database};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct InstDbConn {
|
|
pub conn: sea_orm::DatabaseConnection,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl rocket_db_pools::Pool for InstDbConn {
|
|
type Error = sea_orm::DbErr;
|
|
type Connection = sea_orm::DatabaseConnection;
|
|
|
|
async fn init(figment: &Figment) -> Result<Self, Self::Error> {
|
|
let config = figment.extract::<Config>().unwrap();
|
|
let conn = sea_orm::Database::connect(&config.url).await.unwrap();
|
|
Ok(Self { conn })
|
|
}
|
|
|
|
async fn get(&self) -> Result<Self::Connection, Self::Error> {
|
|
Ok(self.conn.clone())
|
|
}
|
|
}
|
|
|
|
#[derive(Database, Debug)]
|
|
#[database("instances")]
|
|
pub struct Instances(InstDbConn);
|