From: Michael Orlitzky Date: Fri, 4 Jul 2014 06:39:40 +0000 (-0400) Subject: Update TSN.XML modules to use the new Child class. X-Git-Tag: 0.0.6~43 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=b0a87f9323223a0af538184940b35a081f5763af;p=dead%2Fhtsn-import.git Update TSN.XML modules to use the new Child class. --- diff --git a/src/TSN/XML/AutoRacingResults.hs b/src/TSN/XML/AutoRacingResults.hs index 817bf15..370ae81 100644 --- a/src/TSN/XML/AutoRacingResults.hs +++ b/src/TSN/XML/AutoRacingResults.hs @@ -63,6 +63,7 @@ import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers ( xp_earnings, xp_datetime, xp_time_stamp ) import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) ) import Xml ( + Child(..), FromXml(..), FromXmlFk(..), ToDb(..), @@ -210,12 +211,14 @@ instance ToDb AutoRacingResultsListingXml where type Db AutoRacingResultsListingXml = AutoRacingResultsListing -instance FromXmlFk AutoRacingResultsListingXml where +instance Child AutoRacingResultsListingXml where -- | Each 'AutoRacingResultsListingXml' is contained in (i.e. has a -- foreign key to) a 'AutoRacingResults'. -- type Parent AutoRacingResultsListingXml = AutoRacingResults + +instance FromXmlFk AutoRacingResultsListingXml where -- | To convert an 'AutoRacingResultsListingXml' to an -- 'AutoRacingResultsListing', we add the foreign key and copy -- everything else verbatim. @@ -311,12 +314,15 @@ instance ToDb AutoRacingResultsRaceInformationXml where type Db AutoRacingResultsRaceInformationXml = AutoRacingResultsRaceInformation -instance FromXmlFk AutoRacingResultsRaceInformationXml where + +instance Child AutoRacingResultsRaceInformationXml where -- | Each 'AutoRacingResultsRaceInformationXml' is contained in -- (i.e. has a foreign key to) a 'AutoRacingResults'. -- type Parent AutoRacingResultsRaceInformationXml = AutoRacingResults + +instance FromXmlFk AutoRacingResultsRaceInformationXml where -- | To convert an 'AutoRacingResultsRaceInformationXml' to an -- 'AutoRacingResultsRaceInformartion', we add the foreign key and -- copy everything else verbatim. diff --git a/src/TSN/XML/AutoRacingSchedule.hs b/src/TSN/XML/AutoRacingSchedule.hs index 212eee9..01611d2 100644 --- a/src/TSN/XML/AutoRacingSchedule.hs +++ b/src/TSN/XML/AutoRacingSchedule.hs @@ -59,6 +59,7 @@ import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers ( xp_date_padded, xp_tba_time, xp_time_stamp ) import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) ) import Xml ( + Child(..), FromXml(..), FromXmlFk(..), ToDb(..), @@ -192,12 +193,15 @@ instance ToDb AutoRacingScheduleListingXml where -- type Db AutoRacingScheduleListingXml = AutoRacingScheduleListing -instance FromXmlFk AutoRacingScheduleListingXml where + +instance Child AutoRacingScheduleListingXml where -- | Each 'AutoRacingScheduleListingXml' is contained in (i.e. has a -- foreign key to) a 'AutoRacingSchedule'. -- type Parent AutoRacingScheduleListingXml = AutoRacingSchedule + +instance FromXmlFk AutoRacingScheduleListingXml where -- | To convert an 'AutoRacingScheduleListingXml' to an -- 'AutoRacingScheduleListing', we add the foreign key and drop -- the 'xml_race_results'. We also mash the date/time together @@ -289,7 +293,7 @@ instance ToDb AutoRacingScheduleListingRaceResultRaceResultListingXml where AutoRacingScheduleListingRaceResultRaceResultListing -instance FromXmlFk AutoRacingScheduleListingRaceResultRaceResultListingXml where +instance Child AutoRacingScheduleListingRaceResultRaceResultListingXml where -- | Each 'AutoRacingScheduleListingRaceResultRaceResultListingXml' -- is contained in (i.e. has a foreign key to) an -- 'AutoRacingScheduleListing'. We skip the intermediate @@ -298,6 +302,8 @@ instance FromXmlFk AutoRacingScheduleListingRaceResultRaceResultListingXml where type Parent AutoRacingScheduleListingRaceResultRaceResultListingXml = AutoRacingScheduleListing + +instance FromXmlFk AutoRacingScheduleListingRaceResultRaceResultListingXml where -- | To convert an -- 'AutoRacingScheduleListingRaceResultRaceResultListingXml' to an -- 'AutoRacingScheduleListingRaceResultRaceResultListing', we just diff --git a/src/TSN/XML/Injuries.hs b/src/TSN/XML/Injuries.hs index 1d1d314..6af9ad9 100644 --- a/src/TSN/XML/Injuries.hs +++ b/src/TSN/XML/Injuries.hs @@ -64,6 +64,7 @@ import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers ( xp_time_stamp ) import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) ) import Xml ( + Child(..), FromXml(..), FromXmlFk(..), ToDb(..), @@ -122,10 +123,11 @@ instance ToDb InjuriesListingXml where -- | The DB analogue of a 'InjuriesListingXml' is a 'InjuriesListing' type Db InjuriesListingXml = InjuriesListing -instance FromXmlFk InjuriesListingXml where +instance Child InjuriesListingXml where -- | Our foreign key points to an 'Injuries'. type Parent InjuriesListingXml = Injuries +instance FromXmlFk InjuriesListingXml where -- | To convert between a 'InjuriesListingXml' and a -- 'InjuriesListing', we simply append the foreign key. from_xml_fk fk InjuriesListingXml{..} = diff --git a/src/TSN/XML/InjuriesDetail.hs b/src/TSN/XML/InjuriesDetail.hs index 9c6ae5d..0eb3e23 100644 --- a/src/TSN/XML/InjuriesDetail.hs +++ b/src/TSN/XML/InjuriesDetail.hs @@ -59,6 +59,7 @@ import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers( xp_date, xp_time_stamp ) import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) ) import Xml ( + Child(..), FromXml(..), FromXmlFk(..), ToDb(..), @@ -160,11 +161,14 @@ instance ToDb InjuriesDetailListingXml where -- 'InjuriesDetailListing'. type Db InjuriesDetailListingXml = InjuriesDetailListing -instance FromXmlFk InjuriesDetailListingXml where + +instance Child InjuriesDetailListingXml where -- | Each 'InjuriesDetailListingXml' is contained in an -- 'InjuriesDetail'. type Parent InjuriesDetailListingXml = InjuriesDetail + +instance FromXmlFk InjuriesDetailListingXml where -- | Construct a 'InjuriesDetailListing' from a -- 'InjuriesDetailListingXml' and a foreign key to a -- 'InjuriesDetail'. @@ -234,12 +238,15 @@ instance ToDb InjuriesDetailListingPlayerListingXml where type Db InjuriesDetailListingPlayerListingXml = InjuriesDetailListingPlayerListing -instance FromXmlFk InjuriesDetailListingPlayerListingXml where + +instance Child InjuriesDetailListingPlayerListingXml where -- | Each 'InjuriesDetailListingPlayerListingXml' is contained in an -- 'InjuriesDetailListing'. -- type Parent InjuriesDetailListingPlayerListingXml = InjuriesDetailListing + +instance FromXmlFk InjuriesDetailListingPlayerListingXml where -- | To construct a 'InjuriesDetailListingPlayerListing' from a -- 'InjuriesDetailListingPlayerListingXml' we need to supply a -- foreign key to an 'InjuriesDetailListing'. diff --git a/src/TSN/XML/Odds.hs b/src/TSN/XML/Odds.hs index 0e84ce6..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(..), @@ -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. diff --git a/src/TSN/XML/Scores.hs b/src/TSN/XML/Scores.hs index ef2330c..66ef90b 100644 --- a/src/TSN/XML/Scores.hs +++ b/src/TSN/XML/Scores.hs @@ -67,6 +67,7 @@ import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers ( xp_time_stamp ) import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) ) import Xml ( + Child(..), FromXml(..), FromXmlFk(..), ToDb(..), @@ -202,12 +203,15 @@ instance ToDb ScoreGameXml where -- type Db ScoreGameXml = ScoreGame -instance FromXmlFk ScoreGameXml where + +instance Child ScoreGameXml where -- | Each 'ScoreGameXml' is contained in (i.e. has a foreign key to) -- a 'Score'. -- type Parent ScoreGameXml = Score + +instance FromXmlFk ScoreGameXml where from_xml_fk fk ScoreGameXml{..} = ScoreGame { db_scores_id = fk, diff --git a/src/TSN/XML/Weather.hs b/src/TSN/XML/Weather.hs index bda29ee..be591c1 100644 --- a/src/TSN/XML/Weather.hs +++ b/src/TSN/XML/Weather.hs @@ -57,6 +57,7 @@ import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) import TSN.Picklers ( xp_gamedate, xp_time_stamp ) import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) ) import Xml ( + Child(..), FromXml(..), FromXmlFk(..), ToDb(..), @@ -101,15 +102,18 @@ data WeatherForecastListing = instance ToDb WeatherForecastListingXml where type Db WeatherForecastListingXml = WeatherForecastListing --- | This is needed to define the 'XmlImportFk' instance for --- 'WeatherForecastListing'. --- -instance FromXmlFk WeatherForecastListingXml where + +instance Child WeatherForecastListingXml where -- | Each 'WeatherForecastListingXml' is contained in a -- 'WeatherForecast'. -- type Parent WeatherForecastListingXml = WeatherForecast + +-- | This is needed to define the 'XmlImportFk' instance for +-- 'WeatherForecastListing'. +-- +instance FromXmlFk WeatherForecastListingXml where from_xml_fk fk WeatherForecastListingXml{..} = WeatherForecastListing { db_weather_forecasts_id = fk, @@ -164,9 +168,15 @@ instance ToDb WeatherForecastXml where -- type Db WeatherForecastXml = WeatherForecast -instance FromXmlFk WeatherForecastXml where + +instance Child WeatherForecastXml where + -- | The database type containing a 'WeatherForecastXml' is + -- 'Weather'. type Parent WeatherForecastXml = Weather + +instance FromXmlFk WeatherForecastXml where + -- | To convert a 'WeatherForecastXml' into a 'WeatherForecast', we -- replace the 'WeatherLeague' with its name. --