Skip to content

Commit

Permalink
Removed unwanted comments + Added fixed variable
Browse files Browse the repository at this point in the history
  • Loading branch information
beingfranklin committed Dec 7, 2020
1 parent 50f16ad commit 67b2691
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ main = do
let converRes = sqlRowToString res
mapM_ putStrLn converRes
putStrLn "\n****************"
-- TODO JSON Conversion code is below
-- TODO - JSON Conversion code is below
-- sqlValue <- getUnprocessedSQLHolidays conn
-- print $ show sqlValue
-- print "Done!"
Expand Down
16 changes: 7 additions & 9 deletions src/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ initialiseDB = do
"CREATE TABLE IF NOT EXISTS countries (\
\ id INTEGER PRIMARY KEY NOT NULL,\
\ countryCode VARCHAR(40) NOT NULL, \
\ global BOOL DEFAULT NULL \
\ global BOOL DEFAULT NULL, \
\ fixed BOOL DEFAULT NULL \
\)"
[]
commit conn
Expand All @@ -49,21 +50,19 @@ initialiseDB = do
-- | This function will insert the holiday records into the database
insertDB :: Connection -> [HolidayRecord] -> IO ()
insertDB conn records = do
let xs = records -- need to use records and produce xs, this seems easiest possibility
-- xs' <- filter (dateNotInDB conn) (nub xs)
let xs = records
stmt <- prepare conn "INSERT INTO holidays (date,localName,name) VALUES (?,?,?)"
putStrLn "Adding"
-- let xs'' = mapM_ (\x -> putStrLn $ " - " ++ x) xs'
executeMany stmt (map (\x -> [toSql (date x), toSql (localName x), toSql (name x)]) xs)
commit conn

-- | This function will insert the country records into the dsatabase
insertLB :: Connection -> [HolidayRecord] -> IO ()
insertLB conn records = do
let xs = records
stmt <- prepare conn "INSERT INTO countries (countryCode,global) VALUES (?,?)"
stmt <- prepare conn "INSERT INTO countries (countryCode,global,fixed) VALUES (?,?,?)"
putStrLn "Adding"
executeMany stmt (map (\x -> [toSql (countryCode x), toSql (global x)]) xs)
executeMany stmt (map (\x -> [toSql (countryCode x), toSql (global x), toSql (fixed x)]) xs)
commit conn

-- | This function will insert the country_holidays records into the dsatabase
Expand Down Expand Up @@ -102,8 +101,6 @@ getLocalNames conn isGlobal = do
res <-
quickQuery'
conn
-- "SELECT country_holidays.localName, countries.global FROM country_holidays \
-- \ INNER JOIN countries ON country_holidays.countryCode=countries.countryCode WHERE countries.global=true "
"SELECT country_holidays.localName FROM country_holidays \
\INNER JOIN countries \
\ON countries.id = country_holidays.id \
Expand All @@ -121,7 +118,8 @@ recordToSqlValues holidays =
holidayToSqlValues :: HolidayRecord -> [SqlValue]
holidayToSqlValues countries =
[ toSql $ countryCode countries,
toSql $ global countries
toSql $ global countries,
toSql $ fixed countries
]

prepareInsertRecordStmt :: Connection -> IO Statement
Expand Down
6 changes: 2 additions & 4 deletions src/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ import GHC.Generics ( Generic )
-- "countryCode": "GB",
-- "fixed": false,
-- "global": true,
-- "counties": null,
-- "launchYear": null,
-- "type": "Public"
-- }
-- ]
data HolidayRecord = HolidayRecord {
date :: String,
localName :: String,
name :: String,
countryCode :: String,
global::Bool
global::Bool,
fixed::Bool
} deriving (Show, Generic)


Expand Down

0 comments on commit 67b2691

Please sign in to comment.