From: Michael Orlitzky Date: Fri, 2 Jan 2015 22:23:43 +0000 (-0500) Subject: Migrate TSN.XML.Scores to fixed-vector-hetero. X-Git-Tag: 0.2.1~13 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=ddb77c32ec8d5d76b10a5ea642810595a408b82f;p=dead%2Fhtsn-import.git Migrate TSN.XML.Scores to fixed-vector-hetero. --- diff --git a/src/TSN/XML/Scores.hs b/src/TSN/XML/Scores.hs index e4680a5..f0ce6de 100644 --- a/src/TSN/XML/Scores.hs +++ b/src/TSN/XML/Scores.hs @@ -27,6 +27,7 @@ import Data.Data ( Data ) import Data.Time ( UTCTime ) import Data.Tuple.Curry ( uncurryN ) import Data.Typeable ( Typeable ) +import qualified Data.Vector.HFixed as H ( HVector, convert ) import Database.Groundhog ( countAll, deleteAll, @@ -58,7 +59,6 @@ import Text.XML.HXT.Core ( xpWrap ) -- Local imports. -import Generics ( Generic(..), to_tuple ) import TSN.Codegen ( tsn_codegen_config ) import TSN.Database ( insert_or_select ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) @@ -128,9 +128,9 @@ data Message = deriving (Eq, GHC.Generic, Show) --- | For 'Generics.to_tuple'. +-- | For 'H.convert'. -- -instance Generic Message +instance H.HVector Message instance ToDb Message where @@ -206,9 +206,9 @@ data ScoreGameXml = deriving (Eq, GHC.Generic, Show) --- | For 'Generics.to_tuple'. +-- | For 'H.convert'. -- -instance Generic ScoreGameXml +instance H.HVector ScoreGameXml instance ToDb ScoreGameXml where @@ -229,6 +229,10 @@ instance FromXmlFkTeams ScoreGameXml where -- | To create a 'ScoreGame' from a 'ScoreGameXml', we need three -- foreign keys: the parent message, and the away/home teams. -- + -- During conversion, we also get the pitchers out of the teams; + -- unfortunately this prevents us from making the conversion + -- generically. + -- from_xml_fk_teams fk fk_away fk_home ScoreGameXml{..} = ScoreGame { db_scores_id = fk, @@ -416,7 +420,7 @@ mkPersist tsn_codegen_config [groundhog| pickle_message :: PU Message pickle_message = xpElem "message" $ - xpWrap (from_tuple, to_tuple) $ + xpWrap (from_tuple, H.convert) $ xp11Tuple (xpElem "XML_File_ID" xpInt) (xpElem "heading" xpText) (xpElem "game_id" (xpOption xpInt)) @@ -460,7 +464,7 @@ pickle_status = pickle_game :: PU ScoreGameXml pickle_game = xpElem "game" $ - xpWrap (from_tuple, to_tuple) $ + xpWrap (from_tuple, H.convert) $ xp7Tuple pickle_vteam pickle_hteam (xpElem "vscore" xpInt)