Skip to content

Commit a847c60

Browse files
authored
examples: Update to diesel-async 0.7 (#3518)
1 parent ac4ba7b commit a847c60

File tree

3 files changed

+122
-32
lines changed

3 files changed

+122
-32
lines changed

Cargo.lock

Lines changed: 112 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/diesel-async-postgres/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ publish = false
66

77
[dependencies]
88
axum = { path = "../../axum", features = ["macros"] }
9-
diesel = "2"
10-
diesel-async = { version = "0.6", features = ["postgres", "bb8"] }
9+
diesel = "~2.3"
10+
diesel-async = { version = "0.7", features = ["postgres", "bb8", "migrations"] }
11+
diesel_migrations = "~2.3"
1112
serde = { version = "1.0", features = ["derive"] }
1213
tokio = { version = "1.0", features = ["full"] }
1314
tracing = "0.1"

examples/diesel-async-postgres/src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! ```sh
44
//! export DATABASE_URL=postgres://localhost/your_db
5-
//! diesel migration run
65
//! cargo run -p example-diesel-async-postgres
76
//! ```
87
//!
@@ -22,11 +21,14 @@ use axum::{
2221
use diesel::prelude::*;
2322
use diesel_async::{
2423
pooled_connection::{bb8, AsyncDieselConnectionManager},
25-
AsyncPgConnection, RunQueryDsl,
24+
AsyncMigrationHarness, AsyncPgConnection, RunQueryDsl,
2625
};
26+
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
2727
use std::net::SocketAddr;
2828
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
2929

30+
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
31+
3032
// normally part of your generated schema.rs file
3133
table! {
3234
users (id) {
@@ -68,6 +70,9 @@ async fn main() {
6870
let config = AsyncDieselConnectionManager::<diesel_async::AsyncPgConnection>::new(db_url);
6971
let pool = bb8::Pool::builder().build(config).await.unwrap();
7072

73+
let mut harness = AsyncMigrationHarness::new(pool.get_owned().await.unwrap());
74+
harness.run_pending_migrations(MIGRATIONS).unwrap();
75+
7176
// build our application with some routes
7277
let app = Router::new()
7378
.route("/user/list", get(list_users))

0 commit comments

Comments
 (0)