packages feed

postgres-options 0.1.0.0 → 0.1.0.1

raw patch · 2 files changed

+73/−6 lines, 2 filesdep +bytestringPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependencies added: bytestring

API changes (from Hackage documentation)

+ Database.PostgreSQL.Simple.Options: defaultOptions :: String -> Options
+ Database.PostgreSQL.Simple.Options: toConnectionString :: Options -> ByteString

Files

postgres-options.cabal view
@@ -1,5 +1,5 @@ name:                postgres-options-version:             0.1.0.0+version:             0.1.0.1 synopsis:            An Options type representing options for postgres connections description:         This package exports an Options type representing options for postgres connections homepage:            https://github.com/jfischoff/postgres-options#readme@@ -16,7 +16,7 @@ library   hs-source-dirs:      src   exposed-modules:     Database.PostgreSQL.Simple.Options-  build-depends: base >= 4.6 && < 5+  build-depends: base >= 4.6 && < 5, bytestring   default-language:    Haskell2010   ghc-options: -Wall                -fno-warn-unused-do-bind
src/Database/PostgreSQL/Simple/Options.hs view
@@ -2,14 +2,22 @@    'Connection' -} -{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TupleSections #-} -module Database.PostgreSQL.Simple.Options where+module Database.PostgreSQL.Simple.Options+  ( Options(..)+  , defaultOptions+  , toArgs+  , toConnectionString+  ) where -import GHC.Generics (Generic)-import Data.Typeable (Typeable)+import Data.ByteString (ByteString)+import qualified Data.ByteString.Char8 as BSC import Data.Maybe (Maybe, maybeToList)+import Data.Typeable (Typeable)+import GHC.Generics (Generic)  data Options = Options   { oHost                    :: Maybe String@@ -46,3 +54,62 @@   ++ (("--password=" <>) <$> maybeToList oPassword)   ++ ((\x -> "--host=" <> show x) <$> maybeToList oPort) +toConnectionString :: Options -> ByteString+toConnectionString Options {..} = BSC.pack $ unwords $ map (\(k, v) -> k <> "=" <> v)+  $  maybeToPairStr "host" oHost+  <> maybeToPairStr "hostaddr" oHostaddr+  <> [ ("dbname", oDbname)+     ]+  <> maybeToPair "port" oPort+  <> maybeToPairStr "password" oPassword+  <> maybeToPairStr "user" oUser+  <> maybeToPair "connect_timeout" oConnectTimeout+  <> maybeToPairStr "client_encoding" oClientEncoding+  <> maybeToPairStr "options" oOptions+  <> maybeToPairStr "fallback_applicationName" oFallbackApplicationName+  <> maybeToPair "keepalives" oKeepalives+  <> maybeToPair "keepalives_idle" oKeepalivesIdle+  <> maybeToPair "keepalives_count" oKeepalivesCount+  <> maybeToPairStr "sslmode" oSslmode+  <> maybeToPair "requiressl" oRequiressl+  <> maybeToPair "sslcompression" oSslcompression+  <> maybeToPairStr "sslcert" oSslcert+  <> maybeToPairStr "sslkey" oSslkey+  <> maybeToPairStr "sslrootcert" oSslrootcert+  <> maybeToPairStr "requirepeer" oRequirepeer+  <> maybeToPairStr "krbsrvname" oKrbsrvname+  <> maybeToPairStr "gsslib" oGsslib+  <> maybeToPairStr "service" oService+  where+  maybeToPairStr :: String -> Maybe String -> [(String, String)]+  maybeToPairStr k mv = (k,) <$> maybeToList mv++  maybeToPair :: Show a => String -> Maybe a -> [(String, String)]+  maybeToPair k mv = (\v -> (k, show v)) <$> maybeToList mv++defaultOptions :: String -> Options+defaultOptions dbName = Options {+    oHost                    = Nothing+  , oHostaddr                = Nothing+  , oPort                    = Nothing+  , oUser                    = Nothing+  , oPassword                = Nothing+  , oDbname                  = dbName+  , oConnectTimeout          = Nothing+  , oClientEncoding          = Nothing+  , oOptions                 = Nothing+  , oFallbackApplicationName = Nothing+  , oKeepalives              = Nothing+  , oKeepalivesIdle          = Nothing+  , oKeepalivesCount         = Nothing+  , oSslmode                 = Nothing+  , oRequiressl              = Nothing+  , oSslcompression          = Nothing+  , oSslcert                 = Nothing+  , oSslkey                  = Nothing+  , oSslrootcert             = Nothing+  , oRequirepeer             = Nothing+  , oKrbsrvname              = Nothing+  , oGsslib                  = Nothing+  , oService                 = Nothing+}