examples: Update to diesel-async 0.6 (#3470)

This commit is contained in:
tottoto 2025-09-13 00:03:33 +09:00 committed by GitHub
parent 14f15252ee
commit 038f0966a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 14 deletions

13
Cargo.lock generated
View File

@ -1103,13 +1103,13 @@ dependencies = [
[[package]] [[package]]
name = "diesel-async" name = "diesel-async"
version = "0.5.2" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51a307ac00f7c23f526a04a77761a0519b9f0eb2838ebf5b905a58580095bdcb" checksum = "7fcc26599f590c7e5b182a05061cfb445f216bb069df72eb31f38cffde8ca598"
dependencies = [ dependencies = [
"async-trait", "bb8 0.9.0",
"bb8 0.8.6",
"diesel", "diesel",
"futures-core",
"futures-util", "futures-util",
"scoped-futures", "scoped-futures",
"tokio", "tokio",
@ -1404,7 +1404,6 @@ name = "example-diesel-async-postgres"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"axum", "axum",
"bb8 0.8.6",
"diesel", "diesel",
"diesel-async", "diesel-async",
"serde", "serde",
@ -2854,7 +2853,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"windows-targets 0.48.5", "windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -5594,7 +5593,7 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [ dependencies = [
"windows-sys 0.48.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]

View File

@ -6,9 +6,8 @@ publish = false
[dependencies] [dependencies]
axum = { path = "../../axum", features = ["macros"] } axum = { path = "../../axum", features = ["macros"] }
bb8 = "0.8"
diesel = "2" diesel = "2"
diesel-async = { version = "0.5", features = ["postgres", "bb8"] } diesel-async = { version = "0.6", features = ["postgres", "bb8"] }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.0", features = ["full"] } tokio = { version = "1.0", features = ["full"] }
tracing = "0.1" tracing = "0.1"

View File

@ -21,7 +21,8 @@ use axum::{
}; };
use diesel::prelude::*; use diesel::prelude::*;
use diesel_async::{ use diesel_async::{
pooled_connection::AsyncDieselConnectionManager, AsyncPgConnection, RunQueryDsl, pooled_connection::{bb8, AsyncDieselConnectionManager},
AsyncPgConnection, RunQueryDsl,
}; };
use std::net::SocketAddr; use std::net::SocketAddr;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
@ -49,7 +50,7 @@ struct NewUser {
hair_color: Option<String>, hair_color: Option<String>,
} }
type Pool = bb8::Pool<AsyncDieselConnectionManager<AsyncPgConnection>>; type Pool = bb8::Pool<AsyncPgConnection>;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
@ -97,9 +98,7 @@ async fn create_user(
// we can also write a custom extractor that grabs a connection from the pool // we can also write a custom extractor that grabs a connection from the pool
// which setup is appropriate depends on your application // which setup is appropriate depends on your application
struct DatabaseConnection( struct DatabaseConnection(bb8::PooledConnection<'static, AsyncPgConnection>);
bb8::PooledConnection<'static, AsyncDieselConnectionManager<AsyncPgConnection>>,
);
impl<S> FromRequestParts<S> for DatabaseConnection impl<S> FromRequestParts<S> for DatabaseConnection
where where