generated from alecodes/base-template
feat: add sqlx transaction extractor to router
This commit is contained in:
parent
cfaf7ecc1f
commit
a662b94b21
8 changed files with 79 additions and 14 deletions
|
|
@ -1,12 +1,13 @@
|
|||
mod error;
|
||||
pub mod router;
|
||||
|
||||
use axum::extract::FromRef;
|
||||
pub use error::{Error, Result, ResultTemplate};
|
||||
use minijinja::{Environment, Template};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub type Tx = axum_sqlx_tx::Tx<sqlx::Postgres>;
|
||||
pub type TxState = axum_sqlx_tx::State<sqlx::Postgres>;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Link {
|
||||
|
|
@ -15,13 +16,15 @@ pub struct Link {
|
|||
pub subpages: Vec<Self>,
|
||||
}
|
||||
|
||||
#[derive(Clone, FromRef)]
|
||||
pub struct AppState {
|
||||
tmpl_env: Environment<'static>,
|
||||
tx: TxState,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(tmpl_env: Environment<'static>) -> Arc<Self> {
|
||||
Arc::new(AppState { tmpl_env })
|
||||
pub fn new(tmpl_env: Environment<'static>, tx: TxState) -> Self {
|
||||
AppState { tmpl_env, tx }
|
||||
}
|
||||
|
||||
pub fn get_template(&self, name: &str) -> Result<Template> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue