examples: Update to diesel-async 0.7 (#3518)

This commit is contained in:
tottoto
2025-10-06 23:58:01 +09:00
committed by GitHub
parent ac4ba7b63a
commit a847c60937
3 changed files with 123 additions and 33 deletions
+7 -2
View File
@@ -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))