- -> IO (Maybe Int) -- ^ Return the number of records inserted.
-import_generic dummy g xml =
- withSqliteConn "foo.sqlite3" $ runDbConn $ do
- runMigration defaultMigrationLogger $ do
- 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 (\l -> insert l) (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]