add prototype of highscore list

This commit is contained in:
2025-08-02 19:49:35 +02:00
parent 52da18bea6
commit 24697f5ffc
3 changed files with 43 additions and 8 deletions

28
src/model/highscore.rs Normal file
View File

@@ -0,0 +1,28 @@
use crate::Backend;
pub(crate) struct Rank {
pub(crate) name: Option<String>,
pub(crate) uuid: String,
pub(crate) amount: i64,
}
impl Backend {
pub(crate) async fn highscore(&self) -> Vec<Rank> {
match self {
Backend::Sqlite(db) => sqlx::query_as!(
Rank,
"SELECT
c.name,
c.uuid,
COUNT(s.client_uuid) as amount
FROM client c
LEFT JOIN sightings s ON c.uuid = s.client_uuid
GROUP BY c.uuid, c.name
ORDER BY amount DESC"
)
.fetch_all(db)
.await
.unwrap_or_default(),
}
}
}