Skip to content

Commit

Permalink
Updated the headers
Browse files Browse the repository at this point in the history
  • Loading branch information
beingfranklin committed Dec 10, 2020
1 parent 2ef18bf commit 9b55b1a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
13 changes: 11 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
module Main where

import Database
import Http
import Parse
( convertToJSON,
getLocalNames,
initialiseDB,
insertDB,
insertLB,
insertSB,
queryDB,
selectHolidaysInDateRange,
sqlRowToString )
import Http ( download )
import Parse ( parse )

-- | This is the main function of the program to download, parse and process public holidays of differnet countries of the world
main :: IO ()
Expand Down
18 changes: 12 additions & 6 deletions src/Database.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
module Database where

import Database.HDBC
( fromSql,
toSql,
quickQuery',
SqlValue,
Statement(executeMany),
IConnection(commit, run, prepare) )
import qualified Data.ByteString.Lazy.Char8 as L8
import Database.HDBC.Sqlite3
import Parse
import Data.Aeson
import Database.HDBC.Sqlite3 ( connectSqlite3, Connection )
import Parse ( HolidayRecord(..) )
import Data.Aeson ( encode )

{--|
Database.HDBC - Database.HDBC is an abstraction layer between Haskell programs
Expand Down Expand Up @@ -68,19 +74,19 @@ insertDB conn records = do
executeMany stmt (map (\x -> [toSql (date x), toSql (localName x), toSql (name x)]) xs) -- this function use for prepares a database operation and executes it against the parameters sequences
commit conn -- this fuction to commit a transaction to the underlying database

-- | This function will insert the country records into the dsatabase
-- | This function will insert the country records into the database
insertLB :: Connection -> [HolidayRecord] -> IO ()
insertLB conn records = do
let xs = records
stmt <- prepare conn "INSERT INTO countries (countryCode,global,fixed) VALUES (?,?,?)" -- this fuction use to insert the values into the parameters under the country table
executeMany stmt (map (\x -> [toSql (countryCode x), toSql (global x), toSql (fixed x)]) xs) -- this function use for prepares a database operation and executes it against the parameters sequences
commit conn -- this fuction to commit a transaction to the underlying database

-- | This function will insert the country_holidays records into the dsatabase
-- | This function will insert the country_holidays records into the database
insertSB :: Connection -> [HolidayRecord] -> IO ()
insertSB conn records = do
let xs = records
stmt <- prepare conn "INSERT INTO country_holidays (countryCode,localName) VALUES (?,?)" -- this fuction use to insert the values into the parameters under the country_holidays
stmt <- prepare conn "INSERT INTO country_holidays (countryCode,localName) VALUES (?,?)" -- this function use to insert the values into the parameters under the country_holidays
executeMany stmt (map (\x -> [toSql (countryCode x), toSql (localName x)]) xs) -- this function use for prepares a database operation and executes it against the parameters sequences
commit conn -- this function to commit a transaction to the underlying database

Expand Down
2 changes: 1 addition & 1 deletion src/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- |Parse module header
module Parse where

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

Expand Down

0 comments on commit 9b55b1a

Please sign in to comment.