withDb :: (IO Context -> TestTree) -> IO Context -> TestTree
withDb test getContext =
  withResource
    (getContext >>= createTempDb)
    (fmap Response.asBool . Database.delete >=> throwOnError)
    test
  where
    createTempDb ctx = do
      Response.asBool <$> Database.create ctx >>= throwOnError
      return ctx
withDb :: (IO Context -> TestTree) -> IO Context -> TestTree
withDb test getContext =
  withResource
    (getContext >>= createTempDb)
    (fmap Response.asBool . Database.delete >=> throwOnError)
    test
  where
    createTempDb ctx = do
      Response.asBool <$> Database.create ctx >>= throwOnError
      return ctx
withDb test getContext =
  withResource
    (getContext >>= createTempDb)
    (fmap Response.asBool . Database.delete >=> throwOnError)
    test
  where
    createTempDb ctx = do
      Response.asBool <$> Database.create ctx >>= throwOnError
      return ctx