Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade axum to 0.8 #49

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "axum-sqlx-tx"
description = "Request-scoped SQLx transactions for axum"
version = "0.9.0"
version = "0.10.0"
license = "MIT"
repository = "https://github.com/digital-society-coop/axum-sqlx-tx/"
edition = "2021"
Expand All @@ -13,7 +13,7 @@ include = [
]

[dependencies]
axum-core = "0.4"
axum-core = "0.5"
bytes = "1"
futures-core = "0.3"
http = "1"
Expand All @@ -25,8 +25,8 @@ tower-layer = "0.3"
tower-service = "0.3"

[dev-dependencies]
axum = "0.7.2"
axum = "0.8.1"
hyper = "1.0.1"
sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite"] }
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tower = "0.4.12"
tower = "0.5.2"
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
/// # .route("/", post(create_user))
/// # .layer(layer)
/// # .with_state(state);
/// # axum::serve(todo!(), app);
/// # let listener: tokio::net::TcpListener = todo!();
/// # axum::serve(listener, app);
/// # }
/// # async fn create_user(mut tx: Tx, /* ... */) {
/// # /* ... */
Expand Down
5 changes: 4 additions & 1 deletion src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ where

#[cfg(test)]
mod tests {
use tokio::net::TcpListener;

use crate::{Error, State};

use super::Layer;
Expand All @@ -146,6 +148,7 @@ mod tests {
.route("/", axum::routing::get(|| async { "hello" }))
.layer(layer);

axum::serve(todo!(), app);
let listener: TcpListener = todo!();
axum::serve(listener, app);
}
}
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
//! # .route("/", axum::routing::get(|tx: Tx| async move {}))
//! .layer(layer)
//! .with_state(state);
//! # axum::serve(todo!(), app);
//! # let listener: tokio::net::TcpListener = todo!();
//! # axum::serve(listener, app);
//! # }
//! ```
//!
Expand Down
3 changes: 2 additions & 1 deletion src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ use std::fmt::Debug;
/// .layer(layer1)
/// .layer(layer2)
/// .with_state(MyState { state1, state2 });
/// # axum::serve(todo!(), app);
/// # let listener: tokio::net::TcpListener = todo!();
/// # axum::serve(listener, app);
/// # }
/// ```
pub trait Marker: Debug + Send + Sized + 'static {
Expand Down
25 changes: 8 additions & 17 deletions src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,20 @@ impl<DB: Marker, E> std::ops::DerefMut for Tx<DB, E> {

impl<DB: Marker, S, E> FromRequestParts<S> for Tx<DB, E>
where
E: From<Error> + IntoResponse,
S: Sync,
E: From<Error> + IntoResponse + Send,
State<DB>: FromRef<S>,
{
type Rejection = E;

fn from_request_parts<'req, 'state, 'ctx>(
parts: &'req mut Parts,
_state: &'state S,
) -> futures_core::future::BoxFuture<'ctx, Result<Self, Self::Rejection>>
where
Self: 'ctx,
'req: 'ctx,
'state: 'ctx,
{
Box::pin(async move {
let ext: &Extension<DB> = parts.extensions.get().ok_or(Error::MissingExtension)?;
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
let ext: &Extension<DB> = parts.extensions.get().ok_or(Error::MissingExtension)?;

let tx = ext.acquire().await?;
let tx = ext.acquire().await?;

Ok(Self {
tx,
_error: PhantomData,
})
Ok(Self {
tx,
_error: PhantomData,
})
}
}
Expand Down
Loading