IHP Api Reference
Safe HaskellSafe-Inferred

IHP.Test.Database

Synopsis

Documentation

data TestDatabase Source #

Constructors

TestDatabase 

Fields

createTestDatabase :: ByteString -> IO TestDatabase Source #

Given a Postgres Database URL it creates a new randomly named database on the database server. Returns a database url to the freshly created database

>>> createTestDatabase "postgresql:///app?host=/myapp/build/db"
TestDatabase { name = "test-7d3bd463-4cce-413f-a272-ac52e5d93739", url = "postgresql:///test-7d3bd463-4cce-413f-a272-ac52e5d93739?host=/myapp/build/db" }

deleteDatabase :: ByteString -> TestDatabase -> IO () Source #

Given the master connection url and the open test database, this will clean up the test database

>>> deleteDatabase "postgresql:///app?host=/myapp/build/db" TestDatabase { name = "test-7d3bd463-4cce-413f-a272-ac52e5d93739", url = "postgresql:///test-7d3bd463-4cce-413f-a272-ac52e5d93739?host=/myapp/build/db" }

The master connection url needs to be passed as we cannot drop the database we're currently connected to, and therefore we cannot use the test database itself.

withConnection :: ByteString -> (Connection -> IO c) -> IO c Source #