X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;ds=inline;f=src%2FTSN%2FXML%2FAutoRacingResults.hs;h=e51fff852aabac0cb6c25ebc6c4e524bd5b0c310;hb=7b33eb87f59d46ec97d619f7521c067d8a6b9308;hp=40e199f5464e6ea6f84e655925ebe8f10089d6eb;hpb=ee4b98e5b4e9494364604a2e1a999c3d6d5acafb;p=dead%2Fhtsn-import.git
diff --git a/src/TSN/XML/AutoRacingResults.hs b/src/TSN/XML/AutoRacingResults.hs
index 40e199f..e51fff8 100644
--- a/src/TSN/XML/AutoRacingResults.hs
+++ b/src/TSN/XML/AutoRacingResults.hs
@@ -29,14 +29,13 @@ import Data.Maybe ( fromMaybe )
import Data.Time ( UTCTime(..) )
import Data.Tuple.Curry ( uncurryN )
import Data.Typeable ( Typeable )
+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,
@@ -61,7 +60,6 @@ import Text.XML.HXT.Core (
xpWrap )
-- Local imports.
-import Generics ( Generic(..), to_tuple )
import TSN.Codegen ( tsn_codegen_config )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
import TSN.Picklers (
@@ -133,9 +131,9 @@ data Message =
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
@@ -175,49 +173,55 @@ instance XmlImport Message
-- * AutoRacingResultsListing/AutoRacingResultsListingXml
-- | Database representation of a \
contained within a
--- \.
+-- \. The leading underscores prevent unused field
+-- warnings.
--
data AutoRacingResultsListing =
AutoRacingResultsListing {
- db_auto_racing_results_id :: DefaultKey AutoRacingResults,
- db_finish_position :: Int,
- db_starting_position :: Int,
- db_car_number :: Int,
- db_driver_id :: Int,
- db_driver :: String,
- db_car_make :: String,
- db_points :: Int,
- db_laps_completed :: Int,
- db_laps_leading :: Int,
- db_status :: Maybe String,
- db_dnf :: Maybe Bool,
- db_nc :: Maybe Bool,
- db_earnings :: Maybe Int }
-
+ _db_auto_racing_results_id :: DefaultKey AutoRacingResults,
+ _db_finish_position :: Int,
+ _db_starting_position :: Int,
+ _db_car_number :: Int,
+ _db_driver_id :: Int,
+ _db_driver :: String,
+ _db_car_make :: String,
+ _db_points :: Int,
+ _db_laps_completed :: Int,
+ _db_laps_leading :: Int,
+ _db_status :: Maybe String,
+ _db_dnf :: Maybe Bool,
+ _db_nc :: Maybe Bool,
+ _db_earnings :: Maybe Int }
+ deriving ( GHC.Generic )
+
+-- | For 'H.convert' and 'H.cons'.
+--
+instance H.HVector AutoRacingResultsListing
-- | XML representation of a \ contained within a
--- \.
+-- \. The leading underscores prevent unused field
+-- warnings.
--
data AutoRacingResultsListingXml =
AutoRacingResultsListingXml {
- xml_finish_position :: Int,
- xml_starting_position :: Int,
- xml_car_number :: Int,
- xml_driver_id :: Int,
- xml_driver :: String,
- xml_car_make :: String,
- xml_points :: Int,
- xml_laps_completed :: Int,
- xml_laps_leading :: Int,
- xml_status :: Maybe String,
- xml_dnf :: Maybe Bool,
- xml_nc :: Maybe Bool,
- xml_earnings :: Maybe Int }
+ _xml_finish_position :: Int,
+ _xml_starting_position :: Int,
+ _xml_car_number :: Int,
+ _xml_driver_id :: Int,
+ _xml_driver :: String,
+ _xml_car_make :: String,
+ _xml_points :: Int,
+ _xml_laps_completed :: Int,
+ _xml_laps_leading :: Int,
+ _xml_status :: Maybe String,
+ _xml_dnf :: Maybe Bool,
+ _xml_nc :: Maybe Bool,
+ _xml_earnings :: Maybe Int }
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic AutoRacingResultsListingXml
+instance H.HVector AutoRacingResultsListingXml
instance ToDb AutoRacingResultsListingXml where
-- | The database analogue of an 'AutoRacingResultsListingXml' is
@@ -238,22 +242,7 @@ instance FromXmlFk AutoRacingResultsListingXml where
-- 'AutoRacingResultsListing', we add the foreign key and copy
-- everything else verbatim.
--
- from_xml_fk fk AutoRacingResultsListingXml{..} =
- AutoRacingResultsListing {
- db_auto_racing_results_id = fk,
- db_finish_position = xml_finish_position,
- db_starting_position = xml_starting_position,
- db_car_number = xml_car_number,
- db_driver_id = xml_driver_id,
- db_driver = xml_driver,
- db_car_make = xml_car_make,
- db_points = xml_points,
- db_laps_completed = xml_laps_completed,
- db_laps_leading = xml_laps_leading,
- db_status = xml_status,
- db_dnf = xml_dnf,
- db_nc = xml_nc,
- db_earnings = xml_earnings }
+ from_xml_fk = H.cons
-- | This allows us to insert the XML representation
@@ -351,7 +340,7 @@ instance Child AutoRacingResultsRaceInformationXml where
instance FromXmlFk AutoRacingResultsRaceInformationXml where
-- | To convert an 'AutoRacingResultsRaceInformationXml' to an
-- 'AutoRacingResultsRaceInformartion', we add the foreign key and
- -- copy everything else verbatim.
+ -- massage the 'MostLapsLeading' embedded type,
--
from_xml_fk fk AutoRacingResultsRaceInformationXml{..} =
AutoRacingResultsRaceInformation {
@@ -425,7 +414,7 @@ mkPersist tsn_codegen_config [groundhog|
constructors:
- name: AutoRacingResultsListing
fields:
- - name: db_auto_racing_results_id
+ - name: _db_auto_racing_results_id
reference:
onDelete: cascade
@@ -468,7 +457,7 @@ mkPersist tsn_codegen_config [groundhog|
pickle_listing :: PU AutoRacingResultsListingXml
pickle_listing =
xpElem "Listing" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp13Tuple (xpElem "FinishPosition" xpInt)
(xpElem "StartingPosition" xpInt)
(xpElem "CarNumber" xpInt)
@@ -491,7 +480,7 @@ pickle_listing =
pickle_message :: PU Message
pickle_message =
xpElem "message" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp13Tuple (xpElem "XML_File_ID" xpInt)
(xpElem "heading" xpText)
(xpElem "category" xpText)
@@ -673,7 +662,7 @@ test_on_delete_cascade = testGroup "cascading delete tests"
let c = undefined :: AutoRacingResultsRaceInformation
actual <- withSqliteConn ":memory:" $ runDbConn $ do
- runMigration silentMigrationLogger $ do
+ runMigrationSilent $ do
migrate a
migrate b
migrate c