X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FWeather.hs;h=be591c10276d76570fa4f29a8fdc34de7cfbd714;hb=5a8d0ad5929fb297c74ea0802c11f9aa94b25ce7;hp=2561377afebd77f7af1911e2ab47b0e0dc6de732;hpb=53e5e32d40a16923ba1d362f405015c3a679bfeb;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/Weather.hs b/src/TSN/XML/Weather.hs index 2561377..be591c1 100644 --- a/src/TSN/XML/Weather.hs +++ b/src/TSN/XML/Weather.hs @@ -10,6 +10,7 @@ -- that league contains a bunch of listings. -- module TSN.XML.Weather ( + dtd, pickle_message, -- * Tests weather_tests, @@ -25,7 +26,7 @@ import Data.Time ( UTCTime ) import Data.Tuple.Curry ( uncurryN ) import Database.Groundhog ( countAll, - executeRaw, + deleteAll, migrate, runMigration, silentMigrationLogger ) @@ -56,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(..), @@ -64,6 +66,13 @@ import Xml ( unsafe_unpickle ) + +-- | The DTD to which this module corresponds. Used to invoke dbimport. +-- +dtd :: String +dtd = "weatherxml.dtd" + + -- -- DB/XML Data types -- @@ -93,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, @@ -156,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. -- @@ -404,8 +422,7 @@ test_on_delete_cascade = migrate b migrate c _ <- dbimport weather - -- No idea how 'delete' works, so do this instead. - executeRaw False "DELETE FROM weather;" [] + deleteAll a count_a <- countAll a count_b <- countAll b count_c <- countAll c