implemented lazy loading for object_ptr and belongs_to
This commit is contained in:
@@ -18,8 +18,7 @@ using namespace matador::test;
|
||||
TEST_CASE_METHOD(SessionFixture, "Session insert test", "[session][insert]") {
|
||||
const auto result = schema.attach<airplane>("airplanes")
|
||||
.and_then([this] {
|
||||
const auto conn = pool.acquire();
|
||||
return schema.create(*conn);
|
||||
return schema.create(db);
|
||||
} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
@@ -37,8 +36,7 @@ TEST_CASE_METHOD(SessionFixture, "Session insert test", "[session][insert]") {
|
||||
TEST_CASE_METHOD(SessionFixture, "Session update test", "[session][update]") {
|
||||
const auto res = schema.attach<airplane>("airplanes")
|
||||
.and_then([this] {
|
||||
const auto conn = pool.acquire();
|
||||
return schema.create(*conn);
|
||||
return schema.create(db);
|
||||
} );
|
||||
REQUIRE(res.is_ok());
|
||||
|
||||
@@ -69,12 +67,11 @@ TEST_CASE_METHOD(SessionFixture, "Session update test", "[session][update]") {
|
||||
|
||||
TEST_CASE_METHOD(SessionFixture, "Session delete test", "[session][delete]") {
|
||||
const auto res = schema.attach<airplane>("airplanes")
|
||||
.and_then([this] {
|
||||
const auto conn = pool.acquire();
|
||||
return schema.create(*conn);
|
||||
} );
|
||||
.and_then([this] { return schema.create(db); } );
|
||||
REQUIRE(res.is_ok());
|
||||
|
||||
schema.initialize_executor(ses);
|
||||
|
||||
auto result = ses.insert<airplane>(1, "Boeing", "747");
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
@@ -94,10 +91,7 @@ TEST_CASE_METHOD(SessionFixture, "Session delete test", "[session][delete]") {
|
||||
TEST_CASE_METHOD(SessionFixture, "Session relation test", "[session][relation]") {
|
||||
const auto result = schema.attach<airplane>("airplanes")
|
||||
.and_then([this] { return schema.attach<flight>("flights"); } )
|
||||
.and_then([this] {
|
||||
const auto conn = pool.acquire();
|
||||
return schema.create(*conn);
|
||||
} );
|
||||
.and_then([this] { return schema.create(db); } );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto plane = ses.insert<airplane>(1, "Boeing", "A380");
|
||||
@@ -118,10 +112,7 @@ TEST_CASE_METHOD(SessionFixture, "Session relation test", "[session][relation]")
|
||||
|
||||
TEST_CASE_METHOD(SessionFixture, "Use session to find object with id", "[session][find]") {
|
||||
const auto result = schema.attach<airplane>("airplanes")
|
||||
.and_then([this] {
|
||||
const auto conn = pool.acquire();
|
||||
return schema.create(*conn);
|
||||
} );
|
||||
.and_then([this] { return schema.create(db); } );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
auto a380 = ses.insert<airplane>(1, "Boeing", "A380");
|
||||
@@ -141,8 +132,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find object with id", "[session
|
||||
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects", "[session][find]") {
|
||||
const auto result = schema.attach<airplane>("airplanes")
|
||||
.and_then([this] {
|
||||
const auto conn = pool.acquire();
|
||||
return schema.create(*conn);
|
||||
return schema.create(db);
|
||||
} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
@@ -167,9 +157,9 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects", "[session][f
|
||||
auto all_planes = find_result.release();
|
||||
size_t index {0};
|
||||
for (const auto &i: all_planes) {
|
||||
REQUIRE(i.id == std::get<0>(expected_result[index]));
|
||||
REQUIRE(i.brand == std::get<1>(expected_result[index]));
|
||||
REQUIRE(i.model == std::get<2>(expected_result[index]));
|
||||
REQUIRE(i->id == std::get<0>(expected_result[index]));
|
||||
REQUIRE(i->brand == std::get<1>(expected_result[index]));
|
||||
REQUIRE(i->model == std::get<2>(expected_result[index]));
|
||||
++index;
|
||||
}
|
||||
}
|
||||
@@ -177,17 +167,16 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects", "[session][f
|
||||
TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-many lazy relation", "[session][find][one-to-many][eager]") {
|
||||
auto result = schema.attach<author>("authors")
|
||||
.and_then( [this] { return schema.attach<book>("books"); } )
|
||||
.and_then([this] {
|
||||
const auto conn = pool.acquire();
|
||||
return schema.create(*conn);
|
||||
} );
|
||||
.and_then([this] { return schema.create(db); } );
|
||||
|
||||
std::vector<std::unique_ptr<author>> authors;
|
||||
authors.emplace_back(new author{1, "Michael", "Crichton", "23.10.1942", 1975, true, {}});
|
||||
authors.emplace_back(new author{ 2, "Steven", "King", "21.9.1947", 1956, false, {}});
|
||||
schema.initialize_executor(ses);
|
||||
std::vector authors {
|
||||
object_ptr{std::make_shared<author>(1, "Michael", "Crichton", "23.10.1942", 1975, true)},
|
||||
object_ptr{std::make_shared<author>( 2, "Steven", "King", "21.9.1947", 1956, false)}
|
||||
};
|
||||
|
||||
for (auto &&a: authors) {
|
||||
auto res = ses.insert(a.release());
|
||||
for (const auto &a: authors) {
|
||||
auto res = ses.insert(a);
|
||||
REQUIRE(res.is_ok());
|
||||
}
|
||||
|
||||
@@ -197,7 +186,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
|
||||
std::vector<object_ptr<author>> author_repo;
|
||||
for (auto it = all_authors.begin(); it != all_authors.end(); ++it) {
|
||||
std::cout << "author: " << it->first_name << " (books: " << it->books.size() << ")\n";
|
||||
author_repo.emplace_back(it.release());
|
||||
author_repo.emplace_back(it.optr());
|
||||
}
|
||||
REQUIRE(author_repo.size() == 2);
|
||||
|
||||
@@ -231,13 +220,12 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
|
||||
auto result = schema.attach<department>("departments")
|
||||
.and_then( [this] { return schema.attach<employee>("employees"); } )
|
||||
.and_then([this] {
|
||||
const auto conn = pool.acquire();
|
||||
return schema.create(*conn);
|
||||
return schema.create(db);
|
||||
} );
|
||||
|
||||
std::vector<std::unique_ptr<department>> departments;
|
||||
departments.emplace_back(new department{1, "Insurance", {}});
|
||||
departments.emplace_back(new department{2, "Invoice", {}});
|
||||
departments.emplace_back(new department{1, "Insurance"});
|
||||
departments.emplace_back(new department{2, "Invoice"});
|
||||
|
||||
for (auto &&a: departments) {
|
||||
auto res = ses.insert(a.release());
|
||||
@@ -250,7 +238,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
|
||||
std::vector<object_ptr<department>> departments_repo;
|
||||
for (auto it = all_departments.begin(); it != all_departments.end(); ++it) {
|
||||
std::cout << "department: " << it->name << " (employees: " << it->employees.size() << ")\n";
|
||||
departments_repo.emplace_back(it.release());
|
||||
departments_repo.emplace_back(it.optr());
|
||||
}
|
||||
REQUIRE(departments_repo.size() == 2);
|
||||
|
||||
@@ -287,8 +275,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with many-to-m
|
||||
auto result = schema.attach<recipe>("recipes")
|
||||
.and_then( [this] { return schema.attach<ingredient>("ingredients"); } )
|
||||
.and_then([this] {
|
||||
const auto conn = pool.acquire();
|
||||
return schema.create(*conn);
|
||||
return schema.create(db);
|
||||
} );
|
||||
|
||||
std::vector<std::unique_ptr<ingredient>> ingredients;
|
||||
|
||||
Reference in New Issue
Block a user