Last active
August 29, 2015 14:23
-
-
Save L8D/5ffb3c0bb782e1ed22ff 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
findById :: User.Id -> forall s. Tx Postgres s (Maybe User) | |
findById userId = do | |
result <- maybeEx [stmt| | |
SELECT id, email, created_at, updated_at | |
FROM users | |
WHERE id = $userId | |
|] | |
return case result of | |
Just row -> toUser row | |
Nothing -> Nothing | |
-- versus: | |
findById :: User.Id -> forall s. Tx Postgres s (Maybe User) | |
findById userId = fmap toUser <$> maybeEx q where q = [stmt| | |
SELECT id, email, created_at, updated_at | |
FROM users | |
WHERE id = $userId | |
|] | |
-- maybe even | |
findById :: User.Id -> forall s. Tx Postgres s (Maybe User) | |
findById userId = do | |
result <- maybeEx [stmt| | |
SELECT id, email, created_at, updated_at | |
FROM users | |
WHERE id = $userId | |
|] | |
user <- return $ do | |
row <- result | |
return (row & toUser) | |
return user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment