X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTSN%2FXML%2FAutoRacingDriverList.hs;h=482c1f3835699f30fcff5a1716714353d4890e8f;hb=073bbfba4165d4c01d29daaa7523c35c6cc7d114;hp=9d9e090a662fe96da230e8ff9d57422c6597d307;hpb=1f04fd8786215141dad63099dc6f48d17b7ac96c;p=dead%2Fhtsn-import.git
diff --git a/src/TSN/XML/AutoRacingDriverList.hs b/src/TSN/XML/AutoRacingDriverList.hs
index 9d9e090..482c1f3 100644
--- a/src/TSN/XML/AutoRacingDriverList.hs
+++ b/src/TSN/XML/AutoRacingDriverList.hs
@@ -25,14 +25,13 @@ where
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,
@@ -52,7 +51,6 @@ import Text.XML.HXT.Core (
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, xp_time_stamp )
@@ -106,9 +104,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
@@ -143,46 +141,47 @@ instance XmlImport Message
-- AutoRacingDriverListListing / AutoRacingDriverListListingXml
-- | Database representation of a \
contained within a
--- \.
+-- \. The leading underscores prevent unused field
+-- warnings.
--
data AutoRacingDriverListListing =
AutoRacingDriverListListing {
- db_auto_racing_driver_lists_id :: DefaultKey AutoRacingDriverList,
- db_driver_id :: Int,
- db_driver :: String,
- db_height :: Maybe String,
- db_weight :: Int,
- db_date_of_birth :: UTCTime,
- db_hometown :: String,
- db_nationality :: Maybe String,
- db_car_number :: Int,
- db_car :: String }
+ _db_auto_racing_driver_lists_id :: DefaultKey AutoRacingDriverList,
+ _db_driver_id :: Int,
+ _db_driver :: String,
+ _db_height :: Maybe String,
+ _db_weight :: Int,
+ _db_date_of_birth :: UTCTime,
+ _db_hometown :: String,
+ _db_nationality :: Maybe String,
+ _db_car_number :: Int,
+ _db_car :: String }
deriving ( GHC.Generic )
--- | For 'Generics.prepend'.
+-- | For 'H.convert'.
--
-instance Generic AutoRacingDriverListListing
+instance H.HVector AutoRacingDriverListListing
-- | XML representation of a \ contained within a
--- \.
+-- \. The underscores prevent unused field warnings.
--
data AutoRacingDriverListListingXml =
AutoRacingDriverListListingXml {
- xml_driver_id :: Int,
- xml_driver :: String,
- xml_height :: Maybe String,
- xml_weight :: Int,
- xml_date_of_birth :: UTCTime,
- xml_hometown :: String,
- xml_nationality :: Maybe String,
- xml_car_number :: Int,
- xml_car :: String }
+ _xml_driver_id :: Int,
+ _xml_driver :: String,
+ _xml_height :: Maybe String,
+ _xml_weight :: Int,
+ _xml_date_of_birth :: UTCTime,
+ _xml_hometown :: String,
+ _xml_nationality :: Maybe String,
+ _xml_car_number :: Int,
+ _xml_car :: String }
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert' and 'H.cons'.
--
-instance Generic AutoRacingDriverListListingXml
+instance H.HVector AutoRacingDriverListListingXml
instance ToDb AutoRacingDriverListListingXml where
-- | The database analogue of an 'AutoRacingDriverListListingXml' is
@@ -203,7 +202,7 @@ instance FromXmlFk AutoRacingDriverListListingXml where
-- 'AutoRacingDriverListListing', we add the foreign key and copy
-- everything else verbatim.
--
- from_xml_fk = prepend
+ from_xml_fk = H.cons
@@ -250,7 +249,7 @@ mkPersist tsn_codegen_config [groundhog|
constructors:
- name: AutoRacingDriverListListing
fields:
- - name: db_auto_racing_driver_lists_id
+ - name: _db_auto_racing_driver_lists_id
reference:
onDelete: cascade
@@ -266,7 +265,7 @@ mkPersist tsn_codegen_config [groundhog|
pickle_listing :: PU AutoRacingDriverListListingXml
pickle_listing =
xpElem "Listing" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp9Tuple (xpElem "DriverID" xpInt)
(xpElem "Driver" xpText)
(xpElem "Height" $ xpOption xpText)
@@ -284,7 +283,7 @@ pickle_listing =
pickle_message :: PU Message
pickle_message =
xpElem "message" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp7Tuple (xpElem "XML_File_ID" xpInt)
(xpElem "heading" xpText)
(xpElem "category" xpText)
@@ -353,7 +352,7 @@ test_on_delete_cascade = testGroup "cascading delete tests"
let b = undefined :: AutoRacingDriverListListing
actual <- withSqliteConn ":memory:" $ runDbConn $ do
- runMigration silentMigrationLogger $ do
+ runMigrationSilent $ do
migrate a
migrate b
_ <- dbimport results