From 56975146edfa660670d29531b6a368ba29fe384c Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 2 Jan 2015 12:59:59 -0500 Subject: [PATCH] Use Generics.prepend in TSN.XML.AutoRacingResults. --- src/TSN/XML/AutoRacingResults.hs | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/TSN/XML/AutoRacingResults.hs b/src/TSN/XML/AutoRacingResults.hs index 40e199f..9acbe01 100644 --- a/src/TSN/XML/AutoRacingResults.hs +++ b/src/TSN/XML/AutoRacingResults.hs @@ -61,7 +61,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 ) import TSN.Picklers ( @@ -193,7 +193,11 @@ data AutoRacingResultsListing = db_dnf :: Maybe Bool, db_nc :: Maybe Bool, db_earnings :: Maybe Int } + deriving ( GHC.Generic ) +-- | For 'Generics.prepend'. +-- +instance Generic AutoRacingResultsListing -- | XML representation of a \ contained within a -- \. @@ -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 = prepend -- | 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 { -- 2.44.2