]> gitweb.michael.orlitzky.com - dead/htsn-import.git/commitdiff
New module: TSN.Location.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 5 Jul 2014 23:27:20 +0000 (19:27 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 5 Jul 2014 23:27:20 +0000 (19:27 -0400)
.ghci
htsn-import.cabal
src/TSN/Location.hs [new file with mode: 0644]

diff --git a/.ghci b/.ghci
index e03be18bce43c485ff8912304ff032e4a5b2e49e..4e0462cc0580313ed516624b12ce606e20f0933b 100644 (file)
--- 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
index 928ff5465caead42ad90da8be47e618e7f05d8b1..9d87697171b45a838cd36dec46ea38e8976b4fe6 100644 (file)
@@ -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 (file)
index 0000000..1097d93
--- /dev/null
@@ -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]
+|]