From 732c487d3dab4af9fc561527591d3d56299e39f2 Mon Sep 17 00:00:00 2001 From: fx Date: Mon, 9 Oct 2023 16:06:08 +0200 Subject: added db for devices --- src/main.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 0fe170d..761e925 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ +use std::sync::Arc; use axum::{Router, routing::post}; +use sqlx::SqlitePool; use time::util::local_offset; -use tracing::{info, level_filters::LevelFilter}; +use tracing::{debug, info, level_filters::LevelFilter}; use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; use crate::routes::start::start; @@ -8,6 +10,7 @@ mod auth; mod config; mod routes; mod wol; +mod db; #[tokio::main] async fn main() { @@ -27,13 +30,21 @@ async fn main() { ) .init(); + debug!("connecting to db"); + let db = SqlitePool::connect("sqlite:devices.sqlite").await.unwrap(); + sqlx::migrate!().run(&db).await.unwrap(); + info!("connected to db"); + let version = env!("CARGO_PKG_VERSION"); - info!("Starting webol v{}", version); + info!("starting webol v{}", version); + + let shared_state = Arc::new(AppState { db }); // build our application with a single route let app = Router::new() - .route("/start", post(start)); + .route("/start", post(start)) + .with_state(shared_state); // run it with hyper on localhost:3000 axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) @@ -42,3 +53,6 @@ async fn main() { .unwrap(); } +pub struct AppState { + db: SqlitePool +} \ No newline at end of file -- cgit v1.2.3