--- /dev/null
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE GADTs #-}
+
+module TSN.XmlImport (
+ XmlImport(..) )
+where
+
+import Database.Groundhog (
+ AutoKey,
+ insert,
+ insertByAll )
+import Database.Groundhog.Core ( PersistBackend, PersistEntity )
+
+import Xml ( FromXml(..) )
+
+
+class (FromXml a, PersistEntity (Db a)) => XmlImport a where
+ -- | This is similar to the signature for Groundhog's 'insert'
+ -- function, except the 'AutoKey' we return is for our 'Db'
+ -- counterpart.
+ insert_xml :: (PersistBackend m) => a -> m (AutoKey (Db a))
+ insert_xml x = insert (from_xml x)
+
+ -- | Same rationale as 'insert_xml', except it uses 'insertByAll'.
+ insertByAll_xml :: (PersistBackend m)
+ => a
+ -> m ( Either (AutoKey (Db a)) (AutoKey (Db a)) )
+ insertByAll_xml x = insertByAll (from_xml x)