This commit is contained in:
philipp 2023-07-24 21:17:51 +02:00
parent 2dc70fa629
commit 290e05dc4c

View File

@ -1,5 +1,5 @@
use serde::Serialize; use serde::Serialize;
use sqlx::{Row, FromRow, SqlitePool}; use sqlx::{FromRow, Row, SqlitePool};
#[derive(FromRow, Serialize, Clone)] #[derive(FromRow, Serialize, Clone)]
pub struct Stat { pub struct Stat {
@ -9,6 +9,7 @@ pub struct Stat {
impl Stat { impl Stat {
pub async fn get_rowed_km(db: &SqlitePool) -> Vec<Stat> { pub async fn get_rowed_km(db: &SqlitePool) -> Vec<Stat> {
//TODO: switch to query! macro again (once upgraded to sqlite 3.42 on server)
sqlx::query( sqlx::query(
"SELECT u.name AS name, COALESCE(SUM(distance_in_km), 0) as rowed_km "SELECT u.name AS name, COALESCE(SUM(distance_in_km), 0) as rowed_km
FROM user u FROM user u
@ -20,7 +21,7 @@ impl Stat {
FROM logbook l FROM logbook l
INNER JOIN rower r ON r.logbook_id = l.id INNER JOIN rower r ON r.logbook_id = l.id
) AS subquery ON u.id = subquery.user_id ) AS subquery ON u.id = subquery.user_id
GROUP BY u.id ORDER BY rowed_km DESC;" GROUP BY u.id ORDER BY rowed_km DESC;",
) )
.fetch_all(db) .fetch_all(db)
.await .await