use table metas where possible
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "matador/object/attribute.hpp"
|
||||
#include "matador/object/object_generator.hpp"
|
||||
|
||||
#include "matador/sql/connection.hpp"
|
||||
@@ -14,12 +13,13 @@
|
||||
#include "QueryFixture.hpp"
|
||||
|
||||
#include "models/airplane.hpp"
|
||||
#include "models/location.hpp"
|
||||
#include "models/model_metas.hpp"
|
||||
|
||||
using namespace matador::sql;
|
||||
using namespace matador::object;
|
||||
using namespace matador::query;
|
||||
using namespace matador::test;
|
||||
using namespace matador::query::meta;
|
||||
|
||||
namespace matador::test::detail {
|
||||
template<class Type, typename... Args>
|
||||
@@ -31,14 +31,7 @@ template<class Type, typename... Args>
|
||||
class StatementTestFixture : public QueryFixture {
|
||||
public:
|
||||
StatementTestFixture() {
|
||||
const auto obj = object_generator::generate<airplane>(repo.repo(), "airplane");
|
||||
const auto res = query::create()
|
||||
.table(obj->name())
|
||||
.columns(obj->attributes())
|
||||
.constraints(obj->constraints())
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
tables_to_drop.emplace("airplane");
|
||||
REQUIRE(repo.attach<airplane>("airplanes"));
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -51,11 +44,10 @@ protected:
|
||||
|
||||
TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]") {
|
||||
using namespace matador::utils;
|
||||
REQUIRE(repo.attach<airplane>("airplane"));
|
||||
table ap{"airplane"};
|
||||
REQUIRE(repo.create(db));
|
||||
SECTION("Insert with prepared statement and placeholder") {
|
||||
auto stmt = query::insert()
|
||||
.into("airplane", generator::columns<airplane>(repo))
|
||||
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.values(generator::placeholders<airplane>())
|
||||
.prepare(db);
|
||||
REQUIRE(stmt.is_ok());
|
||||
@@ -67,8 +59,8 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
stmt->reset();
|
||||
}
|
||||
|
||||
auto result = query::select(generator::columns<airplane>(repo))
|
||||
.from(ap)
|
||||
auto result = query::select({AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.from(AIRPLANE)
|
||||
.fetch_all<airplane>(db);
|
||||
|
||||
REQUIRE(result.is_ok());
|
||||
@@ -83,7 +75,7 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
SECTION("Select with prepared statement") {
|
||||
for (const auto &plane: planes) {
|
||||
auto res = query::insert()
|
||||
.into("airplane", generator::columns<airplane>(repo))
|
||||
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.values(*plane)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
@@ -91,8 +83,8 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
}
|
||||
|
||||
auto stmt = query::select(generator::columns<airplane>(repo))
|
||||
.from(ap)
|
||||
.where("brand"_col == _)
|
||||
.from(AIRPLANE)
|
||||
.where(AIRPLANE.brand == _)
|
||||
.prepare(db);
|
||||
REQUIRE(stmt.is_ok());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user