From e1344533476e1d8111d4228941e0a46ae34e9055 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 11 Jan 2014 02:07:35 -0500 Subject: [PATCH] Add missing TSN.XmlImport module. --- src/TSN/XmlImport.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/TSN/XmlImport.hs 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) -- 2.43.2