Skip to content

Commit

Permalink
Updated minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Franklin Antony authored and Franklin Antony committed Dec 3, 2020
1 parent 29880fc commit a858b44
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 3 additions & 5 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ main = do
print "Downloading..."
json <- download url
print "Parsing"
case (parse json) of
case parse json of
Left err -> print err
-- Print first record
Right recs -> do
Expand All @@ -24,8 +24,6 @@ main = do
insertLB conn recs
print "Done!"
res <- queryDB conn "GB"
print $ "Number of rows is "++(show $ length res)


-- P.S It Outputs the haskell datatype we specified
-- putStr $ show res
print $ "Number of rows is " ++ show (length res)

13 changes: 8 additions & 5 deletions src/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,26 @@ insertSB conn records = do

-- This function will select all the holidays of a given country
queryDB :: Connection -> String -> IO [[SqlValue]]
queryDB conn countryCode = do
res <- quickQuery' conn "SELECT localName FROM country_holidays WHERE countryCode =(?)" [toSql countryCode]
return res
queryDB conn countryCode =
do quickQuery'
conn
"SELECT localName FROM country_holidays WHERE countryCode =(?)"
[toSql countryCode]

--This function will select all the holidays in the date specified of a given country
querySQ :: Connection -> String -> IO Bool
querySQ conn date = do
let d1 = "31-JUL-20"
let d2 = "1-JAN-20"
res <- quickQuery' conn "SELECT localName FROM holidays WHERE date BETWEEN (?) AND (?)" [toSql date]
return (length res == 0)
return (null res)

-- This function will call all the names on the database.
getNAMEs :: Connection -> IO [String]
getNAMEs conn = do
res <- quickQuery' conn "SELECT name FROM holidays" []
return $ map fromSql (map head res)
-- return $ map fromSql (map head res)
return $ map (fromSql . head) res


recordToSqlValues :: HolidayRecord -> [SqlValue]
Expand Down
3 changes: 1 addition & 2 deletions src/Http.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module Http

import qualified Data.ByteString.Lazy.Char8 as L8
import Network.HTTP.Simple

type URL = String
( parseRequest, getResponseBody, httpLBS )

download :: String -> IO L8.ByteString
download url = do
Expand Down
4 changes: 2 additions & 2 deletions src/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

module Parse where

import Data.Aeson
import Data.Aeson ( eitherDecode, FromJSON, ToJSON )
import qualified Data.ByteString.Lazy.Char8 as L8
import GHC.Generics
import GHC.Generics ( Generic )

-- -- Sample format
-- [
Expand Down

0 comments on commit a858b44

Please sign in to comment.