findProductRepo :: P.ProductID -> WithDBPool (Maybe ProductRepo)
findProductRepo prodID = ask >>= \pool ->
  (liftIO (DB.runSqlPool findProductRepoQuery pool)) >>= \result ->
    case result of
      [] -> return Nothing
      (x:_) -> return $ Just (toProductRepo x)
  where
    findProductRepoQuery =
      E.select $ E.from $ \(repoStatus `E.InnerJoin` prod) -> do
        E.on $ repoStatus ^. RepositoryStatusProductId E.==. prod ^. ProductId
        E.on $ prod ^. ProductId E.==. (E.val (toKey prodID))
        return (repoStatus, prod)
findProductRepo :: P.ProductID -> WithDBPool (Maybe ProductRepo)
findProductRepo prodID = ask >>= \pool ->
  (liftIO (DB.runSqlPool findProductRepoQuery pool)) >>= \result ->
    case result of
      [] -> return Nothing
      (x:_) -> return $ Just (toProductRepo x)
  where
    findProductRepoQuery =
      E.select $ E.from $ \(repoStatus `E.InnerJoin` prod) -> do
        E.on $ repoStatus ^. RepositoryStatusProductId E.==. prod ^. ProductId
        E.on $ prod ^. ProductId E.==. (E.val (toKey prodID))
        return (repoStatus, prod)
findProductRepo prodID = ask >>= \pool ->
  (liftIO (DB.runSqlPool findProductRepoQuery pool)) >>= \result ->
    case result of
      [] -> return Nothing
      (x:_) -> return $ Just (toProductRepo x)
  where
    findProductRepoQuery =
      E.select $ E.from $ \(repoStatus `E.InnerJoin` prod) -> do
        E.on $ repoStatus ^. RepositoryStatusProductId E.==. prod ^. ProductId
        E.on $ prod ^. ProductId E.==. (E.val (toKey prodID))
        return (repoStatus, prod)