import Control.Monad ( forM_ )
import Data.Time ( UTCTime(..) )
import Data.Tuple.Curry ( uncurryN )
+import qualified Data.Vector.HFixed as H ( HVector, cons, convert )
import Database.Groundhog (
countAll,
deleteAll,
- 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,
xpWrap )
-- Local imports.
-import Generics ( Generic(..), prepend, to_tuple )
import TSN.Codegen (
tsn_codegen_config )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
-import TSN.Picklers ( xp_date_padded, xp_tba_time, xp_time_stamp )
+import TSN.Picklers ( xp_date_padded, xp_tba_int, xp_tba_time, xp_time_stamp )
import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) )
import Xml (
Child(..),
xml_time_stamp :: UTCTime }
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic Message
+instance H.HVector Message
instance ToDb Message where
db_track_name :: String,
db_location :: String,
db_tv_listing :: Maybe String,
- db_laps :: Int,
+ db_laps :: Maybe Int,
db_track_length :: String -- ^ Sometimes the word "miles" shows up.
}
xml_track_name :: String,
xml_location :: String,
xml_tv_listing :: Maybe String,
- xml_laps :: Int,
+ xml_laps :: Maybe Int,
xml_track_length :: String, -- ^ Sometimes the word \"miles\" shows up,
-- so we can't do the right thing and use
-- a 'Double'.
xml_race_results :: [AutoRacingScheduleListingRaceResult] }
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic AutoRacingScheduleListingXml
+instance H.HVector AutoRacingScheduleListingXml
-- | Pseudo-accessor to get the race result listings out of a
}
deriving ( GHC.Generic )
--- | For 'Generics.prepend'.
+-- | For 'H.cons'.
--
-instance Generic AutoRacingScheduleListingRaceResultRaceResultListing
+instance H.HVector AutoRacingScheduleListingRaceResultRaceResultListing
-- | XML Representation of an
}
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic AutoRacingScheduleListingRaceResultRaceResultListingXml
+instance H.HVector AutoRacingScheduleListingRaceResultRaceResultListingXml
instance ToDb AutoRacingScheduleListingRaceResultRaceResultListingXml where
-- 'AutoRacingScheduleListingRaceResultRaceResultListing', we just
-- add the foreign key to the parent 'AutoRacingScheduleListing'.
--
- from_xml_fk = prepend
+ from_xml_fk = H.cons
-- | This allows us to insert the XML representation
pickle_message :: PU Message
pickle_message =
xpElem "message" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp8Tuple (xpElem "XML_File_ID" xpInt)
(xpElem "heading" xpText)
(xpElem "category" xpText)
pickle_listing :: PU AutoRacingScheduleListingXml
pickle_listing =
xpElem "Listing" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp10Tuple (xpElem "RaceID" xpInt)
(xpElem "Race_Date" xp_date_padded)
(xpElem "Race_Time" xp_tba_time)
(xpElem "TrackName" xpText)
(xpElem "Location" xpText)
(xpElem "TV_Listing" $ xpOption xpText)
- (xpElem "Laps" xpInt)
+ (xpElem "Laps" xp_tba_int)
(xpElem "TrackLength" xpText)
(xpList pickle_race_results)
where
PU AutoRacingScheduleListingRaceResultRaceResultListingXml
pickle_race_results_listing =
xpElem "RaceResultsListing" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp7Tuple (xpElem "FinishPosition" xpInt)
(xpElem "DriverID" xpInt)
(xpElem "Name" xpText)
let c = undefined :: AutoRacingScheduleListingRaceResultRaceResultListing
actual <- withSqliteConn ":memory:" $ runDbConn $ do
- runMigration silentMigrationLogger $ do
+ runMigrationSilent $ do
migrate a
migrate b
migrate c