removed unused code
This commit is contained in:
@@ -28,7 +28,6 @@ protected:
|
||||
virtual attribute_reader& result_binder() = 0;
|
||||
|
||||
private:
|
||||
// detail::empty_binder empty_result_binder_;
|
||||
object_result_binder object_binder_;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,67 +25,77 @@ class value;
|
||||
}
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
namespace detail {
|
||||
class pk_reader
|
||||
{
|
||||
class pk_reader {
|
||||
public:
|
||||
explicit pk_reader(query_result_reader &reader);
|
||||
|
||||
template<class Type>
|
||||
void read(Type &obj, const size_t column_index)
|
||||
{
|
||||
void read(Type &obj, const size_t column_index) {
|
||||
column_index_ = column_index;
|
||||
access::process(*this, obj);
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
void on_primary_key(const char *id, ValueType &value, std::enable_if_t<std::is_integral_v<ValueType> && !std::is_same_v<bool, ValueType>>* = nullptr);
|
||||
void on_primary_key(const char *id, ValueType &value,
|
||||
std::enable_if_t<std::is_integral_v<ValueType> && !std::is_same_v<bool, ValueType>> * = nullptr);
|
||||
void on_primary_key(const char *id, std::string &value, size_t size);
|
||||
void on_revision(const char * /*id*/, unsigned long long &/*rev*/) { ++column_index_; }
|
||||
|
||||
template < class Type >
|
||||
void on_attribute(const char * /*id*/, Type &/*x*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) { ++column_index_; }
|
||||
template < class Pointer >
|
||||
void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) { ++column_index_; }
|
||||
template < class Pointer >
|
||||
template<class Type>
|
||||
void on_attribute(const char * /*id*/, Type &/*x*/,
|
||||
const utils::field_attributes &/*attr*/ = utils::null_attributes) { ++column_index_; }
|
||||
|
||||
template<class Pointer>
|
||||
void on_belongs_to(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) {
|
||||
++column_index_;
|
||||
}
|
||||
|
||||
template<class Pointer>
|
||||
void on_has_one(const char * /*id*/, Pointer &/*x*/, const utils::foreign_attributes &/*attr*/) { ++column_index_; }
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char * /*id*/, ContainerType &, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
void on_has_many(const char * /*id*/, ContainerType &, const char * /*join_column*/,
|
||||
const utils::foreign_attributes &/*attr*/) {
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many_to_many(const char *id, ContainerType &c, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
void on_has_many_to_many(const char *id, ContainerType &c, const char * /*join_column*/,
|
||||
const char * /*inverse_join_column*/, const utils::foreign_attributes &/*attr*/) {
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many_to_many(const char *id, ContainerType &c, const utils::foreign_attributes &/*attr*/) {}
|
||||
void on_has_many_to_many(const char *id, ContainerType &c, const utils::foreign_attributes &/*attr*/) {
|
||||
}
|
||||
|
||||
private:
|
||||
size_t column_index_{};
|
||||
query_result_reader &reader_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
class query_result_impl
|
||||
{
|
||||
class query_result_impl {
|
||||
public:
|
||||
query_result_impl(std::unique_ptr<query_result_reader> &&reader, std::vector<object::attribute_definition> &&prototype, size_t column_index = 0);
|
||||
query_result_impl(std::unique_ptr<query_result_reader> &&reader, const std::vector<object::attribute_definition> &prototype, size_t column_index = 0);
|
||||
query_result_impl(std::unique_ptr<query_result_reader> &&reader,
|
||||
std::vector<object::attribute_definition> &&prototype, size_t column_index = 0);
|
||||
query_result_impl(std::unique_ptr<query_result_reader> &&reader,
|
||||
const std::vector<object::attribute_definition> &prototype, size_t column_index = 0);
|
||||
|
||||
template<typename ValueType>
|
||||
void on_primary_key(const char *id, ValueType &value, std::enable_if_t<std::is_integral_v<ValueType> && !std::is_same_v<bool, ValueType>>* = nullptr)
|
||||
{
|
||||
void on_primary_key(const char *id, ValueType &value,
|
||||
std::enable_if_t<std::is_integral_v<ValueType> && !std::is_same_v<bool, ValueType>> * = nullptr) {
|
||||
utils::data_type_traits<ValueType>::read_value(*reader_, id, column_index_++, value);
|
||||
if (type_stack_.size() == 1) {
|
||||
last_pk_ = current_pk_;
|
||||
current_pk_ = value;
|
||||
}
|
||||
}
|
||||
|
||||
void on_primary_key(const char *id, std::string &value, size_t size);
|
||||
void on_revision(const char *id, uint64_t &rev);
|
||||
|
||||
template < class Type >
|
||||
void on_attribute(const char *id, Type &x, const utils::field_attributes &/*attr*/ = utils::null_attributes)
|
||||
{
|
||||
template<class Type>
|
||||
void on_attribute(const char *id, Type &x, const utils::field_attributes &/*attr*/ = utils::null_attributes) {
|
||||
utils::data_type_traits<Type>::read_value(*reader_, id, column_index_++, x);
|
||||
}
|
||||
|
||||
@@ -93,89 +103,81 @@ public:
|
||||
void on_attribute(const char *id, std::string &value, const utils::field_attributes &attr = utils::null_attributes);
|
||||
void on_attribute(const char *id, utils::value &val, const utils::field_attributes &attr = utils::null_attributes);
|
||||
|
||||
template < class Pointer >
|
||||
template<class Pointer>
|
||||
void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {
|
||||
if (x.empty()) {
|
||||
x.reset(new typename Pointer::value_type);
|
||||
}
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
} else {
|
||||
const auto ti = std::type_index(typeid(*x));
|
||||
type_stack_.push(ti);
|
||||
access::process(*this, *x);
|
||||
type_stack_.pop();
|
||||
}
|
||||
on_foreign_key(x, attr);
|
||||
}
|
||||
template < class Pointer >
|
||||
|
||||
template<class Pointer>
|
||||
void on_has_one(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {
|
||||
if (x.empty()) {
|
||||
x.reset(new typename Pointer::value_type);
|
||||
}
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
} else {
|
||||
const auto ti = std::type_index(typeid(*x));
|
||||
type_stack_.push(ti);
|
||||
access::process(*this, *x);
|
||||
type_stack_.pop();
|
||||
}
|
||||
on_foreign_key(x, attr);
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many_to_many(const char *, ContainerType &, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
void on_has_many_to_many(const char *, ContainerType &, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char * /*id*/, ContainerType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr) {
|
||||
if ( attr.fetch() == utils::fetch_type::LAZY ) {
|
||||
// pk_reader_.read(*id, column_index_++);
|
||||
} else {
|
||||
const auto ti = std::type_index(typeid(typename ContainerType::value_type::value_type));
|
||||
auto obj = std::make_unique<typename ContainerType::value_type::value_type>();
|
||||
type_stack_.push(ti);
|
||||
access::process(*this, *obj);
|
||||
type_stack_.pop();
|
||||
auto ptr = typename ContainerType::value_type(obj.release());
|
||||
const auto pk = ptr.primary_key();
|
||||
if (ptr.primary_key().is_valid()) {
|
||||
cont.push_back(ptr);
|
||||
}
|
||||
}
|
||||
void on_has_many_to_many(const char *, ContainerType &, const char * /*join_column*/, const char * /*inverse_join_column*/, const utils::foreign_attributes &attr) {
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
|
||||
} else {}
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char *, ContainerType &, const utils::foreign_attributes &/*attr*/) {}
|
||||
void on_has_many_to_many(const char *, ContainerType &, const utils::foreign_attributes &attr) {
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
|
||||
} else {}
|
||||
}
|
||||
|
||||
template<class ContainerType>
|
||||
void on_has_many(const char * /*id*/, ContainerType &cont, const char * /*join_column*/,
|
||||
const utils::foreign_attributes &attr) {
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
// pk_reader_.read(*id, column_index_++);
|
||||
} else {
|
||||
const auto ti = std::type_index(typeid(typename ContainerType::value_type::value_type));
|
||||
auto obj = std::make_unique<typename ContainerType::value_type::value_type>();
|
||||
type_stack_.push(ti);
|
||||
access::process(*this, *obj);
|
||||
type_stack_.pop();
|
||||
auto ptr = typename ContainerType::value_type(obj.release());
|
||||
const auto pk = ptr.primary_key();
|
||||
if (ptr.primary_key().is_valid()) {
|
||||
cont.push_back(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// template<class ContainerType>
|
||||
// void on_has_many(const char *, ContainerType &, const utils::foreign_attributes &/*attr*/) {}
|
||||
|
||||
template<class Type>
|
||||
void bind(const Type &obj)
|
||||
{
|
||||
void bind(const Type &obj) {
|
||||
reader_->bind(obj);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool pk_has_changed() const {
|
||||
return !last_pk_.is_null() && last_pk_ != current_pk_;
|
||||
return !last_pk_.is_null() && last_pk_ != current_pk_;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
bool fetch(Type &obj) {
|
||||
bool first = true;
|
||||
do {
|
||||
if (auto fetched = reader_->fetch(); !fetched.is_ok() || !*fetched) {
|
||||
return !first;
|
||||
}
|
||||
last_pk_ = current_pk_;
|
||||
current_pk_ = discover_current_primary_key(obj);
|
||||
if (pk_has_changed()) {
|
||||
reader_->unshift();
|
||||
last_pk_.clear();
|
||||
current_pk_.clear();
|
||||
break;
|
||||
}
|
||||
first = false;
|
||||
type_stack_.push(typeid(Type));
|
||||
column_index_ = reader_->start_column_index();
|
||||
access::process(*this, obj);
|
||||
type_stack_.pop();
|
||||
if (auto fetched = reader_->fetch(); !fetched.is_ok() || !*fetched) {
|
||||
return !first;
|
||||
}
|
||||
last_pk_ = current_pk_;
|
||||
current_pk_ = discover_current_primary_key(obj);
|
||||
if (pk_has_changed()) {
|
||||
reader_->unshift();
|
||||
last_pk_.clear();
|
||||
current_pk_.clear();
|
||||
break;
|
||||
}
|
||||
first = false;
|
||||
type_stack_.emplace(typeid(Type));
|
||||
column_index_ = reader_->start_column_index();
|
||||
access::process(*this, obj);
|
||||
type_stack_.pop();
|
||||
} while (last_pk_ == current_pk_);
|
||||
return true;
|
||||
}
|
||||
@@ -190,14 +192,29 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] const std::vector<object::attribute_definition>& prototype() const;
|
||||
[[nodiscard]] const std::vector<object::attribute_definition> &prototype() const;
|
||||
|
||||
private:
|
||||
template<class Type>
|
||||
utils::identifier discover_current_primary_key(const Type &obj) {
|
||||
internal::query_result_pk_resolver resolver(*reader_);
|
||||
return resolver.discover(obj);
|
||||
template<class Type>
|
||||
utils::identifier discover_current_primary_key(const Type &obj) {
|
||||
internal::query_result_pk_resolver resolver(*reader_);
|
||||
return resolver.discover(obj);
|
||||
}
|
||||
|
||||
template<class Pointer>
|
||||
void on_foreign_key(Pointer &x, const utils::foreign_attributes &attr) {
|
||||
if (x.empty()) {
|
||||
x.reset(new typename Pointer::value_type);
|
||||
}
|
||||
if (attr.fetch() == utils::fetch_type::LAZY) {
|
||||
pk_reader_.read(*x, column_index_++);
|
||||
} else {
|
||||
const auto ti = std::type_index(typeid(*x));
|
||||
type_stack_.push(ti);
|
||||
access::process(*this, *x);
|
||||
type_stack_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
size_t column_index_ = 0;
|
||||
@@ -210,13 +227,11 @@ protected:
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename ValueType>
|
||||
void pk_reader::on_primary_key(const char *id, ValueType &value, std::enable_if_t<std::is_integral_v<ValueType> && !std::is_same_v<bool, ValueType>> *)
|
||||
{
|
||||
void pk_reader::on_primary_key(const char *id, ValueType &value,
|
||||
std::enable_if_t<std::is_integral_v<ValueType> && !std::is_same_v<bool, ValueType>> *) {
|
||||
utils::data_type_traits<ValueType>::read_value(reader_, id, column_index_++, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user