| 43 | } |
| 44 | |
| 45 | pub async fn get_relay_count(filters: &RelayFilters) -> Result<i64, Error> { |
| 46 | let q = device::dsl::device |
| 47 | .select(dsl::count_star()) |
| 48 | .inner_join(device_profile::table); |
| 49 | |
| 50 | #[cfg(feature = "postgres")] |
| 51 | let mut q = q |
| 52 | .filter( |
| 53 | dsl::sql::<sql_types::Bool>("(relay_params->'is_relay')::boolean =") |
| 54 | .bind::<sql_types::Bool, _>(true), |
| 55 | ) |
| 56 | .into_boxed(); |
| 57 | |
| 58 | #[cfg(feature = "sqlite")] |
| 59 | let mut q = q |
| 60 | .filter( |
| 61 | dsl::sql::<sql_types::Bool>("relay_params->>'is_relay' =") |
| 62 | .bind::<sql_types::Bool, _>(true), |
| 63 | ) |
| 64 | .into_boxed(); |
| 65 | |
| 66 | if let Some(application_id) = &filters.application_id { |
| 67 | q = q.filter(device::dsl::application_id.eq(fields::Uuid::from(application_id))); |
| 68 | } |
| 69 | |
| 70 | Ok(q.first(&mut get_async_db_conn().await?).await?) |
| 71 | } |
| 72 | |
| 73 | pub async fn list_relays( |
| 74 | limit: i64, |