hasql-postgres 0.7.0 → 0.7.1
raw patch · 5 files changed
+34/−34 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- hasql-postgres.cabal +1/−1
- library/Hasql/Postgres.hs +1/−1
- library/Hasql/Postgres/Connector.hs +28/−28
- library/Hasql/Postgres/Mapping.hs +2/−2
- library/Hasql/Postgres/ResultParser.hs +2/−2
hasql-postgres.cabal view
@@ -1,7 +1,7 @@ name: hasql-postgres version:- 0.7.0+ 0.7.1 synopsis: A "PostgreSQL" backend for the "hasql" library description:
library/Hasql/Postgres.hs view
@@ -59,7 +59,7 @@ } connect p = do- r <- runEitherT $ Connector.open settings+ r <- Connector.open settings c <- either (\e -> throwIO $ Backend.CantConnect $ fromString $ show e) return r Connection <$> pure c <*> StatementPreparer.new c <*> newIORef Nothing <*> getIntegerDatetimes c where
library/Hasql/Postgres/Connector.hs view
@@ -6,6 +6,7 @@ import qualified Data.ByteString.Lazy.Builder as BB import qualified Data.ByteString.Lazy.Builder.ASCII as BB import qualified Data.ByteString.Lazy as BL+import qualified Data.Text as T import qualified Data.Text.Encoding as TE @@ -19,52 +20,51 @@ } --- |--- Default settings.-settings :: Settings-settings =- Settings "127.0.0.1" 5432 "postgres" "" ""-- data Error = BadStatus (Maybe ByteString) | UnsupportedVersion Int- deriving (Show, Typeable)+ deriving (Show) -- | -- Establish and initialize a connection.-open :: Settings -> EitherT Error IO PQ.Connection+open :: Settings -> IO (Either Error PQ.Connection) open s =- do+ runEitherT $ do c <- lift $ PQ.connectdb (settingsBS s) do s <- lift $ PQ.status c- when (s /= PQ.ConnectionOk) $ - do- m <- lift $ PQ.errorMessage c- left $ BadStatus m+ when (s /= PQ.ConnectionOk) $ do+ m <- lift $ PQ.errorMessage c+ left $ BadStatus m do v <- lift $ PQ.serverVersion c when (v < 80200) $ left $ UnsupportedVersion v- lift $ PQ.exec c $ mconcat $ map (<> ";") $ + lift $ PQ.exec c $ BL.toStrict $ BB.toLazyByteString $ mconcat $ map (<> BB.char7 ';') $ [ - "SET client_encoding = 'UTF8'",- "SET client_min_messages TO WARNING"+ BB.string7 "SET client_encoding = 'UTF8'",+ BB.string7 "SET client_min_messages TO WARNING" ] return c settingsBS :: Settings -> ByteString settingsBS s =- BL.toStrict $ BB.toLazyByteString $ - mconcat $ intersperse (BB.char7 ' ') args- where- args =- [- BB.string7 "host=" <> BB.byteString (host s),- BB.string7 "port=" <> BB.word16Dec (port s),- BB.string7 "user=" <> BB.byteString (TE.encodeUtf8 (user s)),- BB.string7 "password=" <> BB.byteString (TE.encodeUtf8 (password s)),- BB.string7 "dbname=" <> BB.byteString (TE.encodeUtf8 (database s))- ]+ BL.toStrict $ BB.toLazyByteString $ mconcat $ intersperse (BB.char7 ' ') $ catMaybes $+ [+ mappend (BB.string7 "host=") . BB.byteString <$> + partial (not . B.null) (host s)+ ,+ mappend (BB.string7 "port=") . BB.word16Dec <$> + partial (/= 0) (port s)+ ,+ mappend (BB.string7 "user=") . BB.byteString . TE.encodeUtf8 <$> + partial (not . T.null) (user s)+ ,+ mappend (BB.string7 "password=") . BB.byteString . TE.encodeUtf8 <$> + partial (not . T.null) (password s)+ ,+ mappend (BB.string7 "dbname=") . BB.byteString . TE.encodeUtf8 <$> + partial (not . T.null) (database s)+ ]+
library/Hasql/Postgres/Mapping.hs view
@@ -288,8 +288,8 @@ {-# INLINE arrayEncode #-} arrayEncode e x = Array.fromSingleton (Just ($encoder e x))- (False)- (PTI.oidWord32 (PTI.ptiOID $pti))+ (False)+ (PTI.oidWord32 (PTI.ptiOID $pti)) {-# INLINE arrayDecode #-} arrayDecode e = \case
library/Hasql/Postgres/ResultParser.hs view
@@ -80,9 +80,9 @@ erroneousResultText = \case NoResult (Just bs) -> - Just $ "Inable to send command to the server due to: " <> Text.decodeLatin1 bs+ Just $ "Unable to send command to the server due to: " <> Text.decodeLatin1 bs NoResult Nothing -> - Just $ "Inable to send command to the server"+ Just $ "Unable to send command to the server" StatusError status code message details hint -> Just $ "A status error. " <> formatFields fields