| 642 | } |
| 643 | |
| 644 | pub async fn upsert_device(d: Device) -> Result<Device, Error> { |
| 645 | let d: Device = diesel::insert_into(device_profile_device::table) |
| 646 | .values(&d) |
| 647 | .on_conflict(device_profile_device::id) |
| 648 | .do_update() |
| 649 | .set(( |
| 650 | device_profile_device::updated_at.eq(Utc::now()), |
| 651 | device_profile_device::name.eq(&d.name), |
| 652 | device_profile_device::description.eq(&d.name), |
| 653 | device_profile_device::metadata.eq(&d.metadata), |
| 654 | )) |
| 655 | .get_result(&mut get_async_db_conn().await?) |
| 656 | .await |
| 657 | .map_err(|e| Error::from_diesel(e, d.id.to_string()))?; |
| 658 | |
| 659 | info!(id = %d.id, "Device-profile device upserted"); |
| 660 | |
| 661 | Ok(d) |
| 662 | } |
| 663 | |
| 664 | pub async fn delete_device(id: uuid::Uuid) -> Result<(), Error> { |
| 665 | let ra = diesel::delete(device_profile_device::table.find(&fields::Uuid::from(id))) |