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

Function list_devices

chirpstack/src/storage/relay.rs:124–179  ·  view source on GitHub ↗
(
    limit: i64,
    offset: i64,
    filters: &DeviceFilters,
)

Source from the content-addressed store, hash-verified

122}
123
124pub async fn list_devices(
125 limit: i64,
126 offset: i64,
127 filters: &DeviceFilters,
128) -> Result<Vec<DeviceListItem>, Error> {
129 let q = relay_device::dsl::relay_device
130 .inner_join(device::table.on(relay_device::dsl::dev_eui.eq(device::dsl::dev_eui)))
131 .inner_join(
132 device_profile::table.on(device::dsl::device_profile_id.eq(device_profile::dsl::id)),
133 );
134
135 #[cfg(feature = "postgres")]
136 let mut q = q
137 .select((
138 relay_device::dev_eui,
139 device::join_eui,
140 device::dev_addr,
141 relay_device::created_at,
142 device::name,
143 dsl::sql::<sql_types::SmallInt>(
144 "coalesce((relay_params->'ed_uplink_limit_bucket_size')::smallint, 0::smallint)",
145 ),
146 dsl::sql::<sql_types::SmallInt>(
147 "coalesce((relay_params->'ed_uplink_limit_reload_rate')::smallint, 0::smallint)",
148 ),
149 ))
150 .into_boxed();
151
152 #[cfg(feature = "sqlite")]
153 let mut q = q
154 .select((
155 relay_device::dev_eui,
156 device::join_eui,
157 device::dev_addr,
158 relay_device::created_at,
159 device::name,
160 dsl::sql::<sql_types::SmallInt>(
161 "coalesce(relay_params->>'ed_uplink_limit_bucket_size', 0)",
162 ),
163 dsl::sql::<sql_types::SmallInt>(
164 "coalesce(relay_params->>'ed_uplink_limit_reload_rate', 0)",
165 ),
166 ))
167 .into_boxed();
168
169 if let Some(relay_dev_eui) = &filters.relay_dev_eui {
170 q = q.filter(relay_device::dsl::relay_dev_eui.eq(relay_dev_eui));
171 }
172
173 q.order_by(device::dsl::name)
174 .limit(limit)
175 .offset(offset)
176 .load(&mut get_async_db_conn().await?)
177 .await
178 .map_err(|e| Error::from_diesel(e, "".into()))
179}
180
181pub async fn add_device(relay_dev_eui: EUI64, device_dev_eui: EUI64) -> Result<(), Error> {

Callers 6

test_relayFunction · 0.70
_update_uplink_listMethod · 0.50
_update_filter_listMethod · 0.50
list_devicesMethod · 0.50
list_devicesMethod · 0.50

Calls 2

get_async_db_connFunction · 0.70
intoMethod · 0.45

Tested by 1

test_relayFunction · 0.56