diff options
author | fx <[email protected]> | 2023-10-09 16:06:08 +0200 |
---|---|---|
committer | fx <[email protected]> | 2023-10-09 16:06:08 +0200 |
commit | 732c487d3dab4af9fc561527591d3d56299e39f2 (patch) | |
tree | 8c26464761f0c879a0aa7517e236af72cf87c6b2 /src/main.rs | |
parent | bc5f721de8996b48550b5069f5592caf2968e822 (diff) | |
download | webol-732c487d3dab4af9fc561527591d3d56299e39f2.tar webol-732c487d3dab4af9fc561527591d3d56299e39f2.tar.gz webol-732c487d3dab4af9fc561527591d3d56299e39f2.zip |
added db for devices
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 20 |
1 files changed, 17 insertions, 3 deletions
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 @@ | |||
1 | use std::sync::Arc; | ||
1 | use axum::{Router, routing::post}; | 2 | use axum::{Router, routing::post}; |
3 | use sqlx::SqlitePool; | ||
2 | use time::util::local_offset; | 4 | use time::util::local_offset; |
3 | use tracing::{info, level_filters::LevelFilter}; | 5 | use tracing::{debug, info, level_filters::LevelFilter}; |
4 | use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; | 6 | use tracing_subscriber::{EnvFilter, fmt::{self, time::LocalTime}, prelude::*}; |
5 | use crate::routes::start::start; | 7 | use crate::routes::start::start; |
6 | 8 | ||
@@ -8,6 +10,7 @@ mod auth; | |||
8 | mod config; | 10 | mod config; |
9 | mod routes; | 11 | mod routes; |
10 | mod wol; | 12 | mod wol; |
13 | mod db; | ||
11 | 14 | ||
12 | #[tokio::main] | 15 | #[tokio::main] |
13 | async fn main() { | 16 | async fn main() { |
@@ -27,13 +30,21 @@ async fn main() { | |||
27 | ) | 30 | ) |
28 | .init(); | 31 | .init(); |
29 | 32 | ||
33 | debug!("connecting to db"); | ||
34 | let db = SqlitePool::connect("sqlite:devices.sqlite").await.unwrap(); | ||
35 | sqlx::migrate!().run(&db).await.unwrap(); | ||
36 | info!("connected to db"); | ||
37 | |||
30 | let version = env!("CARGO_PKG_VERSION"); | 38 | let version = env!("CARGO_PKG_VERSION"); |
31 | 39 | ||
32 | info!("Starting webol v{}", version); | 40 | info!("starting webol v{}", version); |
41 | |||
42 | let shared_state = Arc::new(AppState { db }); | ||
33 | 43 | ||
34 | // build our application with a single route | 44 | // build our application with a single route |
35 | let app = Router::new() | 45 | let app = Router::new() |
36 | .route("/start", post(start)); | 46 | .route("/start", post(start)) |
47 | .with_state(shared_state); | ||
37 | 48 | ||
38 | // run it with hyper on localhost:3000 | 49 | // run it with hyper on localhost:3000 |
39 | axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) | 50 | axum::Server::bind(&"0.0.0.0:3000".parse().unwrap()) |
@@ -42,3 +53,6 @@ async fn main() { | |||
42 | .unwrap(); | 53 | .unwrap(); |
43 | } | 54 | } |
44 | 55 | ||
56 | pub struct AppState { | ||
57 | db: SqlitePool | ||
58 | } \ No newline at end of file | ||