postgresql-simple-0.5.3.0: Mid-Level PostgreSQL client library

Copyright(c) 2012-2013 Leonid Onokhov Joey Adams
LicenseBSD3
MaintainerLeon P Smith <leon@melding-monads.com>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell98

Database.PostgreSQL.Simple.Errors

Description

| Module for parsing errors from postgresql error messages. Currently only parses integrity violation errors (class 23).

Note: Success of parsing may depend on language settings.

Synopsis

Documentation

constraintViolation :: SqlError -> Maybe ConstraintViolation Source #

Tries to convert SqlError to ConstrainViolation, checks sqlState and succeedes only if able to parse sqlErrorMsg.

createUser = handleJust constraintViolation handler $ execute conn ...
  where
    handler (UniqueViolation "user_login_key") = ...
    handler _ = ...

constraintViolationE :: SqlError -> Maybe (SqlError, ConstraintViolation) Source #

Like constraintViolation, but also packs original SqlError.

createUser = handleJust constraintViolationE handler $ execute conn ...
  where
    handler (_, UniqueViolation "user_login_key") = ...
    handler (e, _) = throwIO e

catchViolation :: (SqlError -> ConstraintViolation -> IO a) -> IO a -> IO a Source #

Catches SqlError, tries to convert to ConstraintViolation, re-throws on fail. Provides alternative interface to handleJust

createUser = catchViolation catcher $ execute conn ...
  where
    catcher _ (UniqueViolation "user_login_key") = ...
    catcher e _ = throwIO e