Compare commits
3 Commits
6c3af53dfa
...
1deaab116c
| Author | SHA1 | Date |
|---|---|---|
|
|
1deaab116c | |
|
|
02d6ac514c | |
|
|
4377f2fab1 |
|
|
@ -95,19 +95,19 @@ public:
|
|||
}
|
||||
|
||||
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*/);
|
||||
|
||||
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>
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
template<class C>
|
||||
|
|
|
|||
|
|
@ -164,6 +164,7 @@ statement &statement::bind(const Type &obj) {
|
|||
template<class Type>
|
||||
utils::result<query_result<Type>, utils::error> statement::fetch() {
|
||||
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) {
|
||||
auto resolver = statement_proxy_->statement_->query_.resolver->object_resolver<Type>();
|
||||
const auto prototype = value->prototype();
|
||||
|
|
@ -176,6 +177,7 @@ utils::result<query_result<Type>, utils::error> statement::fetch() {
|
|||
template<class Type>
|
||||
utils::result<object::object_ptr<Type>, utils::error> statement::fetch_one() {
|
||||
std::cout << statement_proxy_->sql() << std::endl;
|
||||
statement_proxy_->statement_->query_.result_type = typeid(Type);
|
||||
auto result = statement_proxy_->fetch(*bindings_);
|
||||
if (!result.is_ok()) {
|
||||
return utils::failure(result.err());
|
||||
|
|
|
|||
|
|
@ -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]") {
|
||||
// auto result = schema.attach<author>("authors")
|
||||
// .and_then( [this] { return schema.attach<book>("books"); } )
|
||||
auto result = schema.attach<book>("books")
|
||||
.and_then( [this] { return schema.attach<author>("authors"); } )
|
||||
.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);
|
||||
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)}
|
||||
make_object<author>(1, "Michael", "Crichton", "23.10.1942", 1975, true),
|
||||
make_object<author>( 2, "Steven", "King", "21.9.1947", 1956, false)
|
||||
};
|
||||
|
||||
for (const auto &a: authors) {
|
||||
|
|
@ -189,8 +187,8 @@ TEST_CASE_METHOD(SessionFixture, "Use session to find all objects with one-to-ma
|
|||
auto all_authors = find_result.release();
|
||||
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.optr());
|
||||
REQUIRE(it->books.size() == 0);
|
||||
author_repo.emplace_back(it.optr());
|
||||
}
|
||||
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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue