--- | We put the 'Configuration' and 'XmlTree' arguments last so that
--- it's easy to eta reduce all of the import_foo functions that call
--- this.
---
-import_generic :: (XmlPickler a, MonadIO m, PersistEntity b, PersistBackend m)
- => b -- ^ Dummy Listing instance needed for 'migrate'
- -> (a -> [b]) -- ^ listings getter
- -> XmlTree
- -> m (Maybe Int) -- ^ Return the number of records inserted.
-import_generic dummy g xml = do
- -- Needs NoMonomorphismRestriction to be allowed to return
- -- different types in the two cases above.
- runMigration defaultMigrationLogger $ migrate dummy
- let root_element = unpickleDoc xpickle xml
- case root_element of
- Nothing -> do
- let msg = "Could not unpickle document in import_generic."
- liftIO $ report_error msg
- return Nothing
- Just elt -> do
- ids <- mapM insert (g elt)
- return $ Just (length ids)
-
-
-
--- | Import TSN.News from an 'XmlTree'.
-import_news :: (MonadIO m, PersistBackend m)
- => XmlTree
- -> m (Maybe Int)
-import_news = -- This implementation is wrroooonnnnngggg.
- import_generic
- (undefined :: News.Message)
- (\m -> [m] :: [News.Message]) -- Turn a Message into a [Message]
-
--- | Import TSN.Injuries from an 'XmlTree'.
-import_injuries :: (MonadIO m, PersistBackend m)
- => XmlTree
- -> m (Maybe Int)
-import_injuries =
- import_generic
- (undefined :: Injuries.Listing)
- Injuries.listings
-
--- | Import TSN.InjuriesDetail from an 'XmlTree'.
-import_injuries_detail :: (MonadIO m, PersistBackend m)
- => XmlTree
- -> m (Maybe Int)
-import_injuries_detail =
- import_generic
- (undefined :: InjuriesDetail.PlayerListing)
- ( (concatMap InjuriesDetail.player_listings) . InjuriesDetail.listings)