packages feed

tmp-postgres 1.2.0.0 → 1.2.0.1

raw patch · 3 files changed

+58/−52 lines, 3 files

Files

src/Database/Postgres/Temp.hs view
@@ -118,22 +118,23 @@   @    listen_addresses = ''-   unix_socket_directories = {DATA_DIRECTORY}+   unix_socket_directories = SOCKET_DIRECTORY  @  To add to \"postgresql.conf\" file create a custom 'Config' like the following:   @-  let custom = defaultConfig <> mempty { configPlan = mempty-        { partialPlanConfig = Mappend-            [ "wal_level=replica"-            , "archive_mode=on"-            , "max_wal_senders=2"-            , "fsync=on"-            , "synchronous_commit=on"-            ]+  let custom = defaultConfig <> mempty+        { configPlan = mempty+          { partialPlanConfig = Mappend+              [ "wal_level=replica"+              , "archive_mode=on"+              , "max_wal_senders=2"+              , "fsync=on"+              , "synchronous_commit=on"+              ]+          }         }-    }  @   In general you'll want to 'mappend' a config to the 'defaultConfig'.
src/Database/Postgres/Temp/Internal/Partial.hs view
@@ -75,9 +75,11 @@   --   The key is `mappend`ed with value so the key should include   --   the space or equals (as shown in the first two examples   --   respectively).+  --   The 'Dual' monoid is used so the last key wins.   , partialCommandLineArgsIndexBased :: Map Int String   -- ^ Arguments that appear at the end of the key based   --   arguments.+  --   The 'Dual' monoid is used so the last key wins.   }   deriving stock (Generic, Show, Eq)   deriving Monoid via GenericMonoid PartialCommandLineArgs@@ -111,7 +113,8 @@ --   defaults when creating a 'ProcessConfig'. data PartialProcessConfig = PartialProcessConfig   { partialProcessConfigEnvVars :: Lastoid (Map String String)-  -- ^ A monoid for combine environment variables or replacing them+  -- ^ A monoid for combine environment variables or replacing them.+  --   for the maps the 'Dual' monoid is used. So the last key wins.   , partialProcessConfigCmdLine :: Lastoid PartialCommandLineArgs   -- ^ A monoid for combine command line arguments or replacing them   , partialProcessConfigStdIn   :: Last Handle@@ -463,53 +466,55 @@   =  ( mempty        { configPlan = optionsToPlan opts        , configPort = maybe (Last Nothing) (pure . pure) $ getLast port-       , configSocket = hostToSocketClass $ getLast host-       }-     )-  <> ( mempty-       { configPlan = mempty-         { partialPlanPostgres = mempty-           { partialPostgresPlanClientConfig = opts-           }-         }+       , configSocket = maybe mempty hostToSocketClass $ getLast host        }      )-+-- | Convert the 'Client.Options' to a 'PartialPlan' that can+--   be connected to with the 'Client.Options'. optionsToPlan :: Client.Options -> PartialPlan-optionsToPlan Client.Options {..}-  =  dbnameToPlan (getLast dbname)-  <> userToPlan (getLast user)+optionsToPlan opts@Client.Options {..}+  =  maybe mempty dbnameToPlan (getLast dbname)+  <> maybe mempty userToPlan (getLast user)+  <> clientOptionsToPlan opts -userToPlan :: Maybe String -> PartialPlan-userToPlan = \case-  Nothing -> mempty-  Just user -> mempty-    { partialPlanCreateDb = Mappend $ Just $ mempty-      { partialProcessConfigCmdLine = Mappend $ mempty-          { partialCommandLineArgsKeyBased = Map.singleton "--username=" $ Just user-          }-      }-    , partialPlanInitDb = Mappend $ Just $ mempty-      { partialProcessConfigCmdLine =  Mappend $ mempty-          { partialCommandLineArgsKeyBased = Map.singleton "--username=" $ Just user-          }-      }+-- | Wrap the 'Client.Options' in an appropiate+--   'PartialPostgresPlan'+clientOptionsToPlan :: Client.Options -> PartialPlan+clientOptionsToPlan opts = mempty+  { partialPlanPostgres = mempty+    { partialPostgresPlanClientConfig = opts     }+  } -dbnameToPlan :: Maybe String -> PartialPlan-dbnameToPlan = \case-  Nothing -> mempty-  Just dbName -> mempty-    { partialPlanCreateDb = Mappend $ Just $ mempty-      { partialProcessConfigCmdLine = Mappend $ mempty-        { partialCommandLineArgsIndexBased = Map.singleton 0 dbName+-- | Create a 'PartialPlan' given a user+userToPlan :: String -> PartialPlan+userToPlan user = mempty+  { partialPlanCreateDb = Mappend $ Just $ mempty+    { partialProcessConfigCmdLine = Mappend $ mempty+        { partialCommandLineArgsKeyBased = Map.singleton "--username=" $ Just user         }+    }+  , partialPlanInitDb = Mappend $ Just $ mempty+    { partialProcessConfigCmdLine =  Mappend $ mempty+        { partialCommandLineArgsKeyBased = Map.singleton "--username=" $ Just user+        }+    }+  }++-- | Adds a @createdb@ PartialProcessPlan with the argument+--   as the database name.+dbnameToPlan :: String -> PartialPlan+dbnameToPlan dbName = mempty+  { partialPlanCreateDb = Mappend $ Just $ mempty+    { partialProcessConfigCmdLine = Mappend $ mempty+      { partialCommandLineArgsIndexBased = Map.singleton 0 dbName       }     }+  } -hostToSocketClass :: Maybe String -> PartialSocketClass-hostToSocketClass = \case-  Nothing -> mempty-  Just hostOrSocketPath -> case hostOrSocketPath of-    '/' : _ -> PUnixSocket $ PPermanent hostOrSocketPath-    _ -> PIpSocket $ pure hostOrSocketPath+-- | Parse a host string as either an UNIX domain socket directory+--   or a domain or IP.+hostToSocketClass :: String -> PartialSocketClass+hostToSocketClass hostOrSocketPath = case hostOrSocketPath of+  '/' : _ -> PUnixSocket $ PPermanent hostOrSocketPath+  _ -> PIpSocket $ pure hostOrSocketPath
tmp-postgres.cabal view
@@ -1,5 +1,5 @@ name:                tmp-postgres-version:             1.2.0.0+version:             1.2.0.1 synopsis: Start and stop a temporary postgres description:  @tmp-postgres@ provides functions creating a temporary @postgres@ instance.