Skip to content

Instantly share code, notes, and snippets.

@willxeric
Created August 29, 2014 21:02
Show Gist options
  • Save willxeric/011490de26b5b4da3a1c to your computer and use it in GitHub Desktop.
Save willxeric/011490de26b5b4da3a1c to your computer and use it in GitHub Desktop.
{-# 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