v0.14.1
This commit is contained in:
@@ -48,6 +48,32 @@ impl Db {
|
||||
pub fn delete_group(&self, id: &str) -> Result<bool> {
|
||||
self.delete_by_id("groups", id)
|
||||
}
|
||||
|
||||
pub fn save_device_group(&self, group: &DeviceGroup) -> Result<()> {
|
||||
let payload = Self::to_json(group)?;
|
||||
let conn = self.lock()?;
|
||||
conn.execute(
|
||||
queries::UPSERT_DEVICE_GROUP,
|
||||
params![group.id, payload, group.updated_at.to_rfc3339()],
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn list_device_groups(&self) -> Result<Vec<DeviceGroup>> {
|
||||
self.list_payloads(queries::LIST_DEVICE_GROUPS)
|
||||
}
|
||||
|
||||
pub fn get_device_group(&self, id: &str) -> Result<Option<DeviceGroup>> {
|
||||
self.get_payload(queries::GET_DEVICE_GROUP, id)
|
||||
}
|
||||
|
||||
pub fn device_group_for_device(&self, device_id: &str) -> Result<Option<DeviceGroup>> {
|
||||
Ok(self.list_device_groups()?.into_iter().find(|group| group.device_ids.iter().any(|id| id == device_id)))
|
||||
}
|
||||
|
||||
pub fn delete_device_group(&self, id: &str) -> Result<bool> {
|
||||
self.delete_by_id("device_groups", id)
|
||||
}
|
||||
}
|
||||
|
||||
impl Db {
|
||||
|
||||
Reference in New Issue
Block a user