selda-postgresql 0.1.2.1 → 0.1.2.2
raw patch · 2 files changed
+11/−6 lines, 2 filesdep ~selda
Dependency ranges changed: selda
Files
selda-postgresql.cabal view
@@ -1,5 +1,5 @@ name: selda-postgresql-version: 0.1.2.1+version: 0.1.2.2 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,7 +28,7 @@ build-depends: base >=4.8 && <5 , exceptions >=0.8 && <0.9- , selda >=0.1.3.2 && <0.2+ , selda >=0.1.4.1 && <0.2 , text >=1.0 && <1.3 if !flag(haste) build-depends:
src/Database/Selda/PostgreSQL.hs view
@@ -69,27 +69,32 @@ withPostgreSQL _ _ = return $ error "withPostgreSQL called in JS context" #else withPostgreSQL ci m = do- conn <- liftIO $ connectdb (pgConnString ci)+ conn <- liftIO $ connectdb connstr st <- liftIO $ status conn case st of ConnectionOk -> do- let backend = pgBackend conn+ let backend = pgBackend (decodeUtf8 connstr) conn liftIO $ runStmt backend "SET client_min_messages TO WARNING;" [] runSeldaT m backend `finally` liftIO (finish conn) 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 -> SeldaBackend-pgBackend c = SeldaBackend+pgBackend :: T.Text -- ^ Unique database identifier. Preferably the+ -- connection string used to open the connection.+ -> Connection -- ^ PostgreSQL connection object.+ -> SeldaBackend+pgBackend ident c = SeldaBackend { runStmt = \q ps -> right <$> pgQueryRunner c False q ps , runStmtWithPK = \q ps -> left <$> pgQueryRunner c True q ps , customColType = pgColType , defaultKeyword = "DEFAULT"+ , dbIdentifier = ident } where left (Left x) = x