packages feed

selda-postgresql 0.1.1.0 → 0.1.2.0

raw patch · 2 files changed

+17/−24 lines, 2 filesdep ~seldaPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: selda

API changes (from Hackage documentation)

- Database.Selda.PostgreSQL: PGConnectException :: String -> PGConnectException
- Database.Selda.PostgreSQL: data PGConnectException
- Database.Selda.PostgreSQL: instance GHC.Exception.Exception Database.Selda.PostgreSQL.PGConnectException
- Database.Selda.PostgreSQL: instance GHC.Exception.Exception Database.Selda.PostgreSQL.PGQueryException
- Database.Selda.PostgreSQL: instance GHC.Show.Show Database.Selda.PostgreSQL.PGConnectException
- Database.Selda.PostgreSQL: instance GHC.Show.Show Database.Selda.PostgreSQL.PGQueryException
+ Database.Selda.PostgreSQL: pgBackend :: Connection -> SeldaBackend
+ Database.Selda.PostgreSQL: pgConnString :: PGConnectInfo -> ByteString

Files

selda-postgresql.cabal view
@@ -1,5 +1,5 @@ name:                selda-postgresql-version:             0.1.1.0+version:             0.1.2.0 synopsis:            PostgreSQL backend for the Selda database EDSL. description:         PostgreSQL backend for the Selda database EDSL.                      Requires the PostgreSQL @libpq@ development libraries to be@@ -26,10 +26,10 @@     OverloadedStrings     CPP   build-depends:-      base             >=4.8   && <5-    , exceptions       >=0.8   && <0.9-    , selda            >=0.1.1 && <0.2-    , text             >=1.0   && <1.3+      base             >=4.8     && <5+    , exceptions       >=0.8     && <0.9+    , selda            >=0.1.3.2 && <0.2+    , text             >=1.0     && <1.3   if !flag(haste)     build-depends:         bytestring       >=0.9 && <0.11
src/Database/Selda/PostgreSQL.hs view
@@ -1,8 +1,10 @@ {-# LANGUAGE OverloadedStrings, RecordWildCards, GADTs, CPP #-} -- | PostgreSQL backend for Selda. module Database.Selda.PostgreSQL-  ( PGConnectInfo (..), PGConnectException (..)+  ( PGConnectInfo (..)   , withPostgreSQL, on, auth+  , pgBackend+  , pgConnString   ) where import Data.Monoid import qualified Data.Text as T@@ -15,17 +17,6 @@ import qualified Data.ByteString.Char8 as BS #endif --- | The exception thrown when a connection could not be made to the PostgreSQL---   server.-data PGConnectException = PGConnectException String-  deriving Show-instance Exception PGConnectException---- | The exception thrown when a query fails.-data PGQueryException = PGQueryException String-  deriving Show-instance Exception PGQueryException- -- | PostgreSQL connection information. data PGConnectInfo = PGConnectInfo   { -- | Host to connect to.@@ -84,10 +75,11 @@     ConnectionOk -> runSeldaT m (pgBackend conn) `finally` liftIO (finish conn)     nope         -> connFailed nope   where-    connFailed f = throwM $ PGConnectException $ unwords+    connFailed f = throwM $ DbError $ unwords       [ "unable to connect to postgres server: " ++ show f       ] +-- | Create a `SeldaBackend` for PostgreSQL `Connection` pgBackend :: Connection -> SeldaBackend pgBackend c = SeldaBackend   { runStmt        = \q ps -> right <$> pgQueryRunner c False q ps@@ -101,6 +93,7 @@     right (Right x) = x     right _         = error "impossible" +-- | Convert `PGConnectInfo` into `ByteString` pgConnString :: PGConnectInfo -> BS.ByteString pgConnString PGConnectInfo{..} = mconcat   [ "host=", encodeUtf8 pgHost, " "@@ -123,12 +116,12 @@       Just res -> do         st <- resultStatus res         case st of-          BadResponse       -> throwM $ PGQueryException "bad response"-          FatalError        -> throwM $ PGQueryException errmsg-          NonfatalError     -> throwM $ PGQueryException errmsg+          BadResponse       -> throwM $ SqlError "bad response"+          FatalError        -> throwM $ SqlError errmsg+          NonfatalError     -> throwM $ SqlError errmsg           _ | return_lastid -> Left <$> getLastId res             | otherwise     ->Right <$> getRows res-      Nothing           -> error "unable to submit query to server"+      Nothing           -> throwM $ DbError "unable to submit query to server"   where     errmsg = "error executing query `" ++ T.unpack q' ++ "'"     q' | return_lastid = q <> " RETURNING LASTVAL();"@@ -164,7 +157,7 @@   | t == intType     = SqlInt $ read (BS.unpack val)   | t == doubleType  = SqlFloat $ read (BS.unpack val)   | t `elem` textish = SqlString (decodeUtf8 val)-  | otherwise        = error $ "result with unknown type oid: " ++ show t+  | otherwise        = error $ "BUG: result with unknown type oid: " ++ show t   where     textish = [textType, timestampType, timeType, dateType]     readBool "f"   = False@@ -201,7 +194,7 @@     Nothing  -- | OIDs for all types used by Selda.-boolType, intType, textType, doubleType :: Oid+boolType, intType, textType, doubleType, dateType, timeType, timestampType :: Oid boolType      = Oid 16 intType       = Oid 20 textType      = Oid 25