From: Michael Orlitzky Date: Sat, 11 Jan 2014 07:07:35 +0000 (-0500) Subject: Add missing TSN.XmlImport module. X-Git-Tag: 0.0.1~99 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=e1344533476e1d8111d4228941e0a46ae34e9055;p=dead%2Fhtsn-import.git Add missing TSN.XmlImport module. --- diff --git a/src/TSN/XmlImport.hs b/src/TSN/XmlImport.hs new file mode 100644 index 0000000..3791ab5 --- /dev/null +++ b/src/TSN/XmlImport.hs @@ -0,0 +1,28 @@ +{-# 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)