Add controller to database

This commit is contained in:
Tobias Reisinger 2023-11-24 22:45:44 +01:00
parent 9f64075f5a
commit d193000aec
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
34 changed files with 1055 additions and 195 deletions
emgauwa-lib/src/db

View file

@ -6,17 +6,18 @@ use std::str::FromStr;
use crate::db::errors::DatabaseError;
use crate::db::model_utils::Period;
use crate::db::types::EmgauwaUid;
use crate::db::types::ScheduleUid;
// export for easier/flatter access
pub use crate::db::schedules::{Periods, Schedule};
pub(crate) mod errors;
pub mod errors;
mod model_utils;
mod models;
pub(crate) mod schedules;
pub(crate) mod tag;
pub mod schedules;
pub mod tag;
pub mod types;
pub mod controllers;
static MIGRATOR: Migrator = sqlx::migrate!("../migrations"); // defaults to "./migrations"
@ -27,7 +28,7 @@ pub async fn run_migrations(pool: &Pool<Sqlite>) {
async fn init_schedule(
pool: &Pool<Sqlite>,
uid: &EmgauwaUid,
uid: &ScheduleUid,
name: &str,
periods: Periods,
) -> Result<(), DatabaseError> {
@ -68,13 +69,13 @@ pub async fn init(db: &str) -> Pool<Sqlite> {
run_migrations(&pool).await;
init_schedule(&pool, &EmgauwaUid::Off, "Off", Periods(vec![]))
init_schedule(&pool, &ScheduleUid::Off, "Off", Periods(vec![]))
.await
.expect("Error initializing schedule Off");
init_schedule(
&pool,
&EmgauwaUid::On,
&ScheduleUid::On,
"On",
Periods(vec![Period::new_on()]),
)