selda-postgresql 0.1.5.1 → 0.1.6.0
raw patch · 2 files changed
+23/−25 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: pgOpen :: (MonadIO m, MonadThrow m) => PGConnectInfo -> m SeldaConnection
+ Database.Selda.PostgreSQL: pgOpen :: (MonadIO m, MonadMask m) => PGConnectInfo -> m SeldaConnection
Files
- selda-postgresql.cabal +6/−6
- src/Database/Selda/PostgreSQL.hs +17/−19
selda-postgresql.cabal view
@@ -1,5 +1,5 @@ name: selda-postgresql-version: 0.1.5.1+version: 0.1.6.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@@ -28,11 +28,11 @@ OverloadedStrings CPP build-depends:- base >=4.8 && <5- , bytestring >=0.9 && <0.11- , exceptions >=0.8 && <0.9- , selda >=0.1.8.0 && <0.2- , text >=1.0 && <1.3+ base >=4.8 && <5+ , bytestring >=0.9 && <0.11+ , exceptions >=0.8 && <0.9+ , selda >=0.1.10.0 && <0.2+ , text >=1.0 && <1.3 if !flag(haste) build-depends: postgresql-libpq >=0.9 && <0.10
src/Database/Selda/PostgreSQL.hs view
@@ -91,33 +91,31 @@ #ifdef __HASTE__ withPostgreSQL _ _ = return $ error "withPostgreSQL called in JS context" #else-withPostgreSQL ci m = do- c <- pgOpen ci- runSeldaT m c `finally` seldaClose c+withPostgreSQL ci m = bracket (pgOpen ci) seldaClose (runSeldaT m) #endif -- | Open a new PostgreSQL connection. The connection will persist across -- calls to 'runSeldaT', and must be explicitly closed using 'seldaClose' -- when no longer needed.-pgOpen :: (MonadIO m, MonadThrow m) => PGConnectInfo -> m SeldaConnection+pgOpen :: (MonadIO m, MonadMask m) => PGConnectInfo -> m SeldaConnection #ifdef __HASTE__ pgOpen _ = return $ error "pgOpen called in JS context" #else-pgOpen ci = do- conn <- liftIO $ connectdb connstr- st <- liftIO $ status conn- case st of- ConnectionOk -> do- let backend = pgBackend conn- liftIO $ runStmt backend "SET client_min_messages TO WARNING;" []- newConnection backend (decodeUtf8 connstr)- nope -> do- connFailed nope- where- connstr = pgConnString ci- connFailed f = throwM $ DbError $ unwords- [ "unable to connect to postgres server: " ++ show f- ]+pgOpen ci =+ bracketOnError (liftIO $ connectdb connstr) (liftIO . finish) $ \conn -> do+ st <- liftIO $ status conn+ case st of+ ConnectionOk -> do+ let backend = pgBackend conn+ liftIO $ runStmt backend "SET client_min_messages TO WARNING;" []+ newConnection backend (decodeUtf8 connstr)+ nope -> do+ connFailed nope+ where+ connstr = pgConnString ci+ connFailed f = throwM $ DbError $ unwords+ [ "unable to connect to postgres server: " ++ show f+ ] -- | Create a `SeldaBackend` for PostgreSQL `Connection` pgBackend :: Connection -- ^ PostgreSQL connection object.