]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blob - src/TSN/DbImport.hs
Rewrite everything to use XmlImport/DbImport classes making things much more easy...
[dead/htsn-import.git] / src / TSN / DbImport.hs
1 -- | Definition of the DbImport typeclass.
2 module TSN.DbImport
3 where
4
5 import Control.Monad.IO.Class ( MonadIO )
6 import Database.Groundhog.Core ( PersistBackend )
7
8 import TSN.XmlImport ( XmlImport(..) )
9
10 -- | The type that will be returned from every file import attempt.
11 --
12 data ImportResult =
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.
19
20 -- | Instances of this type know how to insert themselves into a
21 -- Groundhog database.
22 --
23 class DbImport a where
24 -- | Import an instance of type @a@.
25 dbimport :: (PersistBackend m) => a -> m ImportResult
26
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 ()
30
31 dbimport_generic :: (XmlImport a, MonadIO m, PersistBackend m)
32 => a
33 -> m ImportResult
34 dbimport_generic x = insert_xml x >> return ImportSucceeded