Move web code to web module

This commit is contained in:
Joscha 2023-08-05 12:58:38 +02:00
parent 3bfeb89686
commit 6d93e3bd70
4 changed files with 73 additions and 32 deletions

18
src/web/index.rs Normal file
View file

@ -0,0 +1,18 @@
use askama::Template;
use axum::{extract::State, response::IntoResponse};
use sqlx::SqlitePool;
#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate {
number: i32,
}
pub async fn get(State(db): State<SqlitePool>) -> super::Result<impl IntoResponse> {
let result = sqlx::query!("SELECT column1 AS number FROM (VALUES (1))")
.fetch_one(&db)
.await?;
let number = result.number;
Ok(IndexTemplate { number })
}