Skip to content

Instantly share code, notes, and snippets.

@L8D
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L8D/5ffb3c0bb782e1ed22ff to your computer and use it in GitHub Desktop.
Save L8D/5ffb3c0bb782e1ed22ff to your computer and use it in GitHub Desktop.
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