import TSN.Team ( Team(..) )
import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) )
import Xml (
+ Child(..),
FromXml(..),
FromXmlFk(..),
ToDb(..),
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.
--
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.
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.