LD4GLVSF6YTA7OZWIGJ45H6TUXGM4WKUIYXKWQFNUP36WDMYSMXAC
qdbUserRowParser = QDBUser <$> fieldWith uidParser <*> userRowParser
qdbUserRowParser = QDBUser <$> fieldWith uidParser
<*> userRowParser
projectRowParser :: RowParser Project
projectRowParser = Project <$> field
<*> field
<*> fieldWith uidParser
qdbProjectRowParser :: RowParser QDBProject
qdbProjectRowParser = QDBProject <$> fieldWith pidParser <*> projectRowParser
createProject' :: Project -> ReaderT Connection IO ProjectId
createProject' p = do
conn <- ask
pids <- lift $ query conn
"INSERT INTO projects (project_name, inception_date, initiator_id) VALUES (?, ?, ?) RETURNING id"
(p ^. projectName, p ^. inceptionDate, p ^. (initiator._UserId))
pure . ProjectId . fromOnly $ DL.head pids
findUserProjects' :: UserId -> ReaderT Connection IO [QDBProject]
findUserProjects' (UserId uid) = do
conn <- ask
results <- lift $ query conn
"SELECT p.id, p.project_name, p.inception_date, p.initiator_id \
\FROM projects p LEFT OUTER JOIN project_companions pc ON pc.project_id = p.id \
\WHERE p.initiator_id = ? OR pc.companion_id = ?"
(uid, uid)
pure $ fmap pQDBProject results