Now all stats can be fetched...
This commit is contained in:
parent
f25ff85276
commit
34b35e0795
|
@ -7,7 +7,7 @@ use crate::database::DatabaseHandler;
|
|||
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
|
||||
pub struct Map {
|
||||
pub map: String,
|
||||
pub mapper: String,
|
||||
pub mappers: Vec<String>,
|
||||
pub category: String,
|
||||
pub points: i16,
|
||||
pub stars: i16,
|
||||
|
@ -22,7 +22,7 @@ impl Map {
|
|||
sqlx::query_as!(
|
||||
Map,
|
||||
"
|
||||
SELECT record_maps.map, category, points, stars, mapper, release, width, height,
|
||||
SELECT record_maps.map, category, points, stars, mappers, release, width, height,
|
||||
string_to_array(CONCAT_WS(',',
|
||||
CASE WHEN DEATH = '1' THEN 'DEATH' END,
|
||||
CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
|
||||
|
@ -75,7 +75,7 @@ impl Map {
|
|||
sqlx::query_as!(
|
||||
Map,
|
||||
"
|
||||
SELECT record_maps.map, category, points, stars, mapper, release, width, height,
|
||||
SELECT record_maps.map, category, points, stars, mappers, release, width, height,
|
||||
string_to_array(CONCAT_WS(',',
|
||||
CASE WHEN DEATH = '1' THEN 'DEATH' END,
|
||||
CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
|
||||
|
@ -133,7 +133,7 @@ impl Map {
|
|||
sqlx::query_as!(
|
||||
Map,
|
||||
"
|
||||
SELECT record_maps.map, category, points, stars, mapper, release, width, height,
|
||||
SELECT record_maps.map, category, points, stars, mappers, release, width, height,
|
||||
string_to_array(CONCAT_WS(',',
|
||||
CASE WHEN DEATH = '1' THEN 'DEATH' END,
|
||||
CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
|
||||
|
@ -191,7 +191,7 @@ impl Map {
|
|||
sqlx::query_as!(
|
||||
Map,
|
||||
"
|
||||
SELECT record_maps.map, category, points, stars, mapper, release, width, height,
|
||||
SELECT record_maps.map, category, points, stars, mappers, release, width, height,
|
||||
string_to_array(CONCAT_WS(',',
|
||||
CASE WHEN DEATH = '1' THEN 'DEATH' END,
|
||||
CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
|
||||
|
@ -234,7 +234,7 @@ impl Map {
|
|||
CASE WHEN PLASMAE = '1' THEN 'PLASMAE' END,
|
||||
CASE WHEN PLASMAU = '1' THEN 'PLASMAU' END), ',') AS tiles
|
||||
FROM record_maps JOIN record_mapinfo ON record_maps.map = record_mapinfo.map
|
||||
WHERE mapper = $1;
|
||||
WHERE $1 = ANY(mappers)
|
||||
",
|
||||
mapper
|
||||
)
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
pub mod map;
|
||||
pub mod race;
|
||||
pub mod teamrace;
|
||||
|
|
|
@ -5,14 +5,14 @@ use crate::database::DatabaseHandler;
|
|||
|
||||
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
|
||||
pub struct Race {
|
||||
name: Option<String>,
|
||||
map: Option<String>,
|
||||
time: Option<f64>,
|
||||
timestamp: Option<NaiveDateTime>,
|
||||
server: Option<String>,
|
||||
checkpoints: Option<Vec<f64>>,
|
||||
gameid: Option<String>,
|
||||
ddnet7: Option<i16>,
|
||||
pub name: String,
|
||||
pub map: String,
|
||||
pub time: f32,
|
||||
pub timestamp: NaiveDateTime,
|
||||
pub server: String,
|
||||
pub checkpoints: Option<Vec<f64>>,
|
||||
pub gameid: Option<String>,
|
||||
pub ddnet7: i16,
|
||||
}
|
||||
|
||||
impl Race {
|
||||
|
|
39
src/database/models/teamrace.rs
Normal file
39
src/database/models/teamrace.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use chrono::NaiveDateTime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::database::DatabaseHandler;
|
||||
|
||||
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
|
||||
pub struct Teamrace {
|
||||
pub players: Vec<String>,
|
||||
pub map: String,
|
||||
pub time: f32,
|
||||
pub timestamp: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl Teamrace {
|
||||
pub async fn get_teamrace_by_player(
|
||||
db: &DatabaseHandler,
|
||||
player: &str,
|
||||
) -> Result<Vec<Teamrace>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Teamrace,
|
||||
"SELECT players, map, time, timestamp FROM record_teamrace_array WHERE $1 = ANY(players)",
|
||||
player
|
||||
).fetch_all(&db.pool)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_teamrace_by_map(
|
||||
db: &DatabaseHandler,
|
||||
map: &str,
|
||||
) -> Result<Vec<Teamrace>, sqlx::Error> {
|
||||
sqlx::query_as!(
|
||||
Teamrace,
|
||||
"SELECT players, map, time, timestamp FROM record_teamrace_array WHERE map = $1",
|
||||
map
|
||||
)
|
||||
.fetch_all(&db.pool)
|
||||
.await
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user