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,
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 )
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic Message
+instance H.HVector Message
instance ToDb Message where
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic ScoreGameXml
+instance H.HVector ScoreGameXml
instance ToDb 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,
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))
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)