From 7701e386e295b11c7b02d7b6f7418fac4575f21e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 21 Jan 2014 12:45:22 -0500 Subject: [PATCH] Add time_stamp and xml_file_id to Weather. --- src/TSN/XML/Weather.hs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/TSN/XML/Weather.hs b/src/TSN/XML/Weather.hs index f3b60af..4951951 100644 --- a/src/TSN/XML/Weather.hs +++ b/src/TSN/XML/Weather.hs @@ -50,11 +50,14 @@ import Text.XML.HXT.Core ( import TSN.Codegen ( tsn_codegen_config ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) -import TSN.Picklers ( xp_gamedate ) +import TSN.Picklers ( xp_gamedate, xp_time_stamp ) import TSN.XmlImport ( XmlImport(..) ) import Xml ( FromXml(..), ToDb(..), pickle_unpickle, unpickleable ) +-- +-- DB/XML Data types +-- -- | Database/XML representation of a weather forecast listing. -- @@ -136,8 +139,10 @@ instance XmlImport WeatherForecastXml -- data Weather = Weather { + db_xml_file_id :: Int, db_sport :: String, - db_title :: String } + db_title :: String, + db_time_stamp :: UTCTime } -- | The XML representation of a weather message. @@ -150,7 +155,7 @@ data Message = xml_sport :: String, xml_title :: String, xml_forecasts :: [WeatherForecastXml], - xml_time_stamp :: String } + xml_time_stamp :: UTCTime } deriving (Eq, Show) @@ -165,8 +170,10 @@ instance FromXml Message where -- from_xml Message{..} = Weather { + db_xml_file_id = xml_xml_file_id, db_sport = xml_sport, - db_title = xml_title } + db_title = xml_title, + db_time_stamp = xml_time_stamp } -- | This allows us to call 'insert_xml' on a 'Message' without first -- converting it to the database representation. @@ -192,6 +199,13 @@ data WeatherForecast_WeatherForecastListing = mkPersist tsn_codegen_config [groundhog| - entity: Weather + constructors: + - name: Weather + uniques: + - name: unique_weather + type: constraint + # Prevent multiple imports of the same message. + fields: [db_xml_file_id] - entity: WeatherForecast dbName: weather_forecasts @@ -313,7 +327,7 @@ pickle_message = (xpElem "sport" xpText) (xpElem "title" xpText) (xpList pickle_forecast) - (xpElem "time_stamp" xpText) + (xpElem "time_stamp" xp_time_stamp) where from_tuple = uncurryN Message to_tuple Message{..} = (xml_xml_file_id, -- 2.44.2