Skip to content

Commit ca316d8

Browse files
authored
Merge pull request #17 from wasdacraic/upgrade-axum
Upgrade `axum` to 0.6
2 parents e98b009 + 302717b commit ca316d8

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

Cargo.toml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "axum-sqlx-tx"
33
description = "Request-scoped SQLx transactions for axum"
4-
version = "0.4.1"
4+
version = "0.5.0"
55
license = "MIT"
66
repository = "https://github.com/wasdacraic/axum-sqlx-tx/"
77
edition = "2021"
@@ -27,20 +27,20 @@ runtime-tokio-rustls = ["sqlx/runtime-tokio-rustls"]
2727
features = ["all-databases", "runtime-tokio-rustls"]
2828

2929
[dependencies]
30-
axum-core = "0.2.1"
31-
bytes = "1.1.0"
32-
futures-core = "0.3.21"
33-
http = "0.2.6"
34-
http-body = "0.4.4"
35-
parking_lot = "0.12.0"
30+
axum-core = "0.3"
31+
bytes = "1"
32+
futures-core = "0.3"
33+
http = "0.2"
34+
http-body = "0.4"
35+
parking_lot = "0.12"
3636
sqlx = { version = "0.6", default-features = false }
37-
thiserror = "1.0.30"
38-
tower-layer = "0.3.1"
39-
tower-service = "0.3.1"
37+
thiserror = "1"
38+
tower-layer = "0.3"
39+
tower-service = "0.3"
4040

4141
[dev-dependencies]
4242
axum-sqlx-tx = { path = ".", features = ["runtime-tokio-rustls", "sqlite"] }
43-
axum = "0.5.1"
43+
axum = "0.6.4"
4444
hyper = "0.14.17"
4545
tempfile = "3.3.0"
4646
tokio = { version = "1.17.0", features = ["macros"] }

src/layer.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ impl<DB: sqlx::Database> Layer<DB> {
5353
}
5454
}
5555

56+
impl<DB: sqlx::Database, E> Clone for Layer<DB, E> {
57+
fn clone(&self) -> Self {
58+
Self {
59+
pool: self.pool.clone(),
60+
_error: self._error,
61+
}
62+
}
63+
}
64+
5665
impl<DB: sqlx::Database, S, E> tower_layer::Layer<S> for Layer<DB, E> {
5766
type Service = Service<DB, S, E>;
5867

src/tx.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
33
use std::marker::PhantomData;
44

5-
use axum_core::{
6-
extract::{FromRequest, RequestParts},
7-
response::IntoResponse,
8-
};
5+
use axum_core::{extract::FromRequestParts, response::IntoResponse};
6+
use http::request::Parts;
97
use sqlx::Transaction;
108

119
use crate::{
@@ -114,25 +112,23 @@ impl<DB: sqlx::Database, E> std::ops::DerefMut for Tx<DB, E> {
114112
}
115113
}
116114

117-
impl<DB: sqlx::Database, B, E> FromRequest<B> for Tx<DB, E>
115+
impl<DB: sqlx::Database, S, E> FromRequestParts<S> for Tx<DB, E>
118116
where
119-
B: Send,
120117
E: From<Error> + IntoResponse,
121118
{
122119
type Rejection = E;
123120

124-
fn from_request<'req, 'ctx>(
125-
req: &'req mut RequestParts<B>,
121+
fn from_request_parts<'req, 'state, 'ctx>(
122+
parts: &'req mut Parts,
123+
_state: &'state S,
126124
) -> futures_core::future::BoxFuture<'ctx, Result<Self, Self::Rejection>>
127125
where
128-
'req: 'ctx,
129126
Self: 'ctx,
127+
'req: 'ctx,
128+
'state: 'ctx,
130129
{
131130
Box::pin(async move {
132-
let ext: &mut Lazy<DB> = req
133-
.extensions_mut()
134-
.get_mut()
135-
.ok_or(Error::MissingExtension)?;
131+
let ext: &mut Lazy<DB> = parts.extensions.get_mut().ok_or(Error::MissingExtension)?;
136132

137133
let tx = ext.get_or_begin().await?;
138134

tests/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ struct Response {
188188

189189
async fn build_app<H, T>(handler: H) -> (NamedTempFile, sqlx::SqlitePool, Response)
190190
where
191-
H: axum::handler::Handler<T, axum::body::Body>,
191+
H: axum::handler::Handler<T, (), axum::body::Body>,
192192
T: 'static,
193193
{
194194
let db = NamedTempFile::new().unwrap();

0 commit comments

Comments
 (0)