import Control.Monad ( forM_ )
import Data.Time ( UTCTime(..) )
import Data.Tuple.Curry ( uncurryN )
+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 ScheduleChangeXml
+instance H.HVector ScheduleChangeXml
-- | XML representation of a 'ScheduleChanges'. It has the same
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic Message
+instance H.HVector Message
instance ToDb Message where
-- like, \<status numeral=\"4\"\>FINAL\</status\> within the XML,
-- but they're in one-to-one correspondence with the listings.
--
+-- The leading underscores prevent unused field warnings.
+--
data ScheduleChangesListingStatus =
ScheduleChangesListingStatus {
- db_status_numeral :: Int,
- db_status :: Maybe String } -- Yes, they can be empty.
- deriving (Eq, Show)
+ _db_status_numeral :: Int,
+ _db_status :: Maybe String } -- Yes, they can be empty.
+ deriving (Eq, GHC.Generic, Show)
+-- | For 'H.convert'.
+--
+instance H.HVector ScheduleChangesListingStatus
+
-- | Database representation of a \<SC_Listing\> contained within a
-- \<Schedule_Change\>, within a \<message\>. During the transition
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic ScheduleChangesListingXml
+instance H.HVector ScheduleChangesListingXml
instance ToDb ScheduleChangesListingXml where
- embedded: ScheduleChangesListingStatus
fields:
- - name: db_status_numeral
+ - name: _db_status_numeral
dbName: status_numeral
- - name: db_status
+ - name: _db_status
dbName: status
|]
pickle_status :: PU ScheduleChangesListingStatus
pickle_status =
xpElem "status" $
- xpWrap (from_tuple, to_tuple') $
+ xpWrap (from_tuple, H.convert) $
xpPair (xpAttr "numeral" xpInt)
(xpOption xpText)
where
from_tuple = uncurry ScheduleChangesListingStatus
- -- Avouid unused field warnings.
- to_tuple' ScheduleChangesListingStatus{..} =
- (db_status_numeral, db_status)
-- | An (un)pickler for the \<SC_Listing\> elements.
--
pickle_listing :: PU ScheduleChangesListingXml
pickle_listing =
xpElem "SC_Listing" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp11Tuple (xpAttr "type" xpText)
(xpElem "Schedule_ID" xpInt)
(xpElem "Game_Date" xp_date_padded)
pickle_schedule_change :: PU ScheduleChangeXml
pickle_schedule_change =
xpElem "Schedule_Change" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xpPair (xpAttr "Sport" xpText)
(xpList pickle_listing)
where
pickle_message :: PU Message
pickle_message =
xpElem "message" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp6Tuple (xpElem "XML_File_ID" xpInt)
(xpElem "heading" xpText)
(xpElem "category" xpText)