X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FScores.hs;h=aa847a837ee1d9dc68a47c01c10db2668506da43;hb=f0425854304197ab5ad47293b27b2e0b188cb844;hp=e4680a5f71e3d39dd41098c192b6262548aa9346;hpb=6bf6a25053c2f721d67a70b1eaa1a018da5baa87;p=dead%2Fhtsn-import.git diff --git a/src/TSN/XML/Scores.hs b/src/TSN/XML/Scores.hs index e4680a5..aa847a8 100644 --- a/src/TSN/XML/Scores.hs +++ b/src/TSN/XML/Scores.hs @@ -27,15 +27,14 @@ 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, insert_, - migrate, - runMigration, - silentMigrationLogger ) + migrate ) import Database.Groundhog.Core ( DefaultKey ) -import Database.Groundhog.Generic ( runDbConn ) +import Database.Groundhog.Generic ( runDbConn, runMigrationSilent ) import Database.Groundhog.Sqlite ( withSqliteConn ) import Database.Groundhog.TH ( groundhog, @@ -58,12 +57,11 @@ 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 ) import TSN.Location ( Location(..), pickle_location ) -import TSN.Picklers ( xp_time_stamp ) +import TSN.Picklers ( xp_attr_option, xp_time_stamp ) import TSN.Team ( FromXmlFkTeams(..), HTeam(..), @@ -128,9 +126,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 +204,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 +227,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 +418,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)) @@ -442,7 +444,7 @@ pickle_status :: PU ScoreGameStatus pickle_status = xpElem "status" $ xpWrap (from_tuple, to_tuple') $ - xpTriple (xpAttr "numeral" $ xpOption xpInt) + xpTriple (xpAttr "numeral" $ xp_attr_option) (xpOption $ xpAttr "type" $ xpOption xpText) xpText where @@ -460,7 +462,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) @@ -625,7 +627,7 @@ test_on_delete_cascade = testGroup "cascading delete tests" let d = undefined :: ScoreGame let e = undefined :: Score_Location actual <- withSqliteConn ":memory:" $ runDbConn $ do - runMigration silentMigrationLogger $ do + runMigrationSilent $ do migrate a migrate b migrate c