- -> IO (Maybe Int) -- ^ Return the number of records inserted.
-import_generic dummy g cfg xml
- | backend cfg == Postgres = withPostgresqlConn cs go
- | otherwise = withSqliteConn cs go
- where
- -- | Pull the real connection String out of the configuration.
- cs :: String
- cs = get_connection_string $ connection_string cfg
-
- -- Needs NoMonomorphismRestriction to be allowed to return
- -- different types in the two cases above.
- go = runDbConn $ do
- 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)
-
-
+ -> 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]