X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FOdds.hs;h=c4f00266b6fbfa398442056d2d47249da77cf3ce;hb=b0a87f9323223a0af538184940b35a081f5763af;hp=8061a3e23db2ec2c2eb6c3311ecebcf735fd239e;hpb=1fd949aaaa0798f2e01d649711a4148e31275327;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/Odds.hs b/src/TSN/XML/Odds.hs index 8061a3e..c4f0026 100644 --- a/src/TSN/XML/Odds.hs +++ b/src/TSN/XML/Odds.hs @@ -68,6 +68,7 @@ import TSN.Picklers ( xp_date_padded, xp_time, xp_time_stamp ) import TSN.Team ( Team(..) ) import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) ) import Xml ( + Child(..), FromXml(..), FromXmlFk(..), ToDb(..), @@ -187,8 +188,8 @@ instance FromXml OddsGameHomeTeamXml where from_xml OddsGameHomeTeamXml{..} = Team { team_id = xml_home_team_id, - team_abbreviation = Just xml_home_team_abbr, - team_name = Just xml_home_team_name } + abbreviation = Just xml_home_team_abbr, + name = Just xml_home_team_name } -- | This allows us to insert the XML representation -- 'OddsGameHomeTeamXml' directly. @@ -325,12 +326,15 @@ instance ToDb OddsGameXml where -- type Db OddsGameXml = OddsGame -instance FromXmlFk OddsGameXml where + +instance Child OddsGameXml where -- | Each 'OddsGameXml' is contained in an 'Odds'. In other words -- the foreign key for 'OddsGame' points to an 'Odds'. -- type Parent OddsGameXml = Odds + +instance FromXmlFk OddsGameXml where -- | To convert from the XML representation to the database one, we -- drop the home/away teams and the casino lines, but retain the -- home/away rotation numbers and the starters. @@ -535,15 +539,13 @@ instance DbImport Message where odds_id <- insert_xml m forM_ (xml_games m) $ \g -> do - -- Next, we insert the home and away teams. We do this before - -- inserting the game itself because the game has two foreign keys - -- pointing to "teams". + -- First insert the game, keyed to the "odds", + game_id <- insert_xml_fk odds_id g + + -- Next, we insert the home and away teams. away_team_id <- insert_xml_or_select (xml_away_team g) home_team_id <- insert_xml_or_select (xml_home_team g) - -- Now insert the game, keyed to the "odds", - game_id <- insert_xml_fk odds_id g - -- Insert a record into odds_games__teams mapping the -- home/away teams to this game. Use the full record syntax -- because the types would let us mix up the home/away teams.