]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/TSN/Location.hs
New module: TSN.Location.
[dead/htsn-import.git] / src / TSN / Location.hs
1 {-# LANGUAGE FlexibleInstances #-}
2 {-# LANGUAGE GADTs #-}
3 {-# LANGUAGE QuasiQuotes #-}
4 {-# LANGUAGE TemplateHaskell #-}
5 {-# LANGUAGE TypeFamilies #-}
6
7 -- | (At least) two different XML types have a notion of locations:
8 -- "TSN.XML.News" and "TSN.XML.Scores". And in fact those two types
9 -- agree on the city, state, and country -- at least for the
10 -- database representation.
11 --
12 -- This module contains a data type for the common database
13 -- representation.
14 --
15 module TSN.Location (
16 Location(..),
17 LocationConstructor(..) )
18 where
19
20 -- System imports
21 import Database.Groundhog () -- Required for some String instance
22 import Database.Groundhog.TH (
23 defaultCodegenConfig,
24 groundhog,
25 mkPersist )
26
27
28 -- | Database representation of a location.
29 --
30 -- The country has always been present in the XML that we've
31 -- seen. The city/state however have been observed missing in some
32 -- cases. The Scores are better about always having a city/state,
33 -- but in the interest of consolidation, we've made them optional so
34 -- that they can be mushed together into this one type.
35 --
36 data Location =
37 Location {
38 city :: Maybe String,
39 state :: Maybe String,
40 country :: String }
41 deriving (Eq, Show)
42
43
44 -- Generate the Groundhog code for 'Location'.
45 mkPersist defaultCodegenConfig [groundhog|
46 - entity: Location
47 dbName: locations
48 constructors:
49 - name: Location
50 uniques:
51 - name: unique_location
52 type: constraint
53 fields: [city, state, country]
54 |]