- dbimport :: (MonadIO m, PersistBackend m)
- => a
- -> XmlTree
- -> m (Maybe Int)
-
-
--- | 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)
- => (a -> [b]) -- ^ listings getter
- -> b -- ^ Dummy Listing instance needed for 'migrate'
- -> XmlTree
- -> m (Maybe Int) -- ^ Return the number of records inserted.
-import_generic g dummy xml = 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)
+ -- | Import an instance of type @a@.
+ dbimport :: (PersistBackend m) => a -> m ImportResult
+
+ -- | This must migrate *all* stuffs that can potentially be
+ -- created/used by the type @a@.
+ dbmigrate :: (MonadIO m, PersistBackend m) => a -> m ()
+
+
+-- | The simplest possible implementation of 'dbimport', for types
+-- which happen to be members of the 'XmlImport' typeclass.
+--
+dbimport_generic :: (XmlImport a, MonadIO m, PersistBackend m)
+ => a
+ -> m ImportResult
+dbimport_generic x = insert_xml x >> return ImportSucceeded
+
+
+-- | A migration runner that will use our normal info reporting
+-- mechanism.
+--
+run_dbmigrate :: (MonadIO m, PersistBackend m) => Migration m -> m ()
+run_dbmigrate =
+ runMigration pretty_migration_logger
+ where
+ pretty_migration_logger x =
+ report_info ("Migration: " ++ x ++ ";")