Safe Haskell | None |
---|---|
Language | Haskell2010 |
Testing with an in-memory sqlite database using persistent-sqlite
For a fully worked example, see sydtest-yesod/blog-example.
Synopsis
- persistSqliteSpec :: Migration -> SpecWith ConnectionPool -> SpecWith a
- withConnectionPool :: Migration -> (ConnectionPool -> IO ()) -> IO ()
- connectionPoolSetupFunc :: Migration -> SetupFunc () ConnectionPool
- connectionPoolSetupFunc' :: SetupFunc Migration ConnectionPool
- runSqlPool :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> m a
- runSqliteTest :: ConnectionPool -> SqlPersistT IO a -> IO a
Documentation
persistSqliteSpec :: Migration -> SpecWith ConnectionPool -> SpecWith a Source #
Declare a test suite that uses a database connection.
This sets up the database connection around every test, so state is not preserved accross tests.
withConnectionPool :: Migration -> (ConnectionPool -> IO ()) -> IO () Source #
Set up a sqlite connection and migrate it to run the given function.
connectionPoolSetupFunc :: Migration -> SetupFunc () ConnectionPool Source #
The SetupFunc
version of withConnectionPool
.
connectionPoolSetupFunc' :: SetupFunc Migration ConnectionPool Source #
A wrapped version of connectionPoolSetupFunc
runSqlPool :: forall backend m a. (MonadUnliftIO m, BackendCompatible SqlBackend backend) => ReaderT backend m a -> Pool backend -> m a #
Get a connection from the pool, run the given action, and then return the connection to the pool.
Note: This function previously timed out after 2 seconds, but this behavior was buggy and caused more problems than it solved. Since version 2.1.2, it performs no timeout checks.
runSqliteTest :: ConnectionPool -> SqlPersistT IO a -> IO a Source #
A flipped version of runSqlPool
to run your tests