feat: basic setup[ of the webserver

This commit is contained in:
silver 2023-05-26 00:02:12 +01:00
parent 0da50263b8
commit fe69e0cc9c
3 changed files with 122 additions and 12 deletions

44
src/lib.rs Normal file
View file

@ -0,0 +1,44 @@
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::{Error, Pool, Sqlite};
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use tide::prelude::*;
pub async fn db_init(database: &str) -> Result<Pool<Sqlite>, Error> {
let pool = SqlitePoolOptions::new()
.max_connections(5)
.connect_with(SqliteConnectOptions::from_str(&format!("sqlite://{}", database))?.create_if_missing(true))
.await?;
/*
// https://store.steampowered.com/api/appdetails?appids=1258740
sqlx::query(
"CREATE TABLE IF NOT EXISTS store_details (
id integer primary key,
name text not null,
item_type text not null,
last_timestamp integer not null
)",
)
.execute(&pool)
.await?;
*/
// set up indexes?
/*
sqlx::query("CREATE INDEX IF NOT EXISTS index_estimate ON bus_results (valid_estimate)")
.execute(&pool)
.await?;
*/
Ok(pool)
}
pub fn get_now() -> i64 {
if let Ok(x) = SystemTime::now().duration_since(UNIX_EPOCH) {
x.as_secs() as i64
} else {
0
}
}