hasql-postgres 0.7.3 → 0.8.0
raw patch · 5 files changed
+48/−50 lines, 5 filesdep ~transformersPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: transformers
API changes (from Hackage documentation)
- Hasql.Postgres: Postgres :: ByteString -> Word16 -> Text -> Text -> Text -> Postgres
- Hasql.Postgres: data Postgres
- Hasql.Postgres: database :: Postgres -> Text
- Hasql.Postgres: host :: Postgres -> ByteString
- Hasql.Postgres: password :: Postgres -> Text
- Hasql.Postgres: port :: Postgres -> Word16
- Hasql.Postgres: user :: Postgres -> Text
+ Hasql.Postgres: ParamSettings :: ByteString -> Word16 -> ByteString -> ByteString -> ByteString -> Settings
+ Hasql.Postgres: StringSettings :: ByteString -> Settings
+ Hasql.Postgres: data Settings
+ Hasql.Postgres: type Postgres = Settings
Files
- competition/Main.hs +3/−3
- hasql-postgres.cabal +3/−3
- library/Hasql/Postgres.hs +8/−13
- library/Hasql/Postgres/Connector.hs +31/−28
- tests/Main.hs +3/−3
competition/Main.hs view
@@ -34,7 +34,7 @@ subject "hasql" $ do pause- H.session (H.Postgres host port user password db) (fromJust $ H.sessionSettings 1 30) $ do+ H.session (H.ParamSettings host port user password db) (fromJust $ H.sessionSettings 1 30) $ do H.tx Nothing $ do H.unit [H.q|DROP TABLE IF EXISTS a|] H.unit [H.q|CREATE TABLE a (id SERIAL NOT NULL, @@ -110,7 +110,7 @@ subject "hasql" $ do pause- H.session (H.Postgres host port user password db) (fromJust $ H.sessionSettings 1 30) $ do+ H.session (H.ParamSettings host port user password db) (fromJust $ H.sessionSettings 1 30) $ do H.tx Nothing $ do H.unit [H.q|DROP TABLE IF EXISTS a|] H.unit [H.q|CREATE TABLE a (id SERIAL NOT NULL, @@ -183,7 +183,7 @@ subject "hasql" $ do pause- H.session (H.Postgres host port user password db) (fromJust $ H.sessionSettings 1 30) $ do+ H.session (H.ParamSettings host port user password db) (fromJust $ H.sessionSettings 1 30) $ do H.tx Nothing $ do H.unit [H.q|DROP TABLE IF EXISTS a|] H.unit [H.q|CREATE TABLE a (id SERIAL NOT NULL, balance INT8, PRIMARY KEY (id))|]
hasql-postgres.cabal view
@@ -1,7 +1,7 @@ name: hasql-postgres version:- 0.7.3+ 0.8.0 synopsis: A "PostgreSQL" backend for the "hasql" library description:@@ -91,7 +91,7 @@ either == 4.*, list-t < 0.4, mmorph == 1.0.*,- transformers >= 0.2 && < 0.5,+ transformers >= 0.3 && < 0.5, -- errors: loch-th == 0.2.*, placeholders == 0.1.*,@@ -144,7 +144,7 @@ either == 4.*, list-t < 0.4, mmorph == 1.0.*,- transformers >= 0.2 && < 0.5,+ transformers >= 0.3 && < 0.5, -- errors: loch-th == 0.2.*, placeholders == 0.1.*,
library/Hasql/Postgres.hs view
@@ -13,7 +13,8 @@ -- module Hasql.Postgres (- Postgres(..), + Postgres(..),+ Connector.Settings(..), ) where @@ -33,16 +34,12 @@ -- |--- Settings of a Postgres backend.-data Postgres =- Postgres {- host :: ByteString,- port :: Word16,- user :: Text,- password :: Text,- database :: Text- }+-- Just an alias to settings,+-- which is used as a more descriptive identifier type of the backend.+type Postgres = + Connector.Settings + instance Backend.Backend Postgres where data StatementArgument Postgres = StatementArgument PQ.Oid (Mapping.Environment -> Maybe ByteString)@@ -55,15 +52,13 @@ transactionEnv :: !Transaction.Env, mappingEnv :: !Mapping.Environment }- connect p =+ connect settings = do r <- Connector.open settings c <- either (\e -> throwIO $ Backend.CantConnect $ fromString $ show e) return r ee <- Execution.newEnv c Connection <$> pure c <*> pure ee <*> Transaction.newEnv ee <*> getIntegerDatetimes c where- settings =- Connector.Settings (host p) (port p) (user p) (password p) (database p) getIntegerDatetimes c = fmap parseResult $ PQ.parameterStatus c "integer_datetimes" where
library/Hasql/Postgres/Connector.hs view
@@ -6,19 +6,19 @@ 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 +-- |+-- Connection settings. data Settings =- Settings {- host :: ByteString,- port :: Word16,- user :: Text,- password :: Text,- database :: Text- }-+ -- | + -- A host, a port, a user, a password and a database.+ ParamSettings ByteString Word16 ByteString ByteString ByteString |+ -- | + -- All settings encoded in a single byte string according to + -- <http://www.postgresql.org/docs/9.4/static/libpq-connect.html#LIBPQ-CONNSTRING the PostgreSQL format>.+ StringSettings ByteString+ deriving (Show) data Error = BadStatus (Maybe ByteString) |@@ -49,22 +49,25 @@ settingsBS :: Settings -> ByteString-settingsBS 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)- ]+settingsBS =+ \case+ ParamSettings host port user password database ->+ BL.toStrict $ BB.toLazyByteString $ mconcat $ intersperse (BB.char7 ' ') $ catMaybes $+ [+ mappend (BB.string7 "host=") . BB.byteString <$> + partial (not . B.null) host+ ,+ mappend (BB.string7 "port=") . BB.word16Dec <$> + partial (/= 0) port+ ,+ mappend (BB.string7 "user=") . BB.byteString <$> + partial (not . B.null) user+ ,+ mappend (BB.string7 "password=") . BB.byteString <$> + partial (not . B.null) password+ ,+ mappend (BB.string7 "dbname=") . BB.byteString <$> + partial (not . B.null) database+ ]+ StringSettings x -> x
tests/Main.hs view
@@ -20,7 +20,7 @@ import qualified Control.Concurrent.SSem as SSem import qualified Hasql.Backend as Backend import qualified Hasql as H-import qualified Hasql.Postgres as H+import qualified Hasql.Postgres as HP import qualified Data.Scientific as Scientific import qualified Data.Vector as Vector @@ -37,7 +37,7 @@ test_wrongPort = let - backendSettings = H.Postgres "localhost" 1 "postgres" "" "postgres"+ backendSettings = HP.ParamSettings "localhost" 1 "postgres" "" "postgres" poolSettings = fromJust $ sessionSettings 6 30 io = H.session backendSettings poolSettings $ do@@ -217,7 +217,7 @@ session1 = session backendSettings poolSettings where- backendSettings = Postgres "localhost" 5432 "postgres" "" "postgres"+ backendSettings = HP.ParamSettings "localhost" 5432 "postgres" "" "postgres" poolSettings = fromJust $ sessionSettings 6 30 -- ** Property