1 -- | Definition of the DbImport typeclass.
5 import Control.Monad.IO.Class ( MonadIO )
6 import Database.Groundhog.Core ( PersistBackend )
8 import TSN.XmlImport ( XmlImport(..) )
10 -- | The type that will be returned from every file import attempt.
13 ImportFailed String -- ^ Failure with an error message.
14 | ImportSkipped String -- ^ We processed the file, but didn't import it.
15 -- The reason is contained in the second field.
16 | ImportSucceeded -- ^ We did import records.
17 | ImportUnsupported String -- ^ We didn't know how to process this file.
18 -- The second field should contain info.
20 -- | Instances of this type know how to insert themselves into a
21 -- Groundhog database.
23 class DbImport a where
24 -- | Import an instance of type @a@.
25 dbimport :: (PersistBackend m) => a -> m ImportResult
27 -- | This must migrate *all* stuffs that can potentially be
28 -- created/used by the type @a@.
29 dbmigrate :: (MonadIO m, PersistBackend m) => a -> m ()
31 dbimport_generic :: (XmlImport a, MonadIO m, PersistBackend m)
34 dbimport_generic x = insert_xml x >> return ImportSucceeded