Merge branch 'boat-stats' into 'staging'
add boat stats Fixes #50 Closes #50 See merge request PhilippHofer/rot!58
This commit is contained in:
@ -9,7 +9,28 @@ pub struct Stat {
|
||||
}
|
||||
|
||||
impl Stat {
|
||||
pub async fn get_rowed_km(db: &SqlitePool) -> Vec<Stat> {
|
||||
pub async fn boats(db: &SqlitePool) -> Vec<Stat> {
|
||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||
sqlx::query(
|
||||
"
|
||||
SELECT (SELECT name FROM boat WHERE id=logbook.boat_id) as name, CAST(SUM(distance_in_km) AS INTEGER) AS rowed_km
|
||||
FROM logbook
|
||||
GROUP BY boat_id
|
||||
ORDER BY rowed_km DESC;
|
||||
",
|
||||
)
|
||||
.fetch_all(db)
|
||||
.await
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|row| Stat {
|
||||
name: row.get("name"),
|
||||
rowed_km: row.get("rowed_km"),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub async fn people(db: &SqlitePool) -> Vec<Stat> {
|
||||
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
|
||||
sqlx::query(
|
||||
"
|
||||
|
Reference in New Issue
Block a user