Rename ControllerUid to a more general EmgauwaUid (for macros)

This commit is contained in:
Tobias Reisinger 2024-04-28 02:29:34 +02:00
parent 07d3322c5a
commit 51aa0d3c99
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
11 changed files with 55 additions and 57 deletions
emgauwa-lib/src/db

View file

@ -6,14 +6,14 @@ use sqlx::Sqlite;
use crate::db::{DbRelay, DbTag};
use crate::errors::DatabaseError;
use crate::types::ControllerUid;
use crate::types::EmgauwaUid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DbController {
#[serde(skip)]
pub id: i64,
#[serde(rename = "id")]
pub uid: ControllerUid,
pub uid: EmgauwaUid,
pub name: String,
pub relay_count: i64,
pub active: bool,
@ -41,7 +41,7 @@ impl DbController {
pub async fn get_by_uid(
conn: &mut PoolConnection<Sqlite>,
filter_uid: &ControllerUid,
filter_uid: &EmgauwaUid,
) -> Result<Option<DbController>, DatabaseError> {
sqlx::query_as!(
DbController,
@ -55,7 +55,7 @@ impl DbController {
pub async fn get_by_uid_or_create(
conn: &mut PoolConnection<Sqlite>,
uid: &ControllerUid,
uid: &EmgauwaUid,
new_name: &str,
new_relay_count: i64,
) -> Result<DbController, DatabaseError> {
@ -77,7 +77,7 @@ impl DbController {
pub async fn delete_by_uid(
conn: &mut PoolConnection<Sqlite>,
filter_uid: ControllerUid,
filter_uid: EmgauwaUid,
) -> Result<(), DatabaseError> {
if sqlx::query_scalar!("SELECT 1 FROM controllers WHERE uid = ?", filter_uid)
.fetch_optional(conn.deref_mut())
@ -98,7 +98,7 @@ impl DbController {
pub async fn create(
conn: &mut PoolConnection<Sqlite>,
new_uid: &ControllerUid,
new_uid: &EmgauwaUid,
new_name: &str,
new_relay_count: i64,
) -> Result<DbController, DatabaseError> {