fixed some query record tests
This commit is contained in:
parent
b40fcf0d67
commit
5d2d6d4a30
|
|
@ -130,7 +130,9 @@ public:
|
||||||
public:
|
public:
|
||||||
explicit query_result(std::unique_ptr<query_result_impl> &&impl)
|
explicit query_result(std::unique_ptr<query_result_impl> &&impl)
|
||||||
: impl_(std::move(impl))
|
: impl_(std::move(impl))
|
||||||
, creator_([this]{ return detail::create_prototype<Type>(impl_->prototype()); } ) {}
|
, creator_([this] {
|
||||||
|
return detail::create_prototype<Type>(impl_->prototype());
|
||||||
|
}) {}
|
||||||
|
|
||||||
query_result(std::unique_ptr<query_result_impl> &&impl, creator_func&& creator)
|
query_result(std::unique_ptr<query_result_impl> &&impl, creator_func&& creator)
|
||||||
: impl_(std::move(impl))
|
: impl_(std::move(impl))
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,47 @@
|
||||||
#include "matador/query/intermediates/fetchable_query.hpp"
|
#include "matador/query/intermediates/fetchable_query.hpp"
|
||||||
|
|
||||||
#include "matador/sql/executor.hpp"
|
#include "matador/sql/executor.hpp"
|
||||||
|
#include "matador/sql/field.hpp"
|
||||||
#include "matador/sql/statement.hpp"
|
#include "matador/sql/statement.hpp"
|
||||||
|
|
||||||
namespace matador::query {
|
namespace matador::query {
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
sql::field_type determine_field_type(const utils::constraints c) {
|
||||||
|
if (is_constraint_set(c, utils::constraints::FOREIGN_KEY)) {
|
||||||
|
return sql::field_type::ForeignKey;
|
||||||
|
}
|
||||||
|
if (is_constraint_set(c, utils::constraints::PRIMARY_KEY)) {
|
||||||
|
return sql::field_type::PrimaryKey;
|
||||||
|
}
|
||||||
|
return sql::field_type::Attribute;
|
||||||
|
}
|
||||||
|
|
||||||
|
sql::record *create_prototype(const std::vector<object::attribute_definition> &prototype) {
|
||||||
|
auto result = std::make_unique<sql::record>();
|
||||||
|
for (const auto &col: prototype) {
|
||||||
|
result->append({
|
||||||
|
col.name(),
|
||||||
|
col.type(),
|
||||||
|
determine_field_type(col.attributes().options()),
|
||||||
|
col.attributes().size(),
|
||||||
|
col.index()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
utils::result<sql::query_result<sql::record>, utils::error> fetchable_query::fetch_all(const sql::executor &exec) const {
|
utils::result<sql::query_result<sql::record>, utils::error> fetchable_query::fetch_all(const sql::executor &exec) const {
|
||||||
query_compiler compiler;
|
query_compiler compiler;
|
||||||
context_->mode = query_mode::Direct;
|
context_->mode = query_mode::Direct;
|
||||||
return exec.fetch(compiler.compile(*context_, exec.dialect(), std::nullopt))
|
const auto ctx = compiler.compile(*context_, exec.dialect(), std::nullopt);
|
||||||
|
return exec.fetch(ctx)
|
||||||
.and_then([](auto &&res) {
|
.and_then([](auto &&res) {
|
||||||
return utils::ok(sql::query_result<sql::record>(std::forward<decltype(res)>(res)));
|
const auto prototype = res->prototype();
|
||||||
|
return utils::ok(sql::query_result<sql::record>(std::forward<decltype(res)>(res), [prototype] {
|
||||||
|
return detail::create_prototype(prototype);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue