52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#include "QueryFixture.hpp"
|
|
|
|
#include "matador/query/query.hpp"
|
|
|
|
#include "matador/sql/dialect.hpp"
|
|
|
|
#include "catch2/catch_test_macros.hpp"
|
|
|
|
namespace matador::test {
|
|
|
|
QueryFixture::QueryFixture()
|
|
: db(connection::dns)
|
|
, repo(db.dialect().default_schema_name())
|
|
{
|
|
REQUIRE(db.open());
|
|
}
|
|
|
|
QueryFixture::~QueryFixture() {
|
|
while (!tables_to_drop.empty()) {
|
|
drop_table_if_exists(tables_to_drop.top());
|
|
tables_to_drop.pop();
|
|
}
|
|
}
|
|
|
|
void QueryFixture::check_table_exists(const std::string &table_name) const
|
|
{
|
|
auto result = db.exists(table_name);
|
|
REQUIRE(result.is_ok());
|
|
REQUIRE(*result);
|
|
}
|
|
|
|
void QueryFixture::check_table_not_exists(const std::string &table_name) const
|
|
{
|
|
auto result = db.exists(table_name);
|
|
REQUIRE(result.is_ok());
|
|
REQUIRE(!*result);
|
|
}
|
|
|
|
void QueryFixture::drop_table_if_exists(const std::string &table_name) const {
|
|
const auto result = db.exists(table_name).and_then([&table_name, this](const bool exists) {
|
|
if (exists) {
|
|
auto res = query::query::drop()
|
|
.table(table_name)
|
|
.execute(db);
|
|
REQUIRE(res);
|
|
this->check_table_not_exists(table_name);
|
|
}
|
|
return utils::ok(true);
|
|
});
|
|
}
|
|
|
|
} |