session progress
This commit is contained in:
@@ -24,8 +24,45 @@ using namespace matador::object;
|
||||
using namespace matador::query;
|
||||
using namespace matador::sql;
|
||||
using namespace matador::test;
|
||||
using namespace matador::utils;
|
||||
using namespace matador::query::meta;
|
||||
|
||||
void initialize_resolver(const basic_schema& repo, connection& db) {
|
||||
for (const auto &pair : repo.resolver_producers()) {
|
||||
auto res = pair.second->build_query(db.dialect()).and_then([&db](query_context&& query_ctx) -> result<statement, error> {
|
||||
query_ctx.resolver = db.resolver();
|
||||
return db.prepare(query_ctx);
|
||||
}).and_then([&pair, &db](statement&& stmt) -> result<void, error> {
|
||||
db.resolver()->register_object_resolver(pair.second->produce(std::move(stmt)));
|
||||
|
||||
return ok<void>();
|
||||
}).or_else([](const auto &err) {
|
||||
return failure(err);
|
||||
});
|
||||
|
||||
if (!res) {
|
||||
throw std::runtime_error(res.err().message());
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &pair : repo.collection_resolver_producers()) {
|
||||
auto res = pair.second->build_query(db.dialect()).and_then([&db](query_context&& query_ctx) -> result<statement, error> {
|
||||
query_ctx.resolver = db.resolver();
|
||||
return db.prepare(query_ctx);
|
||||
}).and_then([&pair, &db](statement&& stmt) -> result<void, error> {
|
||||
db.resolver()->register_collection_resolver(pair.second->produce(std::move(stmt), *db.resolver()));
|
||||
|
||||
return ok<void>();
|
||||
}).or_else([](const auto &err) {
|
||||
return failure(err);
|
||||
});
|
||||
|
||||
if (!res) {
|
||||
throw std::runtime_error(res.err().message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(QueryFixture, "Create table with foreign key relation", "[query][foreign][relation]") {
|
||||
const auto result = repo.attach<airplane>("airplane")
|
||||
.and_then([this] { return repo.attach<flight>("flight");})
|
||||
@@ -311,7 +348,7 @@ TEST_CASE_METHOD(QueryFixture, "Select statement with foreign key and for single
|
||||
.and_then([this] {return repo.create(db); });
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
// repo.initialize(db);
|
||||
initialize_resolver(repo, db);
|
||||
|
||||
REQUIRE(db.exists(AIRPLANE.table_name()));
|
||||
REQUIRE(db.exists(FLIGHT.table_name()));
|
||||
@@ -538,7 +575,7 @@ 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(db);
|
||||
initialize_resolver(repo, db);
|
||||
|
||||
const std::vector shipments {
|
||||
make_object<shipment>(1, "4711"),
|
||||
@@ -636,7 +673,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy has many relation", "
|
||||
} );
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
// repo.initialize(db);
|
||||
initialize_resolver(repo, db);
|
||||
|
||||
const std::vector authors {
|
||||
make_object<author>(1, "Michael", "Crichton", "23.10.1942", 1975, true),
|
||||
@@ -718,7 +755,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with lazy belongs to relation",
|
||||
.and_then([this] {return repo.create(db); });
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
// repo.initialize(db);
|
||||
initialize_resolver(repo, db);
|
||||
|
||||
const std::vector deps {
|
||||
make_object<department>(1, "Human Resources"),
|
||||
@@ -864,7 +901,7 @@ TEST_CASE_METHOD(QueryFixture, "Test load entity with eager has many to many rel
|
||||
|
||||
REQUIRE(result.is_ok());
|
||||
|
||||
// repo.initialize(db);
|
||||
initialize_resolver(repo, db);
|
||||
|
||||
REQUIRE(db.exists(RECIPE.table_name()));
|
||||
REQUIRE(db.exists(INGREDIENT.table_name()));
|
||||
|
||||
Reference in New Issue
Block a user