Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created April 25, 2015 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rightfold/a921911af024e2a01ae7 to your computer and use it in GitHub Desktop.
Save rightfold/a921911af024e2a01ae7 to your computer and use it in GitHub Desktop.
findUserByEmailAddress :: Connection -> EmailAddress -> IO (Maybe User)
findUserByEmailAddress conn (EmailAddress emailAddress) =
let sql = "select id, email_address, password_hash from users where email_address = $1"
in fromRows `fmap` query conn sql (Only emailAddress)
where fromRows :: [(String, String, ByteString)] -> Maybe User
fromRows [] = Nothing
fromRows [(id, emailAddress, passwordHash)] =
Just $ User (UserID . fromJust . UUID.fromString $ id)
(EmailAddress emailAddress)
(PasswordHash passwordHash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment