Fix bugs and add controller action for controller ws
This commit is contained in:
parent
8b1affd8c7
commit
6f8d63e7be
11 changed files with 177 additions and 56 deletions
emgauwa-lib/src
|
@ -172,4 +172,13 @@ impl DbController {
|
|||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn reload(
|
||||
&self,
|
||||
conn: &mut PoolConnection<Sqlite>,
|
||||
) -> Result<DbController, DatabaseError> {
|
||||
Self::get(conn, self.id)
|
||||
.await?
|
||||
.ok_or(DatabaseError::NotFound)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::str::FromStr;
|
|||
|
||||
use sqlx::migrate::Migrator;
|
||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
||||
use sqlx::{Pool, Sqlite};
|
||||
use sqlx::{ConnectOptions, Pool, Sqlite};
|
||||
|
||||
mod controllers;
|
||||
mod junction_relay_schedule;
|
||||
|
@ -30,7 +30,9 @@ pub async fn run_migrations(pool: &Pool<Sqlite>) -> Result<(), EmgauwaError> {
|
|||
}
|
||||
|
||||
pub async fn init(db: &str) -> Result<Pool<Sqlite>, EmgauwaError> {
|
||||
let options = SqliteConnectOptions::from_str(db)?.create_if_missing(true);
|
||||
let options = SqliteConnectOptions::from_str(db)?
|
||||
.create_if_missing(true)
|
||||
.log_statements(log::LevelFilter::Trace);
|
||||
|
||||
let pool: Pool<Sqlite> = SqlitePoolOptions::new()
|
||||
.acquire_timeout(std::time::Duration::from_secs(1))
|
||||
|
|
|
@ -71,7 +71,7 @@ impl DbRelay {
|
|||
conn: &mut PoolConnection<Sqlite>,
|
||||
tag: &DbTag,
|
||||
) -> Result<Vec<DbRelay>, DatabaseError> {
|
||||
sqlx::query_as!(DbRelay, "SELECT schedule.* FROM relays AS schedule INNER JOIN junction_tag ON junction_tag.schedule_id = schedule.id WHERE junction_tag.tag_id = ?", tag.id)
|
||||
sqlx::query_as!(DbRelay, "SELECT relay.* FROM relays AS relay INNER JOIN junction_tag ON junction_tag.relay_id = relay.id WHERE junction_tag.tag_id = ?", tag.id)
|
||||
.fetch_all(conn.deref_mut())
|
||||
.await
|
||||
.map_err(DatabaseError::from)
|
||||
|
|
|
@ -18,6 +18,8 @@ pub type Weekday = i64;
|
|||
#[rtype(result = "Result<(), EmgauwaError>")]
|
||||
pub enum ControllerWsAction {
|
||||
Register(Controller),
|
||||
Disconnect,
|
||||
Schedules(Vec<DbSchedule>),
|
||||
Relays(Vec<Relay>),
|
||||
Controller(Controller),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue