]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/TSN/Team.hs
Fix the TSN.Team unique constraint name.
[dead/htsn-import.git] / src / TSN / Team.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 teams:
8 -- "TSN.XML.Odds" and "TSN.XML.JFile". And in fact those two types
9 -- agree on the team id, abbreviation, and name -- 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.Team (
16 Team(..),
17 -- * WARNING: these are private but exported to silence warnings
18 TeamConstructor(..) )
19 where
20
21 -- System imports
22 import Database.Groundhog () -- Required for some String instance
23 import Database.Groundhog.TH (
24 defaultCodegenConfig,
25 groundhog,
26 mkPersist )
27
28
29 -- | The database representation of a team. The 'team_id' is a
30 -- 'String' field because some teams do in fact have ids like
31 -- \"B52\". The pointless \"team_\" prefix is left on the 'team_id'
32 -- field because otherwise the auto-generated column name would
33 -- conflict with the default \"id\" primary key.
34 --
35 data Team =
36 Team {
37 team_id :: String, -- ^ Some of them contain characters
38 abbreviation :: Maybe String, -- ^ Some teams don't have abbreviations,
39 -- or at least, some sample jfilexml
40 -- don't have them for some teams.
41 name :: Maybe String -- ^ Some teams don't even have names!
42 }
43 deriving (Eq, Show)
44
45
46 -- Generate the Groundhog code for 'Team'.
47 mkPersist defaultCodegenConfig [groundhog|
48 - entity: Team
49 dbName: teams
50 constructors:
51 - name: Team
52 uniques:
53 - name: unique_team
54 type: constraint
55 fields: [team_id]
56 |]