-- | Definition of the DbImport typeclass. module TSN.DbImport where import Control.Monad.IO.Class ( MonadIO ) import Database.Groundhog.Core ( PersistBackend ) import TSN.XmlImport ( XmlImport(..) ) -- | The type that will be returned from every file import attempt. -- data ImportResult = ImportFailed String -- ^ Failure with an error message. | ImportSkipped String -- ^ We processed the file, but didn't import it. -- The reason is contained in the second field. | ImportSucceeded -- ^ We did import records. | ImportUnsupported String -- ^ We didn't know how to process this file. -- The second field should contain info. -- | Instances of this type know how to insert themselves into a -- Groundhog database. -- class DbImport a where -- | 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 () dbimport_generic :: (XmlImport a, MonadIO m, PersistBackend m) => a -> m ImportResult dbimport_generic x = insert_xml x >> return ImportSucceeded