aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/db
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-01-02 17:56:52 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-01-02 17:56:52 +0100
commit69331eb08a6199bfa8378e08cf378803b076eaae (patch)
tree3a84474e81c2f2d553369e96244e2a62f601509d /planetwars-server/src/db
parent85dcf3ba2fd0cf907610625399db691b274118bb (diff)
downloadplanetwars.dev-69331eb08a6199bfa8378e08cf378803b076eaae.tar.xz
planetwars.dev-69331eb08a6199bfa8378e08cf378803b076eaae.zip
serve match logs
Diffstat (limited to 'planetwars-server/src/db')
-rw-r--r--planetwars-server/src/db/matches.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/planetwars-server/src/db/matches.rs b/planetwars-server/src/db/matches.rs
index 85f0631..9bf00db 100644
--- a/planetwars-server/src/db/matches.rs
+++ b/planetwars-server/src/db/matches.rs
@@ -1,5 +1,5 @@
use chrono::NaiveDateTime;
-use diesel::{BelongingToDsl, RunQueryDsl};
+use diesel::{BelongingToDsl, QueryDsl, RunQueryDsl};
use diesel::{Connection, GroupedBy, PgConnection, QueryResult};
use crate::schema::{match_players, matches};
@@ -95,3 +95,22 @@ pub fn list_matches(conn: &PgConnection) -> QueryResult<Vec<MatchData>> {
Ok(res)
})
}
+
+pub fn find_match(id: i32, conn: &PgConnection) -> QueryResult<MatchData> {
+ conn.transaction(|| {
+ let match_base = matches::table.find(id).get_result::<MatchBase>(conn)?;
+
+ let match_players = MatchPlayer::belonging_to(&match_base).load::<MatchPlayer>(conn)?;
+
+ let res = MatchData {
+ base: match_base,
+ match_players,
+ };
+
+ Ok(res)
+ })
+}
+
+pub fn find_mach_base(id: i32, conn: &PgConnection) -> QueryResult<MatchBase> {
+ matches::table.find(id).get_result::<MatchBase>(conn)
+}