add prototype of highscore list
This commit is contained in:
28
src/model/highscore.rs
Normal file
28
src/model/highscore.rs
Normal 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(),
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user