MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / upsert_device

Function upsert_device

chirpstack/src/storage/device_profile.rs:644–662  ·  view source on GitHub ↗
(d: Device)

Source from the content-addressed store, hash-verified

642}
643
644pub 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
664pub async fn delete_device(id: uuid::Uuid) -> Result<(), Error> {
665 let ra = diesel::delete(device_profile_device::table.find(&fields::Uuid::from(id)))

Callers 4

test_device_profileFunction · 0.85
runFunction · 0.85
handle_deviceFunction · 0.85
test_device_profileFunction · 0.85

Calls 3

setMethod · 0.80
to_stringMethod · 0.80
get_async_db_connFunction · 0.70

Tested by 2

test_device_profileFunction · 0.68
test_device_profileFunction · 0.68