use function (instead of macro) to work with older sqlite

This commit is contained in:
Philipp 2023-07-24 21:16:43 +02:00
parent b3dd1cdfe5
commit 2dc70fa629

View File

@ -1,5 +1,5 @@
use serde::Serialize; use serde::Serialize;
use sqlx::{FromRow, SqlitePool}; use sqlx::{Row, FromRow, SqlitePool};
#[derive(FromRow, Serialize, Clone)] #[derive(FromRow, Serialize, Clone)]
pub struct Stat { pub struct Stat {
@ -9,7 +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> {
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
INNER JOIN ( INNER JOIN (
@ -27,8 +27,8 @@ impl Stat {
.unwrap() .unwrap()
.into_iter() .into_iter()
.map(|row| Stat { .map(|row| Stat {
name: row.name, name: row.get("name"),
rowed_km: row.rowed_km.unwrap_or(0), rowed_km: row.get("rowed_km"),
}) })
.collect() .collect()
} }