where
-- System imports
-import Control.Monad ( forM_ )
+import Control.Monad ( forM_, join )
import Data.List ( intercalate )
import Data.String.Utils ( split )
import Data.Time ( UTCTime(..) )
import Data.Tuple.Curry ( uncurryN )
+import qualified Data.Vector.HFixed as H ( HVector, convert )
import Database.Groundhog (
countAll,
deleteAll,
- migrate,
- runMigration,
- silentMigrationLogger )
+ migrate )
import Database.Groundhog.Core ( DefaultKey )
-import Database.Groundhog.Generic ( runDbConn )
+import Database.Groundhog.Generic ( runDbConn, runMigrationSilent )
import Database.Groundhog.Sqlite ( withSqliteConn )
import Database.Groundhog.TH (
groundhog,
-- Local imports
-import Generics ( Generic(..), to_tuple )
+import Misc ( double_just )
import TSN.Codegen ( tsn_codegen_config )
import TSN.Database ( insert_or_select )
import TSN.DbImport ( DbImport(..), ImportResult(..), run_dbmigrate )
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic Message
+instance H.HVector Message
instance ToDb Message where
deriving (Eq, GHC.Generic, Show)
--- | For 'Generics.to_tuple'.
+-- | For 'H.convert'.
--
-instance Generic JFileGameXml
+instance H.HVector JFileGameXml
-- * JFileGameListXml
pickle_message :: PU Message
pickle_message =
xpElem "message" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, H.convert) $
xp6Tuple (xpElem "XML_File_ID" xpInt)
(xpElem "heading" xpText)
(xpElem "category" xpText)
pickle_game :: PU JFileGameXml
pickle_game =
xpElem "game" $
- xpWrap (from_tuple, to_tuple) $
+ xpWrap (from_tuple, to_tuple') $
xp14Tuple (xpElem "game_id" xpInt)
(xpElem "schedule_id" xpInt)
pickle_odds_info
(xpElem "Game_Date" xp_date_padded)
(xpElem "Game_Time" xp_tba_time)
pickle_away_team
- (xpOption $ xpElem "vleague" xpText)
+ (xpOption $ xpElem "vleague" (xpOption xpText))
pickle_home_team
(xpOption $ xpElem "hleague" xpText)
(xpElem "vscore" xpInt)
(xpOption $ xpElem "time_r" xpText)
pickle_status
where
- from_tuple = uncurryN JFileGameXml
+ from_tuple (a,b,c,d,e,f,g,h,i,j,k,l,m,n) =
+ JFileGameXml a b c d e f g (join h) i j k l m n
+
+ to_tuple' (JFileGameXml a b c d e f g h i j k l m n) =
+ (a, b, c, d, e, f, g, double_just h, i, j, k, l, m, n)
pickle_odds_info :: PU JFileGameOddsInfo
(xpOption xpText) -- Yup, some are nameless
where
from_tuple = HTeam . (uncurryN Team)
- to_tuple' (HTeam t) = to_tuple t
+ to_tuple' (HTeam t) = H.convert t
-- | (Un)pickle an away team to/from the dual XML/DB representation
(xpOption xpText) -- Yup, some are nameless
where
from_tuple = VTeam . (uncurryN Team)
- to_tuple' (VTeam t) = to_tuple t
+ to_tuple' (VTeam t) = H.convert t
pickle_status :: PU JFileGameStatus
let c = undefined :: JFileGame
actual <- withSqliteConn ":memory:" $ runDbConn $ do
- runMigration silentMigrationLogger $ do
+ runMigrationSilent $ do
migrate a
migrate b
migrate c