Fix small bugs in updating relays

This commit is contained in:
Tobias Reisinger 2023-12-05 03:12:47 +01:00
parent e2cd84b136
commit 8b1affd8c7
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
3 changed files with 15 additions and 5 deletions
emgauwa-lib/src/db

View file

@ -17,6 +17,7 @@ pub struct DbRelay {
pub controller_id: i64,
}
impl DbRelay {
pub async fn get_all(conn: &mut PoolConnection<Sqlite>) -> Result<Vec<DbRelay>, DatabaseError> {
sqlx::query_as!(DbRelay, "SELECT * FROM relays")
@ -152,4 +153,13 @@ impl DbRelay {
}
Ok(())
}
pub async fn reload(
&self,
conn: &mut PoolConnection<Sqlite>,
) -> Result<DbRelay, DatabaseError> {
Self::get(conn, self.id)
.await?
.ok_or(DatabaseError::NotFound)
}
}