Don't save the default <message> fields along with the news.
Make the makefile a little more accurate.
PN = htsn-import
BIN = dist/build/$(PN)/$(PN)
TESTSUITE_BIN = dist/build/testsuite/testsuite
+SRCS := $(shell find src/ -type f -name '*.hs')
+TEST_SRCS := $(shell find test/ -type f -name '*.hs')
.PHONY : dist hlint
-$(BIN): $(PN).cabal src/*.hs src/TSN/*.hs
+$(BIN): $(PN).cabal $(SRCS)
runghc Setup.hs clean
runghc Setup.hs configure --user --prefix=/
runghc Setup.hs build
-profile: $(PN).cabal src/*.hs src/TSN/*.hs
+profile: $(PN).cabal $(SRCS)
runghc Setup.hs clean
runghc Setup.hs configure --user --enable-executable-profiling --prefix=/
runghc Setup.hs build
-doc: $(PN).cabal src/*.hs src/TSN/*.hs
+doc: $(PN).cabal $(SRCS)
runghc Setup.hs configure --user --prefix=/
runghc Setup.hs hscolour --executables
runghc Setup.hs haddock --internal \
rm -f *.xml
rm -rf tmp
-$(TESTSUITE_BIN): $(PN).cabal src/*.hs test/TestSuite.hs
+$(TESTSUITE_BIN): $(PN).cabal $(SRCS) $(TEST_SRCS)
runghc Setup.hs configure --user --enable-tests --prefix=/
runghc Setup.hs build
report_info,
report_error )
import TSN.DbImport
-import qualified TSN.Injuries as Injuries ( Listing )
-import qualified TSN.InjuriesDetail as InjuriesDetail ( PlayerListing )
-import qualified TSN.News as News ( Message )
+import qualified TSN.XML.Injuries as Injuries ( Listing )
+import qualified TSN.XML.InjuriesDetail as InjuriesDetail ( PlayerListing )
+import qualified TSN.XML.News as News ( Message )
import Xml ( parse_opts )
-- The listings will be mapped to a database table called "injuries"
-- automatically. The root message is not retained.
--
-module TSN.Injuries (
+module TSN.XML.Injuries (
Listing,
Message( listings ),
injuries_tests )
-- "injuries_detail" automatically. The root "message" and "listing"
-- are not retained.
--
-module TSN.InjuriesDetail (
+module TSN.XML.InjuriesDetail (
Listing ( player_listings ),
Message ( listings ),
PlayerListing,
-- | Parse TSN XML for the DTD "newsxml.dtd". Each document contains a
-- root element \<message\> that contains an entire news item.
--
-module TSN.News (
+module TSN.XML.News (
Message,
news_tests )
where
data Message =
Message {
- db_xml_file_id :: Int,
- db_heading :: String,
db_mid :: MsgId,
- db_category :: String,
db_sport :: String,
db_url :: String,
db_sms :: String,
db_text :: String,
- db_continue :: String,
- db_time_stamp :: String }
+ db_continue :: String }
deriving (Eq, Show)
instance ToFromXml Message where
-- used our named fields.
to_xml (Message {..}) =
MessageXml
- db_xml_file_id
- db_heading
+ 0
+ ""
db_mid
- db_category
+ ""
db_sport
db_url
[]
db_sms
db_text
db_continue
- db_time_stamp
+ ""
-- We don't need the key argument (from_xml_fk) since the XML type
-- contains more information in this case.
- from_xml (MessageXml a b c d e f _ _ g h i j) =
- Message a b c d e f g h i j
+ from_xml (MessageXml _ _ c _ e f _ _ g h i _) =
+ Message c e f g h i
mkPersist tsn_codegen_config [groundhog|
import Test.Tasty ( TestTree, defaultMain, testGroup )
-import TSN.Injuries ( injuries_tests )
-import TSN.InjuriesDetail ( injuries_detail_tests )
-import TSN.News ( news_tests )
+import TSN.XML.Injuries ( injuries_tests )
+import TSN.XML.InjuriesDetail ( injuries_detail_tests )
+import TSN.XML.News ( news_tests )
tests :: TestTree
tests = testGroup