From: Michael Orlitzky Date: Fri, 2 Jan 2015 18:39:27 +0000 (-0500) Subject: Use Generics.prepend in TSN.XML.AutoRacingSchedule. X-Git-Tag: 0.2.1~27 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=52b420301965efe58a60672832c93b5046695cd0;p=dead%2Fhtsn-import.git Use Generics.prepend in TSN.XML.AutoRacingSchedule. --- diff --git a/src/TSN/XML/AutoRacingSchedule.hs b/src/TSN/XML/AutoRacingSchedule.hs index d4a726b..1cbcbc1 100644 --- a/src/TSN/XML/AutoRacingSchedule.hs +++ b/src/TSN/XML/AutoRacingSchedule.hs @@ -1,3 +1,4 @@ + {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} @@ -55,7 +56,7 @@ import Text.XML.HXT.Core ( xpWrap ) -- Local imports. -import Generics ( Generic(..), to_tuple ) +import Generics ( Generic(..), prepend, to_tuple ) import TSN.Codegen ( tsn_codegen_config ) import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate ) @@ -266,33 +267,40 @@ newtype AutoRacingScheduleListingRaceResult = -- | Database representation of \ within -- \ within \ within... \! +-- The leading underscores prevent unused field warnings. -- data AutoRacingScheduleListingRaceResultRaceResultListing = AutoRacingScheduleListingRaceResultRaceResultListing { - db_auto_racing_schedules_listings_id :: + _db_auto_racing_schedules_listings_id :: DefaultKey AutoRacingScheduleListing, - db_finish_position :: Int, - db_driver_id :: Int, - db_name :: String, - db_leading_laps :: Int, - db_listing_laps :: Int, -- ^ Avoid clash with race's \"laps\" field. - db_earnings :: String, -- ^ This should be an Int, but can have commas. - db_status :: Maybe String -- ^ They can be empty + _db_finish_position :: Int, + _db_driver_id :: Int, + _db_name :: String, + _db_leading_laps :: Int, + _db_listing_laps :: Int, -- ^ Avoid clash with race's \"laps\" field. + _db_earnings :: String, -- ^ This should be an Int, but can have commas. + _db_status :: Maybe String -- ^ They can be empty } + deriving ( GHC.Generic ) + +-- | For 'Generics.prepend'. +-- +instance Generic AutoRacingScheduleListingRaceResultRaceResultListing -- | XML Representation of an -- 'AutoRacingScheduleListingRaceResultRaceResultListing'. +-- The leading underscores prevent unused field warnings. -- data AutoRacingScheduleListingRaceResultRaceResultListingXml = AutoRacingScheduleListingRaceResultRaceResultListingXml { - xml_finish_position :: Int, - xml_driver_id :: Int, - xml_name :: String, - xml_leading_laps :: Int, - xml_listing_laps :: Int, -- ^ Avoid clash with race's \"laps\" field. - xml_earnings :: String, -- ^ Should be an 'Int', but can have commas. - xml_status :: Maybe String -- ^ They can be empty + _xml_finish_position :: Int, + _xml_driver_id :: Int, + _xml_name :: String, + _xml_leading_laps :: Int, + _xml_listing_laps :: Int, -- ^ Avoids clash with race's \"laps\" field. + _xml_earnings :: String, -- ^ Should be an 'Int', but can have commas. + _xml_status :: Maybe String -- ^ They can be empty } deriving (Eq, GHC.Generic, Show) @@ -326,16 +334,7 @@ instance FromXmlFk AutoRacingScheduleListingRaceResultRaceResultListingXml where -- 'AutoRacingScheduleListingRaceResultRaceResultListing', we just -- add the foreign key to the parent 'AutoRacingScheduleListing'. -- - from_xml_fk fk AutoRacingScheduleListingRaceResultRaceResultListingXml{..} = - AutoRacingScheduleListingRaceResultRaceResultListing { - db_auto_racing_schedules_listings_id = fk, - db_finish_position = xml_finish_position, - db_driver_id = xml_driver_id, - db_name = xml_name, - db_leading_laps = xml_leading_laps, - db_listing_laps = xml_listing_laps, - db_earnings = xml_earnings, - db_status = xml_status } + from_xml_fk = prepend -- | This allows us to insert the XML representation @@ -397,7 +396,7 @@ mkPersist tsn_codegen_config [groundhog| constructors: - name: AutoRacingScheduleListingRaceResultRaceResultListing fields: - - name: db_auto_racing_schedules_listings_id + - name: _db_auto_racing_schedules_listings_id reference: onDelete: cascade |]