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


-- | Helpers for creating database tests with hspec and pg-transact
--   
--   Helpers for creating database tests with hspec and pg-transact
--   
--   <tt>hspec-pg-transact</tt> utilizes <tt>tmp-postgres</tt> to
--   automatically and connect to a temporary instance of <tt>postgres</tt>
--   on a random port.
--   
--   <pre>
--   describeDB migrate "Query” $
--     itDB "work" $ do
--       execute_ [sql|
--         INSERT INTO things
--         VALUES (‘me’) |]
--       query_ [sql|
--         SELECT name
--          FROM things |]
--         `shouldReturn` [Only "me"]
--   </pre>
--   
--   In the example above <tt>describeDB</tt> wraps <tt>describe</tt> with
--   a <tt>beforeAll</tt> hook for creating a db and a <tt>afterAll</tt>
--   hook for stopping a db.
--   
--   Tests can be written with <tt>itDB</tt> which is wrapper around
--   <tt>it</tt> that uses the passed in <tt>Connection</tt> to run a db
--   transaction automatically for the test.
--   
--   The libary also provides a few other functions for more fine grained
--   control over running transactions in tests.
@package hspec-pg-transact
@version 0.1.0.2


-- | Helpers for creating database tests with hspec and pg-transact
--   
--   <tt>hspec-pg-transact</tt> utilizes <tt>tmp-postgres</tt> to
--   automatically and connect to a temporary instance of <tt>postgres</tt>
--   on a random port.
--   
--   <pre>
--   <a>describeDB</a> migrate "Query” $
--     itDB "work" $ do
--       <a>execute_</a> [sql|
--         INSERT INTO things
--         VALUES (‘me’) |]
--       <a>query_</a> [sql|
--         SELECT name
--          FROM things |]
--         <a>shouldReturn</a> [Only "me"]
--   </pre>
--   
--   In the example above <a>describeDB</a> wraps <a>describe</a> with a
--   <a>beforeAll</a> hook for creating a db and a <a>afterAll</a> hook for
--   stopping a db. . Tests can be written with <a>itDB</a> which is
--   wrapper around <a>it</a> that uses the passed in <a>TestDB</a> to run
--   a db transaction automatically for the test.
--   
--   The libary also provides a few other functions for more fine grained
--   control over running transactions in tests.
module Test.Hspec.DB
data TestDB
TestDB :: DB -> Pool Connection -> TestDB

-- | Handle for temporary <tt>postgres</tt> process
[tempDB] :: TestDB -> DB

-- | Pool of 50 connections to the temporary <tt>postgres</tt>
[pool] :: TestDB -> Pool Connection

-- | Start a temporary <tt>postgres</tt> process and create a pool of
--   connections to it
setupDB :: (Connection -> IO ()) -> IO TestDB

-- | Drop all the connections and shutdown the <tt>postgres</tt> process
teardownDB :: TestDB -> IO ()

-- | Run an <a>IO</a> action with a connection from the pool
withPool :: TestDB -> (Connection -> IO a) -> IO a

-- | Run an <a>DB</a> transaction. Uses <a>runDBTSerializable</a>.
withDB :: DB a -> TestDB -> IO a

-- | Flipped version of <a>withDB</a>
runDB :: TestDB -> DB a -> IO a

-- | Helper for writing tests. Wrapper around <a>it</a> that uses the
--   passed in <a>TestDB</a> to run a db transaction automatically for the
--   test.
itDB :: String -> DB a -> SpecWith TestDB

-- | Wraps <a>describe</a> with a
--   
--   <pre>
--   <a>beforeAll</a> (<a>setupDB</a> migrate)
--   </pre>
--   
--   hook for creating a db and a
--   
--   <pre>
--   <a>afterAll</a> <a>teardownDB</a>
--   </pre>
--   
--   hook for stopping a db.
describeDB :: (Connection -> IO ()) -> String -> SpecWith TestDB -> Spec
