Compare commits

...

3 Commits

3 changed files with 11 additions and 11 deletions

View File

@ -95,19 +95,19 @@ public:
} }
template < class V > template < class V >
static void on_primary_key(const char *id, V &, const utils::primary_key_attribute& /*attr*/ = utils::default_pk_attributes) {} static void on_primary_key(const char * /*id*/, V &, const utils::primary_key_attribute& /*attr*/ = utils::default_pk_attributes) {}
static void on_revision(const char *id, uint64_t &/*rev*/); static void on_revision(const char *id, uint64_t &/*rev*/);
template<typename Type> template<typename Type>
static void on_attribute(const char *id, Type &, const utils::field_attributes &/*attr*/ = utils::null_attributes) {} static void on_attribute(const char * /*id*/, Type &, const utils::field_attributes &/*attr*/ = utils::null_attributes) {}
template<class Pointer> template<class Pointer>
void on_belongs_to(const char *id, Pointer &obj, const utils::foreign_attributes &attr) { void on_belongs_to(const char * /*id*/, Pointer &obj, const utils::foreign_attributes &attr) {
on_foreign_object(obj, attr); on_foreign_object(obj, attr);
} }
template<class Pointer> template<class Pointer>
void on_has_one(const char *id, Pointer &obj, const utils::foreign_attributes &attr) { void on_has_one(const char * /*id*/, Pointer &obj, const utils::foreign_attributes &attr) {
on_foreign_object(obj, attr); on_foreign_object(obj, attr);
} }
template<class C> template<class C>

View File

@ -164,6 +164,7 @@ statement &statement::bind(const Type &obj) {
template<class Type> template<class Type>
utils::result<query_result<Type>, utils::error> statement::fetch() { utils::result<query_result<Type>, utils::error> statement::fetch() {
std::cout << statement_proxy_->sql() << std::endl; std::cout << statement_proxy_->sql() << std::endl;
statement_proxy_->statement_->query_.result_type = typeid(Type);
return statement_proxy_->fetch(*bindings_).and_then([this](std::unique_ptr<query_result_impl> &&value) { return statement_proxy_->fetch(*bindings_).and_then([this](std::unique_ptr<query_result_impl> &&value) {
auto resolver = statement_proxy_->statement_->query_.resolver->object_resolver<Type>(); auto resolver = statement_proxy_->statement_->query_.resolver->object_resolver<Type>();
const auto prototype = value->prototype(); const auto prototype = value->prototype();
@ -176,6 +177,7 @@ utils::result<query_result<Type>, utils::error> statement::fetch() {
template<class Type> template<class Type>
utils::result<object::object_ptr<Type>, utils::error> statement::fetch_one() { utils::result<object::object_ptr<Type>, utils::error> statement::fetch_one() {
std::cout << statement_proxy_->sql() << std::endl; std::cout << statement_proxy_->sql() << std::endl;
statement_proxy_->statement_->query_.result_type = typeid(Type);
auto result = statement_proxy_->fetch(*bindings_); auto result = statement_proxy_->fetch(*bindings_);
if (!result.is_ok()) { if (!result.is_ok()) {
return utils::failure(result.err()); return utils::failure(result.err());

View File

@ -166,8 +166,6 @@ 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]") { 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"); } )
auto result = schema.attach<book>("books") auto result = schema.attach<book>("books")
.and_then( [this] { return schema.attach<author>("authors"); } ) .and_then( [this] { return schema.attach<author>("authors"); } )
.and_then([this] { return schema.create(db); } ); .and_then([this] { return schema.create(db); } );
@ -175,8 +173,8 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
schema.initialize_executor(ses); schema.initialize_executor(ses);
std::vector authors { std::vector authors {
object_ptr{std::make_shared<author>(1, "Michael", "Crichton", "23.10.1942", 1975, true)}, make_object<author>(1, "Michael", "Crichton", "23.10.1942", 1975, true),
object_ptr{std::make_shared<author>( 2, "Steven", "King", "21.9.1947", 1956, false)} make_object<author>( 2, "Steven", "King", "21.9.1947", 1956, false)
}; };
for (const auto &a: authors) { for (const auto &a: authors) {
@ -189,7 +187,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
auto all_authors = find_result.release(); auto all_authors = find_result.release();
std::vector<object_ptr<author>> author_repo; std::vector<object_ptr<author>> author_repo;
for (auto it = all_authors.begin(); it != all_authors.end(); ++it) { for (auto it = all_authors.begin(); it != all_authors.end(); ++it) {
std::cout << "author: " << it->first_name << " (books: " << it->books.size() << ")\n"; REQUIRE(it->books.size() == 0);
author_repo.emplace_back(it.optr()); author_repo.emplace_back(it.optr());
} }
REQUIRE(author_repo.size() == 2); REQUIRE(author_repo.size() == 2);
@ -217,7 +215,7 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
all_authors = find_result.release(); all_authors = find_result.release();
for (auto it = all_authors.begin(); it != all_authors.end(); ++it) { for (auto it = all_authors.begin(); it != all_authors.end(); ++it) {
std::cout << "author: " << it->first_name << " (books: " << it->books.size() << ")\n"; REQUIRE(it->books.size() == 5);
} }
} }