-
-
Save willxeric/011490de26b5b4da3a1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Control.Applicative | |
import Control.Monad | |
import Control.Monad.IO.Class (liftIO) | |
import Database.PostgreSQL.Simple | |
import Database.PostgreSQL.Simple.FromRow | |
import Data.Word | |
import qualified Data.Text as T | |
connInfo = ConnectInfo "localhost" (15432 :: Word16) "schoolobjects" "schoolobjects" "schoolobject | |
s" | |
data Course = Course { title :: T.Text | |
, description :: Maybe T.Text | |
, creditid :: Maybe Int | |
, status :: T.Text | |
} deriving Show | |
data Activity = Activity { title :: T.Text | |
, courseid :: Int | |
, status :: T.Text | |
} deriving Show | |
data CourseActivity = CourseActivity { | |
instance FromRow Course where | |
fromRow = Course <$> field <*> field <*> field <*> field | |
instance FromRow Activity where | |
fromRow = Activity <$> field <*> field <*> field | |
main :: IO () | |
main = do | |
conn <- connect connInfo | |
c <- query_ conn "SELECT c.title, | |
c.description, | |
c.creditid, | |
c.status, | |
a.title, | |
a.courseid, | |
a.status | |
FROM course c | |
JOIN activity a on a.courseid = c.courseid | |
limit 1" :: (IO [(Course, Activity)]) | |
putStrLn $ show c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment