implemented lazy loading for object_ptr and belongs_to
This commit is contained in:
@@ -21,24 +21,18 @@ using namespace matador::query;
|
||||
using namespace matador::test;
|
||||
using namespace matador::query::meta;
|
||||
|
||||
namespace matador::test::detail {
|
||||
template<class Type, typename... Args>
|
||||
[[maybe_unused]] object_ptr<Type> make_object_ptr(Args&&... args) {
|
||||
return object_ptr(new Type(std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
|
||||
class StatementTestFixture : public QueryFixture {
|
||||
public:
|
||||
StatementTestFixture() {
|
||||
REQUIRE(repo.attach<airplane>("airplanes"));
|
||||
repo.initialize_executor(db);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<object_ptr<airplane>> planes{
|
||||
matador::test::detail::make_object_ptr<airplane>(1, "Airbus", "A380"),
|
||||
matador::test::detail::make_object_ptr<airplane>(2, "Boeing", "707"),
|
||||
matador::test::detail::make_object_ptr<airplane>(3, "Boeing", "747")
|
||||
std::vector<airplane> planes {
|
||||
{1, "Airbus", "A380"},
|
||||
{2, "Boeing", "707"},
|
||||
{3, "Boeing", "747"}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -53,7 +47,7 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
REQUIRE(stmt.is_ok());
|
||||
|
||||
for (const auto &plane: planes) {
|
||||
auto res = stmt->bind(*plane).execute();
|
||||
auto res = stmt->bind(plane).execute();
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
stmt->reset();
|
||||
@@ -66,9 +60,9 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
REQUIRE(result.is_ok());
|
||||
size_t index{0};
|
||||
for (const auto &i: *result) {
|
||||
REQUIRE(i.id == planes[index]->id);
|
||||
REQUIRE(i.brand == planes[index]->brand);
|
||||
REQUIRE(i.model == planes[index++]->model);
|
||||
REQUIRE(i->id == planes[index].id);
|
||||
REQUIRE(i->brand == planes[index].brand);
|
||||
REQUIRE(i->model == planes[index++].model);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,13 +70,13 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
for (const auto &plane: planes) {
|
||||
auto res = query::insert()
|
||||
.into(AIRPLANE, {AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.values(*plane)
|
||||
.values(plane)
|
||||
.execute(db);
|
||||
REQUIRE(res.is_ok());
|
||||
REQUIRE(*res == 1);
|
||||
}
|
||||
|
||||
auto stmt = query::select(generator::columns<airplane>(repo))
|
||||
auto stmt = query::select({AIRPLANE.id, AIRPLANE.brand, AIRPLANE.model})
|
||||
.from(AIRPLANE)
|
||||
.where(AIRPLANE.brand == _)
|
||||
.prepare(db);
|
||||
@@ -93,9 +87,9 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
|
||||
REQUIRE(result.is_ok());
|
||||
for (const auto &i: *result) {
|
||||
REQUIRE(i.id == planes[0]->id);
|
||||
REQUIRE(i.brand == planes[0]->brand);
|
||||
REQUIRE(i.model == planes[0]->model);
|
||||
REQUIRE(i->id == planes[0].id);
|
||||
REQUIRE(i->brand == planes[0].brand);
|
||||
REQUIRE(i->model == planes[0].model);
|
||||
}
|
||||
|
||||
stmt->reset();
|
||||
@@ -106,9 +100,9 @@ TEST_CASE_METHOD(StatementTestFixture, "Create prepared statement", "[statement]
|
||||
size_t index{1};
|
||||
REQUIRE(result.is_ok());
|
||||
for (const auto &i: *result) {
|
||||
REQUIRE(i.id == planes[index]->id);
|
||||
REQUIRE(i.brand == planes[index]->brand);
|
||||
REQUIRE(i.model == planes[index++]->model);
|
||||
REQUIRE(i->id == planes[index].id);
|
||||
REQUIRE(i->brand == planes[index].brand);
|
||||
REQUIRE(i->model == planes[index++].model);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user