diff options
Diffstat (limited to 'planetwars-server/src/db')
-rw-r--r-- | planetwars-server/src/db/matches.rs | 21 |
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) +} |