tmp-postgres-1.14.0.1: Start and stop a temporary postgres

Safe HaskellNone
LanguageHaskell2010

Database.Postgres.Temp.Internal.Config

Description

This module provides types and functions for combining partial configs into a complete configs to ultimately make a CompletePlan.

This module has two classes of types.

Types like ProcessConfig that could be used by any library that needs to combine process options.

Finally it has types and functions for creating CompletePlans that use temporary resources. This is used to create the default behavior of startConfig and related functions. |

Synopsis

Documentation

data EnvironmentVariables Source #

The environment variables can be declared to inherit from the running process or they can be specifically added.

Since: 1.12.0.0

Instances
Eq EnvironmentVariables Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Show EnvironmentVariables Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Generic EnvironmentVariables Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Associated Types

type Rep EnvironmentVariables :: Type -> Type #

Semigroup EnvironmentVariables Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Monoid EnvironmentVariables Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Pretty EnvironmentVariables Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

type Rep EnvironmentVariables Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

type Rep EnvironmentVariables = D1 (MetaData "EnvironmentVariables" "Database.Postgres.Temp.Internal.Config" "tmp-postgres-1.14.0.1-fG3XxSoBTU3GmsPBDQhmh" False) (C1 (MetaCons "EnvironmentVariables" PrefixI True) (S1 (MetaSel (Just "inherit") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Last Bool)) :*: S1 (MetaSel (Just "specific") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Map String String))))

completeEnvironmentVariables :: [(String, String)] -> EnvironmentVariables -> Either [String] [(String, String)] Source #

Combine the current environment (if indicated by inherit) with specific.

Since: 1.12.0.0

data CommandLineArgs Source #

A type to help combine command line Args.

Since: 1.12.0.0

Constructors

CommandLineArgs 

Fields

  • keyBased :: Map String (Maybe String)

    Args of the form -h foo, --host=foo and --switch. The key is mappended 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.

  • indexBased :: Map Int String

    Args that appear at the end of the key based Args. The Dual monoid is used so the last key wins.

Instances
Eq CommandLineArgs Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Show CommandLineArgs Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Generic CommandLineArgs Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Associated Types

type Rep CommandLineArgs :: Type -> Type #

Semigroup CommandLineArgs Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Monoid CommandLineArgs Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Pretty CommandLineArgs Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

type Rep CommandLineArgs Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

type Rep CommandLineArgs = D1 (MetaData "CommandLineArgs" "Database.Postgres.Temp.Internal.Config" "tmp-postgres-1.14.0.1-fG3XxSoBTU3GmsPBDQhmh" False) (C1 (MetaCons "CommandLineArgs" PrefixI True) (S1 (MetaSel (Just "keyBased") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Map String (Maybe String))) :*: S1 (MetaSel (Just "indexBased") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Map Int String))))

completeCommandLineArgs :: CommandLineArgs -> [String] Source #

This convert the CommandLineArgs to '[String]'.

Since: 1.12.0.0

data ProcessConfig Source #

Process configuration

Since: 1.12.0.0

Constructors

ProcessConfig 

Fields

Instances
Eq ProcessConfig Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Show ProcessConfig Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Generic ProcessConfig Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Associated Types

type Rep ProcessConfig :: Type -> Type #

Semigroup ProcessConfig Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Monoid ProcessConfig Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Pretty ProcessConfig Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

type Rep ProcessConfig Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

standardProcessConfig :: ProcessConfig Source #

The standardProcessConfig sets the handles to stdin, stdout and stderr and inherits the environment variables from the calling process.

Since: 1.12.0.0

devNull :: Handle Source #

A global reference to devnull Handle.

Since: 1.12.0.0

silentProcessConfig :: ProcessConfig Source #

silentProcessConfig sets the handles to devnull and inherits the environment variables from the calling process.

Since: 1.12.0.0

completeProcessConfig :: [(String, String)] -> ProcessConfig -> Either [String] CompleteProcessConfig Source #

Turn a ProcessConfig into a ProcessConfig. Fails if any values are missing.

Since: 1.12.0.0

toFilePath :: CompleteDirectoryType -> FilePath Source #

Get the file path of a CompleteDirectoryType, regardless if it is a CPermanent or CTemporary type.

Since: 1.12.0.0

data DirectoryType Source #

Used to specify a Temporary folder that is automatically cleaned up or a Permanent folder which is not automatically cleaned up.

Since: 1.12.0.0

Constructors

Permanent FilePath

A permanent file that should not be generated.

Temporary

A temporary file that needs to generated.

Instances
Eq DirectoryType Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Ord DirectoryType Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Show DirectoryType Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Semigroup DirectoryType Source #

Takes the last Permanent value.

Instance details

Defined in Database.Postgres.Temp.Internal.Config

Monoid DirectoryType Source #

Temporary as mempty

Instance details

Defined in Database.Postgres.Temp.Internal.Config

Pretty DirectoryType Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

setupDirectoryType Source #

Arguments

:: String

Temporary directory configuration

-> String

Directory pattern

-> DirectoryType 
-> IO CompleteDirectoryType 

Either create aCTemporary directory or do nothing to a CPermanent one.

Since: 1.12.0.0

cleanupDirectoryType :: CompleteDirectoryType -> IO () Source #

Either remove a CTemporary directory or do nothing to a CPermanent one.

data CompleteSocketClass Source #

A type for configuring the listening address of the postgres process. postgres can listen on several types of sockets simulatanously but we don't support that behavior. One can either listen on a IP based socket or a UNIX domain socket.

Since: 1.12.0.0

Constructors

CIpSocket String

IP socket type. The String is either an IP address or a host that will resolve to an IP address.

CUnixSocket CompleteDirectoryType

UNIX domain socket

Instances
Eq CompleteSocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Ord CompleteSocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Show CompleteSocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Generic CompleteSocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Associated Types

type Rep CompleteSocketClass :: Type -> Type #

Pretty CompleteSocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

type Rep CompleteSocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

type Rep CompleteSocketClass = D1 (MetaData "CompleteSocketClass" "Database.Postgres.Temp.Internal.Config" "tmp-postgres-1.14.0.1-fG3XxSoBTU3GmsPBDQhmh" False) (C1 (MetaCons "CIpSocket" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)) :+: C1 (MetaCons "CUnixSocket" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 CompleteDirectoryType)))

socketClassToConfig :: CompleteSocketClass -> [String] Source #

Create the extra config lines for listening based on the CompleteSocketClass.

socketClassToHostFlag :: CompleteSocketClass -> [(String, Maybe String)] Source #

Many processes require a "host" flag. We can generate one from the CompleteSocketClass.

socketClassToHost :: CompleteSocketClass -> String Source #

Get the IP address, host name or UNIX domain socket directory as a String.

data SocketClass Source #

SocketClass is used to specify how postgres should listen for connections The two main options are a IpSocket which takes a hostname or IP address. if not is given the default it "127.0.0.1". Alternatively one can specify UnixSocket for a UNIX domain socket. If a directory is specified the socket will live in that folder. Otherwise a temporary folder will get created for the socket.

Since: 1.12.0.0

Constructors

IpSocket (Last String)

The monoid for combining IP address configuration.

UnixSocket DirectoryType

The monoid for combining UNIX socket configuration.

Instances
Eq SocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Ord SocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Show SocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Generic SocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Associated Types

type Rep SocketClass :: Type -> Type #

Semigroup SocketClass Source #

Last IpSocket wins. UnixSocket DirectoryType as mappended together.

Instance details

Defined in Database.Postgres.Temp.Internal.Config

Monoid SocketClass Source #

Treats UnixSocket mempty as mempty.

Instance details

Defined in Database.Postgres.Temp.Internal.Config

Pretty SocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

type Rep SocketClass Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

type Rep SocketClass = D1 (MetaData "SocketClass" "Database.Postgres.Temp.Internal.Config" "tmp-postgres-1.14.0.1-fG3XxSoBTU3GmsPBDQhmh" False) (C1 (MetaCons "IpSocket" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Last String))) :+: C1 (MetaCons "UnixSocket" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 DirectoryType)))

setupSocketClass Source #

Arguments

:: String

Temporary directory.

-> SocketClass

The type of socket.

-> IO CompleteSocketClass 

Turn a SocketClass to a CompleteSocketClass. If the IpSocket is Nothing default to "127.0.0.1". If the is a UnixSocket optionally create a temporary directory if configured to do so.

cleanupSocketConfig :: CompleteSocketClass -> IO () Source #

Cleanup the UNIX socket temporary directory if one was created.

data PostgresPlan Source #

postgres process config and corresponding client connection Options.

Since: 1.12.0.0

Constructors

PostgresPlan 

Fields

data Plan Source #

Describe how to run initdb, createdb and postgres

Since: 1.12.0.0

Constructors

Plan 

Fields

Instances
Generic Plan Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Associated Types

type Rep Plan :: Type -> Type #

Methods

from :: Plan -> Rep Plan x #

to :: Rep Plan x -> Plan #

Semigroup Plan Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Methods

(<>) :: Plan -> Plan -> Plan #

sconcat :: NonEmpty Plan -> Plan #

stimes :: Integral b => b -> Plan -> Plan #

Monoid Plan Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Methods

mempty :: Plan #

mappend :: Plan -> Plan -> Plan #

mconcat :: [Plan] -> Plan #

Pretty Plan Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Methods

pretty :: Plan -> Doc #

prettyList :: [Plan] -> Doc #

type Rep Plan Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

completePlan :: [(String, String)] -> Plan -> Either [String] CompletePlan Source #

Turn a Plan into a CompletePlan. Fails if any values are missing.

data Config Source #

The high level options for overriding default behavior.

Since: 1.12.0.0

Constructors

Config 

Fields

Instances
Generic Config Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Associated Types

type Rep Config :: Type -> Type #

Methods

from :: Config -> Rep Config x #

to :: Rep Config x -> Config #

Semigroup Config Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Monoid Config Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Pretty Config Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

Methods

pretty :: Config -> Doc #

prettyList :: [Config] -> Doc #

type Rep Config Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

toPlan Source #

Arguments

:: Bool

Make initdb options

-> Bool

Make createdb options

-> Int

port

-> CompleteSocketClass

Whether to listen on a IP address or UNIX domain socket

-> FilePath

The postgres data directory

-> Plan 

Create a Plan that sets the command line options of all processes (initdb, postgres and createdb). This the generated plan that is combined with the extra plan from startConfig.

setupConfig Source #

Arguments

:: Config

extra Config to mappend after the generated Config.

-> IO Resources 

Create all the temporary resources from a Config. This also combines the Plan from toPlan with the extra Config passed in.

cleanupConfig :: Resources -> IO () Source #

Free the temporary resources created by setupConfig.

prettyPrintConfig :: Config -> String Source #

Display a Config.

Since: 1.12.0.0

data Resources Source #

Resources holds a description of the temporary folders (if there are any) and includes the final CompletePlan that can be used with startPlan. See setupConfig for an example of how to create a Resources.

Since: 1.12.0.0

Constructors

Resources 

Fields

Instances
Pretty Resources Source # 
Instance details

Defined in Database.Postgres.Temp.Internal.Config

makeResourcesDataDirPermanent :: Resources -> Resources Source #

Make the resourcesDataDir CPermanent so it will not get cleaned up.

Since: 1.12.0.0

optionsToConfig :: Options -> Config Source #

Attempt to create a config from a Options. This is useful if want to create a database owned by a specific user you will also log in as among other use cases. It is possible some Options are not supported so don't hesitate to open an issue on github if you find one.

type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t Source #

Local Lens alias.

type Lens' s a = Lens s s a a Source #

Local Lens' alias.

stdErrL :: Lens' ProcessConfig (Last Handle) Source #

Lens for stdErr

Since: 1.12.0.0

stdInL :: Lens' ProcessConfig (Last Handle) Source #

Lens for stdIn.

Since: 1.12.0.0

stdOutL :: Lens' ProcessConfig (Last Handle) Source #

Lens for stdOut.

Since: 1.12.0.0

loggerL :: Lens' Plan (Last Logger) Source #

Lens for logger.

Since: 1.12.0.0

planL :: Lens' Config Plan Source #

Lens for plan.

Since: 1.12.0.0

portL :: Lens' Config (Last (Maybe Int)) Source #

Lens for port.

Since: 1.12.0.0