Rocket example to use the clone interface
This commit is contained in:
parent
c80621916a
commit
aeea07c8ba
@ -156,9 +156,8 @@ pub fn not_found(req: &Request<'_>) -> Template {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
|
async fn run_migrations(rocket: Rocket<Build>) -> fairing::Result {
|
||||||
let db_url = Db::fetch(&rocket).unwrap().db_url.clone();
|
let conn = &Db::fetch(&rocket).unwrap().conn;
|
||||||
let conn = sea_orm::Database::connect(&db_url).await.unwrap();
|
let _ = setup::create_post_table(conn).await;
|
||||||
let _ = setup::create_post_table(&conn).await;
|
|
||||||
Ok(rocket)
|
Ok(rocket)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ use rocket_db_pools::{rocket::figment::Figment, Config};
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RocketDbPool {
|
pub struct RocketDbPool {
|
||||||
pub db_url: String,
|
pub conn: sea_orm::DatabaseConnection,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@ -14,14 +14,14 @@ impl rocket_db_pools::Pool for RocketDbPool {
|
|||||||
|
|
||||||
async fn init(figment: &Figment) -> Result<Self, Self::Error> {
|
async fn init(figment: &Figment) -> Result<Self, Self::Error> {
|
||||||
let config = figment.extract::<Config>().unwrap();
|
let config = figment.extract::<Config>().unwrap();
|
||||||
let db_url = config.url;
|
let conn = sea_orm::Database::connect(&config.url).await.unwrap();
|
||||||
|
|
||||||
Ok(RocketDbPool {
|
Ok(RocketDbPool {
|
||||||
db_url: db_url.to_owned(),
|
conn,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get(&self) -> Result<Self::Connection, Self::Error> {
|
async fn get(&self) -> Result<Self::Connection, Self::Error> {
|
||||||
Ok(sea_orm::Database::connect(&self.db_url).await.unwrap())
|
Ok(self.conn.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user