X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;ds=sidebyside;f=src%2FTSN%2FXML%2FAutoRacingResults.hs;h=370ae8174c59a52992ac78eed3efebfb009e9bde;hb=bc69a69bcd68d8fc7de87507e53b689668e1e3d6;hp=96433ee0e7638efd31c257e61e812b12776c4970;hpb=f131e49033be01a131234ea12a0864d6e719a520;p=dead%2Fhtsn-import.git
diff --git a/src/TSN/XML/AutoRacingResults.hs b/src/TSN/XML/AutoRacingResults.hs
index 96433ee..370ae81 100644
--- a/src/TSN/XML/AutoRacingResults.hs
+++ b/src/TSN/XML/AutoRacingResults.hs
@@ -60,9 +60,10 @@ import Text.XML.HXT.Core (
import TSN.Codegen (
tsn_codegen_config )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
-import TSN.Picklers ( xp_earnings, xp_racedate, xp_time_stamp )
+import TSN.Picklers ( xp_earnings, xp_datetime, xp_time_stamp )
import TSN.XmlImport ( XmlImport(..), XmlImportFk(..) )
import Xml (
+ Child(..),
FromXml(..),
FromXmlFk(..),
ToDb(..),
@@ -162,7 +163,7 @@ instance XmlImport Message
-- * AutoRacingResultsListing/AutoRacingResultsListingXml
-- | Database representation of a \
contained within a
--- \.
+-- \.
--
data AutoRacingResultsListing =
AutoRacingResultsListing {
@@ -210,12 +211,14 @@ instance ToDb AutoRacingResultsListingXml where
type Db AutoRacingResultsListingXml = AutoRacingResultsListing
-instance FromXmlFk AutoRacingResultsListingXml where
+instance Child AutoRacingResultsListingXml where
-- | Each 'AutoRacingResultsListingXml' is contained in (i.e. has a
-- foreign key to) a 'AutoRacingResults'.
--
type Parent AutoRacingResultsListingXml = AutoRacingResults
+
+instance FromXmlFk AutoRacingResultsListingXml where
-- | To convert an 'AutoRacingResultsListingXml' to an
-- 'AutoRacingResultsListing', we add the foreign key and copy
-- everything else verbatim.
@@ -261,13 +264,13 @@ data MostLapsLeading =
deriving (Data, Eq, Show, Typeable)
--- | Database representation of a \ contained within a
--- \.
+-- | Database representation of a \ contained
+-- within a \.
--
data AutoRacingResultsRaceInformation =
AutoRacingResultsRaceInformation {
-- Note the apostrophe to disambiguate it from the
- -- AutoRacingResultsListing filed.
+ -- AutoRacingResultsListing field.
db_auto_racing_results_id' :: DefaultKey AutoRacingResults,
db_track_length :: Double,
db_track_length_kph :: Double,
@@ -311,12 +314,15 @@ instance ToDb AutoRacingResultsRaceInformationXml where
type Db AutoRacingResultsRaceInformationXml =
AutoRacingResultsRaceInformation
-instance FromXmlFk AutoRacingResultsRaceInformationXml where
+
+instance Child AutoRacingResultsRaceInformationXml where
-- | Each 'AutoRacingResultsRaceInformationXml' is contained in
-- (i.e. has a foreign key to) a 'AutoRacingResults'.
--
type Parent AutoRacingResultsRaceInformationXml = AutoRacingResults
+
+instance FromXmlFk AutoRacingResultsRaceInformationXml where
-- | To convert an 'AutoRacingResultsRaceInformationXml' to an
-- 'AutoRacingResultsRaceInformartion', we add the foreign key and
-- copy everything else verbatim.
@@ -391,13 +397,16 @@ mkPersist tsn_codegen_config [groundhog|
reference:
onDelete: cascade
-
+# Note the apostrophe in the foreign key. This is to disambiguate
+# it from the AutoRacingResultsListing foreign key of the same name.
+# We strip it out of the dbName.
- entity: AutoRacingResultsRaceInformation
dbName: auto_racing_results_race_information
constructors:
- name: AutoRacingResultsRaceInformation
fields:
- name: db_auto_racing_results_id'
+ dbName: auto_racing_results_id
reference:
onDelete: cascade
- name: db_most_laps_leading
@@ -469,7 +478,7 @@ pickle_message =
(xpElem "category" xpText)
(xpElem "sport" xpText)
(xpElem "RaceID" xpInt)
- (xpElem "RaceDate" xp_racedate)
+ (xpElem "RaceDate" xp_datetime)
(xpElem "Title" xpText)
(xpElem "Track_Location" xpText)
(xpElem "Laps_Remaining" xpInt)
@@ -519,7 +528,7 @@ pickle_race_information =
xpWrap (from_tuple, to_tuple) $
xp11Tuple (-- I can't think of another way to get both the
-- TrackLength and its KPH attribute. So we shove them
- -- both in a 2-tuple.
+ -- both in a 2-tuple. This should probably be an embedded type!
xpElem "TrackLength" $ xpPair xpPrim (xpAttr "KPH" xpPrim) )
(xpElem "Laps" xpInt)
(xpOption $ xpElem "AverageSpeedMPH" xpPrim)