Dohman
Dohman
Explore posts from servers
SShuttle
Created by Dohman on 6/28/2023 in #help
Issues with accessing console
15 replies
SShuttle
Created by Dohman on 5/25/2023 in #help
Integrating Diesel into Rocket 0.5
@womble73 I created a very basic shuttle instance based off the documentation. I have been distracted on another project, but I really struggled to understand how I would integrate diesel into the mix as Rocket 0.5 has moved over to using stages as preferred methods of loading databases etc. So in my example the stage for loading postgres looks like this:
use rocket::{fairing::AdHoc, Rocket, Build};

use rocket_sync_db_pools::diesel;
use crate::diesel_migrations::{MigrationHarness, EmbeddedMigrations};

const MIGRATIONS: EmbeddedMigrations = embed_migrations!("db/migrations");

#[database("db")]
pub struct Db(diesel::PgConnection);

async fn run_migrations(rocket: Rocket<Build>) -> Rocket<Build> {
let conn = Db::get_one(&rocket).await.expect("database connection");
conn.run(|c| { c.run_pending_migrations(MIGRATIONS).unwrap(); }).await;
rocket
}

pub(crate) fn stage() -> AdHoc {
AdHoc::on_ignite("Diesel Postgres Stage", |rocket| async {
rocket.attach(Db::fairing())
.attach(AdHoc::on_ignite("Diesel Migrations", run_migrations))
})
}
use rocket::{fairing::AdHoc, Rocket, Build};

use rocket_sync_db_pools::diesel;
use crate::diesel_migrations::{MigrationHarness, EmbeddedMigrations};

const MIGRATIONS: EmbeddedMigrations = embed_migrations!("db/migrations");

#[database("db")]
pub struct Db(diesel::PgConnection);

async fn run_migrations(rocket: Rocket<Build>) -> Rocket<Build> {
let conn = Db::get_one(&rocket).await.expect("database connection");
conn.run(|c| { c.run_pending_migrations(MIGRATIONS).unwrap(); }).await;
rocket
}

pub(crate) fn stage() -> AdHoc {
AdHoc::on_ignite("Diesel Postgres Stage", |rocket| async {
rocket.attach(Db::fairing())
.attach(AdHoc::on_ignite("Diesel Migrations", run_migrations))
})
}
4 replies