X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FScheduleChanges.hs;h=fd5641cdbc15660f6235c6a17dbcb369be68ec06;hb=32147474ba5c91452eeb532381f63e88c257a982;hp=a1812da24067944be8ae66381d8ab3e8675f49e1;hpb=2d8d3c2d84e6880c679c6346802f5a688d047e97;p=dead%2Fhtsn-import.git
diff --git a/src/TSN/XML/ScheduleChanges.hs b/src/TSN/XML/ScheduleChanges.hs
index a1812da..fd5641c 100644
--- a/src/TSN/XML/ScheduleChanges.hs
+++ b/src/TSN/XML/ScheduleChanges.hs
@@ -26,15 +26,14 @@ where
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,
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,
@@ -56,7 +55,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 )
@@ -109,9 +107,10 @@ data ScheduleChangeXml =
xml_sc_listings :: [ScheduleChangesListingXml] }
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
@@ -128,9 +127,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
@@ -168,13 +167,19 @@ instance XmlImport Message
-- like, \FINAL\ 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 \ contained within a
-- \, within a \. During the transition
@@ -221,9 +226,9 @@ data ScheduleChangesListingXml =
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic ScheduleChangesListingXml
+instance H.HVector ScheduleChangesListingXml
instance ToDb ScheduleChangesListingXml where
@@ -344,9 +349,9 @@ mkPersist tsn_codegen_config [groundhog|
- embedded: ScheduleChangesListingStatus
fields:
- - name: db_status_numeral
+ - name: _db_status_numeral
dbName: status_numeral
- - name: db_status
+ - name: _db_status
dbName: status
|]
@@ -388,22 +393,19 @@ pickle_home_team =
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 \ 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)
@@ -424,7 +426,7 @@ pickle_listing =
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
@@ -436,7 +438,7 @@ pickle_schedule_change =
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)
@@ -500,7 +502,7 @@ test_on_delete_cascade =
let c = undefined :: ScheduleChangesListing
actual <- withSqliteConn ":memory:" $ runDbConn $ do
- runMigration silentMigrationLogger $ do
+ runMigrationSilent $ do
migrate a
migrate b
migrate c