Library to Provide a Postgresql Session management layer. You must also include Tower_cookies in order to use this Library.
```
pub fn initpool(config: &ServerConfig) -> anyhow::Result
let pool = block_on(
PgPoolOptions::new()
.max_connections(5)
.connect_with(connect_opts),
)?;
Ok(pool)
}
async fn main() { // Set the RUSTLOG, if it hasn't been explicitly defined if std::env::varos("RUSTLOG").isnone() { std::env::setvar("RUSTLOG", "exampletemplates=debug,towerhttp=debug") } tracing_subscriber::fmt::init();
let config = //load your config here.
let poll = init_pool(&config).unwrap();
let session_config = SqlxSessionConfig::default()
.with_database("test")
.with_table_name("test_table");
// build our application with some routes
let app = Router::new()
.route("/greet/:name", get(greet))
.layer(tower_cookies::CookieManagerLayer::new())
.layer(SqlxSessionLayer::new(session_config, poll.clone()))
// run it
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}
async fn greet(session: SQLxSession) -> &'static str { let mut count: usize = session.get("count").unwrap_or(0); count += 1; session.set("count", count);
count.to_string()[..]
}
```