File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //! Database module
2+ //!
3+ //! ## Axum
4+ //! If you wan't to use axum the best way is to make a small wrapper around
5+ //! ConnOwned.
6+ //!
7+ //! ```rust
8+ //! pub struct ConnOwned(pub pg::db::ConnOwned);
9+ //!
10+ //! impl ConnOwned {
11+ //! pub fn conn(&self) -> Conn {
12+ //! self.0.conn()
13+ //! }
14+ //!
15+ //! pub async fn trans(&mut self) -> Result<Trans, pg::Error> {
16+ //! self.0.trans().await
17+ //! }
18+ //! }
19+ //!
20+ //! impl<S> FromRequestParts<S> for ConnOwned
21+ //! where
22+ //! S: Send + Sync,
23+ //! Db: FromRef<S>,
24+ //! {
25+ //! type Rejection = Error;
26+ //!
27+ //! async fn from_request_parts(
28+ //! _parts: &mut Parts,
29+ //! state: &S,
30+ //! ) -> Result<Self, Self::Rejection> {
31+ //! let db = Db::from_ref(state);
32+ //! db.get()
33+ //! .await
34+ //! .map(Self)
35+ //! .map_err(|e| Error::Internal(e.to_string()))
36+ //! }
37+ //! }
38+ //! ```
39+
140use crate :: {
241 Connection , Database , Error ,
342 connection:: { ConnectionOwned , Transaction } ,
@@ -49,7 +88,6 @@ impl ConnOwned {
4988 }
5089
5190 // or transaction
52- #[ allow( dead_code) ]
5391 pub async fn trans ( & mut self ) -> Result < Trans , Error > {
5492 match & mut self . pg {
5593 Some ( pg) => Ok ( Trans {
You can’t perform that action at this time.
0 commit comments