{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE OverloadedStrings #-} module Main where --import Control.Monad.IO.Class ( liftIO ) import Data.Maybe ( listToMaybe ) --import Database.Groundhog.TH --import Database.Groundhog.Sqlite import Text.Show.Pretty ( ppShow ) import Text.XML.HXT.Core ( SysConfigList, XmlPickler, no, runX, withPreserveComment, withRemoveWS, withValidate, xpickle, xunpickleDocument, yes ) import qualified TSN.Injuries as Injuries ( Message ) import qualified TSN.InjuriesDetail as InjuriesDetail ( Message ) parse_opts :: SysConfigList parse_opts = [ withPreserveComment no, withRemoveWS yes, withValidate no ] parse_file :: XmlPickler a => FilePath -> IO (Maybe a) parse_file path = fmap listToMaybe $ runX ( xunpickleDocument xpickle parse_opts path ) -- main_sql :: IO () -- main_sql = -- withSqliteConn "foo.sqlite3" $ runDbConn $ do -- runMigration defaultMigrationLogger $ do -- migrate (undefined :: Injuries.Message) -- migrate (undefined :: Injuries.Listing) -- msg :: Maybe Injuries.Message <- liftIO $ parse_file -- "test/xml/injuriesxml.xml" -- case msg of -- Nothing -> return () -- Just m -> do -- msg_id <- insert m -- return () main :: IO () main = do msg1 :: Maybe Injuries.Message <- parse_file "test/xml/injuriesxml.xml" putStr $ ppShow msg1 msg2 :: Maybe InjuriesDetail.Message <- parse_file "test/xml/Injuries_Detail_XML.xml" putStr $ ppShow msg2