mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-26 00:00:23 +02:00
examples: Update to diesel-async 0.7 (#3518)
This commit is contained in:
@@ -6,8 +6,9 @@ publish = false
|
||||
|
||||
[dependencies]
|
||||
axum = { path = "../../axum", features = ["macros"] }
|
||||
diesel = "2"
|
||||
diesel-async = { version = "0.6", features = ["postgres", "bb8"] }
|
||||
diesel = "~2.3"
|
||||
diesel-async = { version = "0.7", features = ["postgres", "bb8", "migrations"] }
|
||||
diesel_migrations = "~2.3"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
tracing = "0.1"
|
||||
|
||||
@@ -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