mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-25 00:00:23 +02:00
examples: Update to diesel-async 0.7 (#3518)
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
//!
|
||||
//! ```sh
|
||||
//! export DATABASE_URL=postgres://localhost/your_db
|
||||
//! diesel migration run
|
||||
//! cargo run -p example-diesel-async-postgres
|
||||
//! ```
|
||||
//!
|
||||
@@ -22,11 +21,14 @@ use axum::{
|
||||
use diesel::prelude::*;
|
||||
use diesel_async::{
|
||||
pooled_connection::{bb8, AsyncDieselConnectionManager},
|
||||
AsyncPgConnection, RunQueryDsl,
|
||||
AsyncMigrationHarness, AsyncPgConnection, RunQueryDsl,
|
||||
};
|
||||
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
|
||||
use std::net::SocketAddr;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
|
||||
|
||||
// normally part of your generated schema.rs file
|
||||
table! {
|
||||
users (id) {
|
||||
@@ -68,6 +70,9 @@ async fn main() {
|
||||
let config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(db_url);
|
||||
let pool = bb8::Pool::builder().build(config).await.unwrap();
|
||||
|
||||
let mut harness = AsyncMigrationHarness::new(pool.get_owned().await.unwrap());
|
||||
harness.run_pending_migrations(MIGRATIONS).unwrap();
|
||||
|
||||
// build our application with some routes
|
||||
let app = Router::new()
|
||||
.route("/user/list", get(list_users))
|
||||
|
||||
Reference in New Issue
Block a user