From cc8f953bcec4e464052b3508f378711ae6df2caf Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 5 Jul 2014 19:27:20 -0400 Subject: [PATCH] New module: TSN.Location. --- .ghci | 2 ++ htsn-import.cabal | 1 + src/TSN/Location.hs | 54 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/TSN/Location.hs diff --git a/.ghci b/.ghci index e03be18..4e0462c 100644 --- a/.ghci +++ b/.ghci @@ -12,6 +12,7 @@ src/TSN/Codegen.hs src/TSN/Database.hs src/TSN/DbImport.hs + src/TSN/Location.hs src/TSN/Parse.hs src/TSN/Picklers.hs src/TSN/Team.hs @@ -41,6 +42,7 @@ import OptionalConfiguration import TSN.Codegen import TSN.Database import TSN.DbImport +import TSN.Location import TSN.Parse import TSN.Picklers import TSN.Team diff --git a/htsn-import.cabal b/htsn-import.cabal index 928ff54..9d87697 100644 --- a/htsn-import.cabal +++ b/htsn-import.cabal @@ -262,6 +262,7 @@ executable htsn-import TSN.Codegen TSN.Database TSN.DbImport + TSN.Location TSN.Parse TSN.Picklers TSN.Team diff --git a/src/TSN/Location.hs b/src/TSN/Location.hs new file mode 100644 index 0000000..1097d93 --- /dev/null +++ b/src/TSN/Location.hs @@ -0,0 +1,54 @@ +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeFamilies #-} + +-- | (At least) two different XML types have a notion of locations: +-- "TSN.XML.News" and "TSN.XML.Scores". And in fact those two types +-- agree on the city, state, and country -- at least for the +-- database representation. +-- +-- This module contains a data type for the common database +-- representation. +-- +module TSN.Location ( + Location(..), + LocationConstructor(..) ) +where + +-- System imports +import Database.Groundhog () -- Required for some String instance +import Database.Groundhog.TH ( + defaultCodegenConfig, + groundhog, + mkPersist ) + + +-- | Database representation of a location. +-- +-- The country has always been present in the XML that we've +-- seen. The city/state however have been observed missing in some +-- cases. The Scores are better about always having a city/state, +-- but in the interest of consolidation, we've made them optional so +-- that they can be mushed together into this one type. +-- +data Location = + Location { + city :: Maybe String, + state :: Maybe String, + country :: String } + deriving (Eq, Show) + + +-- Generate the Groundhog code for 'Location'. +mkPersist defaultCodegenConfig [groundhog| +- entity: Location + dbName: locations + constructors: + - name: Location + uniques: + - name: unique_location + type: constraint + fields: [city, state, country] +|] -- 2.44.2