import Xml ( FromXml(..), ToDb(..), pickle_unpickle, unpickleable )
-
--- | The database type for teams as they show up in the news.
---
-data NewsTeam =
- NewsTeam { team_name :: String }
- deriving (Eq, Show)
-
-
-instance ToDb NewsTeam where
- -- | The database representaion of a 'NewsTeam' is itself.
- type Db NewsTeam = NewsTeam
-
--- | This is needed to define the XmlImport instance for NewsTeam.
---
-instance FromXml NewsTeam where
- -- | How to we get a 'NewsTeam' from itself?
- from_xml = id
-
--- | Allow us to call 'insert_xml' on the XML representation of
--- NewsTeams.
--
-instance XmlImport NewsTeam
-
-
--- | Mapping between News records and NewsTeam records in the
--- database. We don't name the fields because we don't use the names
--- explicitly; that means we have to give them nice database names
--- via groundhog.
+-- DB/XML Data types
--
-data News_NewsTeam = News_NewsTeam
- (DefaultKey News)
- (DefaultKey NewsTeam)
-
-
--- | The database type for locations as they show up in the news.
---
-data NewsLocation =
- NewsLocation {
- city :: Maybe String,
- state :: Maybe String,
- country :: String }
- deriving (Eq, Show)
-
-instance ToDb NewsLocation where
- -- | The database representation of a 'NewsLocation' is itself.
- type Db NewsLocation = NewsLocation
-
--- | This is needed to define the XmlImport instance for NewsLocation.
---
-instance FromXml NewsLocation where
- -- | How to we get a 'NewsLocation' from itself?
- from_xml = id
-
--- | Allow us to call 'insert_xml' on the XML representation of
--- NewsLocations.
---
-instance XmlImport NewsLocation
-
-
--- | Mapping between News records and NewsLocation records in the
--- database. We don't name the fields because we don't use the names
--- explicitly; that means we have to give them nice database names
--- via groundhog.
---
-data News_NewsLocation = News_NewsLocation
- (DefaultKey News)
- (DefaultKey NewsLocation)
+-- * News/Message
-- | The msg_id child of <message> contains an event_id attribute; we
-- embed it into the 'News' type. We (pointlessly) use the "db_"
--
data News =
News {
+ db_xml_file_id :: Int,
db_mid :: MsgId,
db_sport :: String,
db_url :: Maybe String,
-- | We use a record wildcard so GHC doesn't complain that we never
-- used the field names.
--
- from_xml Message{..} = News { db_mid = xml_mid,
+ from_xml Message{..} = News { db_xml_file_id = xml_xml_file_id,
+ db_mid = xml_mid,
db_sport = xml_sport,
db_url = xml_url,
db_sms = xml_sms,
--
instance XmlImport Message
+
+-- * NewsTeam
+
+-- | The database type for teams as they show up in the news.
+--
+data NewsTeam =
+ NewsTeam { team_name :: String }
+ deriving (Eq, Show)
+
+
+instance ToDb NewsTeam where
+ -- | The database representaion of a 'NewsTeam' is itself.
+ type Db NewsTeam = NewsTeam
+
+-- | This is needed to define the XmlImport instance for NewsTeam.
+--
+instance FromXml NewsTeam where
+ -- | How to we get a 'NewsTeam' from itself?
+ from_xml = id
+
+-- | Allow us to call 'insert_xml' on the XML representation of
+-- NewsTeams.
+--
+instance XmlImport NewsTeam
+
+
+
+-- * News_NewsTeam
+
+-- | Mapping between News records and NewsTeam records in the
+-- database. We don't name the fields because we don't use the names
+-- explicitly; that means we have to give them nice database names
+-- via groundhog.
+--
+data News_NewsTeam = News_NewsTeam
+ (DefaultKey News)
+ (DefaultKey NewsTeam)
+
+
+-- * NewsLocation
+
+-- | The database type for locations as they show up in the news.
+--
+data NewsLocation =
+ NewsLocation {
+ city :: Maybe String,
+ state :: Maybe String,
+ country :: String }
+ deriving (Eq, Show)
+
+instance ToDb NewsLocation where
+ -- | The database representation of a 'NewsLocation' is itself.
+ type Db NewsLocation = NewsLocation
+
+-- | This is needed to define the XmlImport instance for NewsLocation.
+--
+instance FromXml NewsLocation where
+ -- | How to we get a 'NewsLocation' from itself?
+ from_xml = id
+
+-- | Allow us to call 'insert_xml' on the XML representation of
+-- NewsLocations.
+--
+instance XmlImport NewsLocation
+
+
+-- * News_NewsLocation
+
+-- | Mapping between News records and NewsLocation records in the
+-- database. We don't name the fields because we don't use the names
+-- explicitly; that means we have to give them nice database names
+-- via groundhog.
+--
+data News_NewsLocation = News_NewsLocation
+ (DefaultKey News)
+ (DefaultKey NewsLocation)
+
+
+
+--
+-- Database code
+--
+
-- | Define 'dbmigrate' and 'dbimport' for 'Message's. The import is
-- slightly non-generic because of our 'News_NewsTeam' and
-- 'News_NewsLocation' join tables.
dbName: news
constructors:
- name: News
+ uniques:
+ - name: unique_news
+ type: constraint
+ # Prevent multiple imports of the same message.
+ fields: [db_xml_file_id]
fields:
- name: db_mid
embeddedType:
- {name: msg_id, dbName: msg_id}
- {name: event_id, dbName: event_id}
+
- embedded: MsgId
fields:
- name: db_msg_id
- name: db_event_id
dbName: event_id
-
- entity: News_NewsTeam
dbName: news__news_teams
constructors:
onDelete: cascade
|]
+--
+-- XML Picklers
+--
-- | Convert a 'NewsTeam' to/from XML.
--