collection resolver producer progress

This commit is contained in:
2026-01-25 22:00:11 +01:00
parent 64f2d6899a
commit 046c1d8ed2
4 changed files with 110 additions and 8 deletions
+86 -8
View File
@@ -497,6 +497,8 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many relation",
.and_then([this] {return repo.create(db); });
REQUIRE(result.is_ok());
repo.initialize_executor(db);
const std::vector shipments {
object_ptr{std::make_shared<shipment>(1, "4711")},
object_ptr{std::make_shared<shipment>(2, "0815")}
@@ -575,14 +577,90 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many relation",
REQUIRE(shipment_result.is_ok());
// size_t index{0};
// std::vector<size_t> packages_sizes{2, 3};
// std::cout << "\n";
// for (const auto &s : *shipment_result) {
// REQUIRE(s->id == shipments.at(index)->id);
// REQUIRE(s->tracking_number == shipments.at(index)->tracking_number);
// REQUIRE(s->packages.size() == packages_sizes.at(index++));
// }
size_t index{0};
std::vector<size_t> packages_sizes{2, 3};
std::cout << "\n";
for (const auto &s : *shipment_result) {
REQUIRE(s->id == shipments.at(index)->id);
REQUIRE(s->tracking_number == shipments.at(index)->tracking_number);
REQUIRE(s->packages.size() == packages_sizes.at(index++));
}
}
TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy has many relation", "[query][has_many][lazy]") {
auto result = repo.attach<author>("authors")
.and_then( [this] { return repo.attach<book>("books"); } )
.and_then([this] {
return repo.create(db);
} );
repo.initialize_executor(db);
const 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)}
};
const std::vector books {
object_ptr{std::make_shared<book>(3, "Jurassic Park", authors[0], 1990)},
object_ptr{std::make_shared<book>(4, "Timeline", authors[0], 1999)},
object_ptr{std::make_shared<book>(5, "The Andromeda Strain", authors[0], 1969)},
object_ptr{std::make_shared<book>(6, "Congo", authors[0], 1980)},
object_ptr{std::make_shared<book>(7, "Prey", authors[0], 2002)},
object_ptr{std::make_shared<book>(8, "Carrie", authors[1], 1974)},
object_ptr{std::make_shared<book>(9, "The Shining", authors[1], 1977)},
object_ptr{std::make_shared<book>(10, "It", authors[1], 1986)},
object_ptr{std::make_shared<book>(11, "Misery", authors[1], 1987)},
object_ptr{std::make_shared<book>(12, "The Dark Tower: The Gunslinger", authors[1], 1982)},
};
for (const auto &a: authors) {
auto res = query::insert()
.into(AUTHOR, {AUTHOR.id, AUTHOR.first_name, AUTHOR.last_name, AUTHOR.date_of_birth, AUTHOR.year_of_birth, AUTHOR.distinguished})
.values(*a)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 1);
}
auto count = query::select({count_all()})
.from(AUTHOR)
.fetch_value<int>(db);
REQUIRE(count.is_ok());
REQUIRE(*count == 2);
for (const auto &b: books) {
auto res = query::insert()
.into(BOOK, {BOOK.id, BOOK.title, BOOK.author_id, BOOK.published_in})
.values(*b)
.execute(db);
REQUIRE(res.is_ok());
REQUIRE(*res == 1);
}
count = query::select({count_all()})
.from(BOOK)
.fetch_value<int>(db);
REQUIRE(count.is_ok());
REQUIRE(*count == 10);
auto author_result = query::select({AUTHOR.id, AUTHOR.first_name, AUTHOR.last_name, AUTHOR.date_of_birth, AUTHOR.year_of_birth, AUTHOR.distinguished})
.from(AUTHOR)
.order_by(AUTHOR.id).asc()
.fetch_all<author>(db);
REQUIRE(author_result.is_ok());
size_t index{0};
for (const auto &a : *author_result) {
REQUIRE(a->id == authors.at(index)->id);
REQUIRE(a->first_name == authors.at(index)->first_name);
REQUIRE(a->last_name == authors.at(index)->last_name);
REQUIRE(a->date_of_birth == authors.at(index)->date_of_birth);
REQUIRE(a->year_of_birth == authors.at(index)->year_of_birth);
REQUIRE(a->distinguished == authors.at(index)->distinguished);
REQUIRE(!a->books.empty());
++index;
}
}
TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy belongs to relation", "[query][belongs_to][lazy]") {