This commit is contained in:
Mateusz Gruszczyński
2026-09-01 22:20:10 +02:00
parent 1cb62c8d0b
commit 16e0d94564
47 changed files with 2565 additions and 117 deletions
+38
View File
@@ -0,0 +1,38 @@
impl Db {
pub fn list_flows(&self) -> Result<Vec<Flow>> {
self.list_payloads(queries::LIST_FLOWS)
}
pub fn get_flow(&self, id: &str) -> Result<Option<Flow>> {
self.get_payload(queries::GET_FLOW, id)
}
pub fn replace_flow_outputs(&self, flow: &Flow, schedules: &[Schedule], automations: &[Automation]) -> Result<()> {
let mut conn = self.lock()?;
let tx = conn.transaction()?;
tx.execute(queries::DELETE_SCHEDULES_BY_FLOW_ID, [flow.id.as_str()])?;
tx.execute(queries::DELETE_AUTOMATIONS_BY_FLOW_ID, [flow.id.as_str()])?;
for schedule in schedules {
let payload = Self::to_json(schedule)?;
tx.execute(queries::UPSERT_SCHEDULE, params![schedule.id, schedule.zone_id, payload, schedule.updated_at.to_rfc3339()])?;
}
for item in automations {
let payload = Self::to_json(item)?;
tx.execute(queries::UPSERT_AUTOMATION, params![item.id, payload, item.updated_at.to_rfc3339()])?;
}
let payload = Self::to_json(flow)?;
tx.execute(queries::UPSERT_FLOW, params![flow.id, payload, flow.updated_at.to_rfc3339()])?;
tx.commit()?;
Ok(())
}
pub fn delete_flow(&self, id: &str) -> Result<bool> {
let mut conn = self.lock()?;
let tx = conn.transaction()?;
tx.execute(queries::DELETE_SCHEDULES_BY_FLOW_ID, [id])?;
tx.execute(queries::DELETE_AUTOMATIONS_BY_FLOW_ID, [id])?;
let changed = tx.execute(queries::DELETE_FLOW, [id])? > 0;
tx.commit()?;
Ok(changed)
}
}