-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Start and stop a temporary postgres for testing
--   
--   This module provides functions creating a temporary postgres instance
--   on a random port for testing.
--   
--   <pre>
--   result &lt;- start []
--   case result of
--     Left err -&gt; print err
--     Right tempDB -&gt; do
--       -- Do stuff
--       stop tempDB
--   </pre>
--   
--   The are few different methods for starting <tt>postgres</tt> which
--   provide different methods of dealing with <tt>stdout</tt> and
--   <tt>stderr</tt>.
--   
--   The start methods use a config based on the one used by pg_tmp
--   (http:/<i>ephemeralpg.org</i>), but can be overriden by different
--   values to the first argument of the start functions.
--   
--   WARNING!! Ubuntu's PostgreSQL installation does not put
--   <tt>initdb</tt> on the <tt>PATH</tt>. We need to add it manually. The
--   necessary binaries are in the
--   <tt>/usr/lib/postgresql/VERSION/bin/</tt> directory, and should be
--   added to the <tt>PATH</tt>
--   
--   <pre>
--   echo "export PATH=$PATH:/usr/lib/postgresql/VERSION/bin/" &gt;&gt; /home/ubuntu/.bashrc
--   </pre>
@package tmp-postgres
@version 0.1.1.1

module Database.Postgres.Temp.Internal
openFreePort :: IO Int
waitForDB :: String -> IO ()
data DB
DB :: FilePath -> String -> ProcessHandle -> DB

-- | Temporary directory where the unix socket, logs and data directory
--   live.
[mainDir] :: DB -> FilePath

-- | PostgreSQL connection string.
[connectionString] :: DB -> String

-- | The process handle for the <tt>postgres</tt> process.
[pid] :: DB -> ProcessHandle
data SocketClass
Localhost :: SocketClass
Unix :: SocketClass

-- | start postgres and use the current processes stdout and stderr
start :: [(String, String)] -> IO (Either StartError DB)

-- | start postgres and use the current processes stdout and stderr but use
--   TCP on localhost instead of a unix socket.
startLocalhost :: [(String, String)] -> IO (Either StartError DB)
fourth :: (a, b, c, d) -> d
procWith :: Handle -> Handle -> String -> [String] -> CreateProcess
config :: Maybe FilePath -> String
data StartError
InitDBFailed :: ExitCode -> StartError
CreateDBFailed :: ExitCode -> StartError
throwIfError :: (ExitCode -> StartError) -> ExitCode -> IO ()
pidString :: ProcessHandle -> IO String
runProcessWith :: Handle -> Handle -> String -> String -> [String] -> IO ExitCode

-- | Start postgres and pass in handles for stdout and stderr
startWithHandles :: SocketClass -> [(String, String)] -> Handle -> Handle -> IO (Either StartError DB)
startWithHandlesAndDir :: SocketClass -> [(String, String)] -> FilePath -> Handle -> Handle -> IO (Either StartError DB)
data Event
InitDB :: Event
WriteConfig :: Event
FreePort :: Event
StartPostgres :: Event
WaitForDB :: Event
CreateDB :: Event
Finished :: Event
rmDirIgnoreErrors :: FilePath -> IO ()
startWithLogger :: (Event -> IO ()) -> SocketClass -> [(String, String)] -> FilePath -> Handle -> Handle -> IO (Either StartError DB)

-- | Start postgres and log it's all stdout to {<a>mainDir</a>}/output.txt
--   and {<a>mainDir</a>}/error.txt
startAndLogToTmp :: [(String, String)] -> IO (Either StartError DB)

-- | Stop postgres and clean up the temporary database folder.
stop :: DB -> IO ExitCode
instance GHC.Classes.Ord Database.Postgres.Temp.Internal.Event
instance GHC.Enum.Bounded Database.Postgres.Temp.Internal.Event
instance GHC.Enum.Enum Database.Postgres.Temp.Internal.Event
instance GHC.Classes.Eq Database.Postgres.Temp.Internal.Event
instance GHC.Show.Show Database.Postgres.Temp.Internal.Event
instance GHC.Classes.Eq Database.Postgres.Temp.Internal.StartError
instance GHC.Show.Show Database.Postgres.Temp.Internal.StartError
instance GHC.Generics.Generic Database.Postgres.Temp.Internal.SocketClass
instance GHC.Enum.Bounded Database.Postgres.Temp.Internal.SocketClass
instance GHC.Enum.Enum Database.Postgres.Temp.Internal.SocketClass
instance GHC.Classes.Ord Database.Postgres.Temp.Internal.SocketClass
instance GHC.Read.Read Database.Postgres.Temp.Internal.SocketClass
instance GHC.Classes.Eq Database.Postgres.Temp.Internal.SocketClass
instance GHC.Show.Show Database.Postgres.Temp.Internal.SocketClass
instance GHC.Exception.Exception Database.Postgres.Temp.Internal.StartError


-- | This module provides functions greating a temporary postgres instance
--   on a random port for testing.
--   
--   <pre>
--   result &lt;- <a>start</a> []
--   case result of
--     Left err -&gt; print err
--     Right tempDB -&gt; do
--        -- Do stuff
--        <a>stop</a> tempDB
--   </pre>
--   
--   The are few different methods for starting <tt>postgres</tt> which
--   provide different methods of dealing with <tt>stdout</tt> and
--   <tt>stderr</tt>.
--   
--   The start methods use a config based on the one used by <a>pg_tmp</a>,
--   but can be overriden by in different values to the first argument of
--   the start functions.
--   
--   WARNING!! Ubuntu's PostgreSQL installation does not put
--   <tt>initdb</tt> on the <tt>PATH</tt>. We need to add it manually. The
--   necessary binaries are in the
--   <tt>/usr/lib/postgresql/VERSION/bin/</tt> directory, and should be
--   added to the <tt>PATH</tt>
--   
--   <pre>
--   echo "export PATH=$PATH:/usr/lib/postgresql/VERSION/bin/" &gt;&gt; /home/ubuntu/.bashrc
--   </pre>
module Database.Postgres.Temp
data DB
DB :: FilePath -> String -> ProcessHandle -> DB

-- | Temporary directory where the unix socket, logs and data directory
--   live.
[mainDir] :: DB -> FilePath

-- | PostgreSQL connection string.
[connectionString] :: DB -> String

-- | The process handle for the <tt>postgres</tt> process.
[pid] :: DB -> ProcessHandle
data StartError
InitDBFailed :: ExitCode -> StartError
CreateDBFailed :: ExitCode -> StartError

-- | start postgres and use the current processes stdout and stderr
start :: [(String, String)] -> IO (Either StartError DB)

-- | start postgres and use the current processes stdout and stderr but use
--   TCP on localhost instead of a unix socket.
startLocalhost :: [(String, String)] -> IO (Either StartError DB)

-- | Start postgres and log it's all stdout to {<a>mainDir</a>}/output.txt
--   and {<a>mainDir</a>}/error.txt
startAndLogToTmp :: [(String, String)] -> IO (Either StartError DB)

-- | Start postgres and pass in handles for stdout and stderr
startWithHandles :: SocketClass -> [(String, String)] -> Handle -> Handle -> IO (Either StartError DB)

-- | Stop postgres and clean up the temporary database folder.
stop :: DB -> IO ExitCode
data SocketClass
Localhost :: SocketClass
Unix :: SocketClass
