Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Forked from rightfold/gist:a921911af024e2a01ae7
Last active August 29, 2015 14:19
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 vendethiel/608d1e8304d96a3787bc to your computer and use it in GitHub Desktop.
Save vendethiel/608d1e8304d96a3787bc 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 safeHead (fromRows `fmap` query conn sql (Only emailAddress)) >>= makeUser
where makeUser :: (String, String, ByteString) -> Maybe User
makeUser (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