removed query_record_result and moved content to query_result
This commit is contained in:
parent
0d3ab09c14
commit
c838e9dd7b
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "matador/sql/executor.hpp"
|
||||
#include "matador/sql/query_result.hpp"
|
||||
#include "matador/sql/query_record_result.hpp"
|
||||
#include "matador/sql/record.hpp"
|
||||
|
||||
#include "matador/utils/error.hpp"
|
||||
|
|
|
|||
|
|
@ -35,15 +35,15 @@ struct value_to_identifier{
|
|||
void operator()(const uint16_t &x) { assign(x); }
|
||||
void operator()(const uint32_t &x) { assign(x); }
|
||||
void operator()(const uint64_t &x) { assign(x); }
|
||||
void operator()(const bool &x) {}
|
||||
void operator()(const float &x) {}
|
||||
void operator()(const double &x) { /* assign(x);*/ }
|
||||
void operator()(const char *x) {}
|
||||
void operator()(const bool &) {}
|
||||
void operator()(const float &) {}
|
||||
void operator()(const double &) {}
|
||||
void operator()(const char *) {}
|
||||
void operator()(const std::string &x) { assign(x); }
|
||||
void operator()(const utils::date_type_t &x) {}
|
||||
void operator()(const utils::time_type_t &x) {}
|
||||
void operator()(const utils::timestamp_type_t &x) {}
|
||||
void operator()(const utils::blob_type_t &x) {}
|
||||
void operator()(const utils::date_type_t &) {}
|
||||
void operator()(const utils::time_type_t &) {}
|
||||
void operator()(const utils::timestamp_type_t &) {}
|
||||
void operator()(const utils::blob_type_t &) {}
|
||||
|
||||
template<typename Type>
|
||||
void assign(const Type &x) { id_ = x; }
|
||||
|
|
|
|||
|
|
@ -188,23 +188,21 @@ public:
|
|||
{}
|
||||
|
||||
template<typename ValueType>
|
||||
void on_primary_key(const char *id, ValueType &value, const utils::primary_key_attribute& attr = utils::default_pk_attributes) {
|
||||
|
||||
}
|
||||
static void on_primary_key(const char * /*id*/, ValueType &/*value*/, const utils::primary_key_attribute& /*attr*/ = utils::default_pk_attributes) {}
|
||||
static void on_revision(const char * /*id*/, uint64_t &/*rev*/) {}
|
||||
template<class Type>
|
||||
static void on_attribute(const char * /*id*/, Type &/*value*/, const utils::field_attributes &/*attr*/ = utils::null_attributes) {}
|
||||
template<class Pointer>
|
||||
void on_belongs_to(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {}
|
||||
static void on_belongs_to(const char * /*id*/, Pointer & /*x*/, const utils::foreign_attributes &/*attr*/) {}
|
||||
template<class Pointer>
|
||||
void on_has_one(const char * /*id*/, Pointer &x, const utils::foreign_attributes &attr) {}
|
||||
static void on_has_one(const char * /*id*/, Pointer & /*x*/, const utils::foreign_attributes &/*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) {}
|
||||
static 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) {}
|
||||
static void on_has_many_to_many(const char *, ContainerType &, const utils::foreign_attributes &/*attr*/) {}
|
||||
|
||||
template<class CollectionType>
|
||||
void on_has_many(const char * /*id*/, CollectionType &cont, const char *join_column, const utils::foreign_attributes &attr, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
|
||||
void on_has_many(const char * /*id*/, CollectionType &/*cont*/, const char *join_column, const utils::foreign_attributes &/*attr*/, std::enable_if_t<object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
|
||||
const auto it = schema_.find(typeid(typename CollectionType::value_type::value_type));
|
||||
if (it == schema_.end()) {
|
||||
throw query_builder_exception{query_build_error::UnknownType};
|
||||
|
|
@ -224,7 +222,7 @@ public:
|
|||
}
|
||||
|
||||
template<class CollectionType>
|
||||
void on_has_many(const char * /*id*/, CollectionType &cont, const char * /*join_column*/, const utils::foreign_attributes &attr, std::enable_if_t<!object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
|
||||
void on_has_many(const char * /*id*/, CollectionType &/*cont*/, const char * /*join_column*/, const utils::foreign_attributes &/*attr*/, std::enable_if_t<!object::is_object_ptr<typename CollectionType::value_type>::value> * = nullptr) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,132 +0,0 @@
|
|||
#ifndef MATADOR_QUERY_RECORD_RESULT_HPP
|
||||
#define MATADOR_QUERY_RECORD_RESULT_HPP
|
||||
|
||||
#include "matador/sql/query_result.hpp"
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
template <>
|
||||
class query_result<record>;
|
||||
|
||||
template <>
|
||||
class query_result_iterator<record> {
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = record;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using self = query_result_iterator; /**< Shortcut for this class. */
|
||||
using pointer = value_type*; /**< Shortcut for the pointer type. */
|
||||
using reference = value_type&; /**< Shortcut for the reference type */
|
||||
|
||||
public:
|
||||
query_result_iterator() = default;
|
||||
explicit query_result_iterator(query_result<record> *res)
|
||||
: result_(res)
|
||||
{}
|
||||
query_result_iterator(query_result<record> *res, record rec)
|
||||
: record_(std::move(rec))
|
||||
, result_(res)
|
||||
{}
|
||||
query_result_iterator(query_result_iterator&& x) noexcept
|
||||
: record_(std::move(x.record_))
|
||||
, result_(x.result_)
|
||||
{}
|
||||
query_result_iterator& operator=(query_result_iterator&& x) noexcept {
|
||||
result_ = x.result_;
|
||||
record_ = std::move(x.record_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~query_result_iterator() = default;
|
||||
|
||||
bool operator==(const query_result_iterator& rhs) const {
|
||||
return record_ == rhs.record_;
|
||||
}
|
||||
|
||||
bool operator!=(const query_result_iterator& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
self& operator++();
|
||||
self operator++(int);
|
||||
|
||||
pointer operator->() { return &record_; }
|
||||
reference operator*() { return record_; }
|
||||
record release() { return std::move(record_); }
|
||||
|
||||
private:
|
||||
record record_;
|
||||
query_result<record> *result_{nullptr};
|
||||
};
|
||||
|
||||
template<>
|
||||
class query_result<record> final {
|
||||
public:
|
||||
using iterator = query_result_iterator<record>;
|
||||
|
||||
query_result(std::unique_ptr<query_result_impl> &&impl, const std::vector<object::attribute> &prototype)
|
||||
: impl_(std::move(impl))
|
||||
, prototype_(prototype) {}
|
||||
|
||||
iterator begin() { return std::move(++iterator(this)); }
|
||||
iterator end() { return {}; }
|
||||
|
||||
private:
|
||||
friend class query_result_iterator<record>;
|
||||
|
||||
[[nodiscard]] record create() const;
|
||||
void bind(const record& obj) const;
|
||||
bool fetch(record& obj) const;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<query_result_impl> impl_;
|
||||
std::vector<object::attribute> prototype_;
|
||||
};
|
||||
|
||||
inline record query_result<record>::create() const {
|
||||
record rec;
|
||||
int index{0};
|
||||
for (const auto &col: prototype_) {
|
||||
rec.append({
|
||||
col.name(),
|
||||
col.type(),
|
||||
col.attributes().options(),
|
||||
col.attributes().size(),
|
||||
index++
|
||||
});
|
||||
}
|
||||
return rec;
|
||||
|
||||
}
|
||||
|
||||
inline void query_result<record>::bind(const record &obj) const {
|
||||
impl_->bind(obj);
|
||||
}
|
||||
|
||||
inline bool query_result<record>::fetch(record &obj) const {
|
||||
return impl_->fetch(obj);
|
||||
}
|
||||
|
||||
inline query_result_iterator<record>::self & query_result_iterator<record>::operator++() {
|
||||
record_ = result_->create();
|
||||
result_->bind(record_);
|
||||
if (!result_->fetch(record_)) {
|
||||
record_.clear();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline query_result_iterator<record>::self query_result_iterator<record>::operator++(int) {
|
||||
self tmp(result_, record_);
|
||||
|
||||
record_ = result_->create();
|
||||
result_->bind(record_);
|
||||
if (!result_->fetch(record_)) {
|
||||
record_.clear();
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
#endif //MATADOR_QUERY_RECORD_RESULT_HPP
|
||||
|
|
@ -149,6 +149,131 @@ template<typename Type>
|
|||
bool query_result<Type>::fetch(Type &obj) {
|
||||
return impl_->fetch(obj);
|
||||
}
|
||||
|
||||
template <>
|
||||
class query_result<record>;
|
||||
|
||||
template <>
|
||||
class query_result_iterator<record> {
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = record;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using self = query_result_iterator; /**< Shortcut for this class. */
|
||||
using pointer = value_type*; /**< Shortcut for the pointer type. */
|
||||
using reference = value_type&; /**< Shortcut for the reference type */
|
||||
|
||||
public:
|
||||
query_result_iterator() = default;
|
||||
explicit query_result_iterator(query_result<record> *res)
|
||||
: result_(res)
|
||||
{}
|
||||
query_result_iterator(query_result<record> *res, record rec)
|
||||
: record_(std::move(rec))
|
||||
, result_(res)
|
||||
{}
|
||||
query_result_iterator(query_result_iterator&& x) noexcept
|
||||
: record_(std::move(x.record_))
|
||||
, result_(x.result_)
|
||||
{}
|
||||
query_result_iterator& operator=(query_result_iterator&& x) noexcept {
|
||||
result_ = x.result_;
|
||||
record_ = std::move(x.record_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~query_result_iterator() = default;
|
||||
|
||||
bool operator==(const query_result_iterator& rhs) const {
|
||||
return record_ == rhs.record_;
|
||||
}
|
||||
|
||||
bool operator!=(const query_result_iterator& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
self& operator++();
|
||||
self operator++(int);
|
||||
|
||||
pointer operator->() { return &record_; }
|
||||
reference operator*() { return record_; }
|
||||
record release() { return std::move(record_); }
|
||||
|
||||
private:
|
||||
record record_;
|
||||
query_result<record> *result_{nullptr};
|
||||
};
|
||||
|
||||
template<>
|
||||
class query_result<record> final {
|
||||
public:
|
||||
using iterator = query_result_iterator<record>;
|
||||
|
||||
query_result(std::unique_ptr<query_result_impl> &&impl, const std::vector<object::attribute> &prototype)
|
||||
: impl_(std::move(impl))
|
||||
, prototype_(prototype) {}
|
||||
|
||||
iterator begin() { return std::move(++iterator(this)); }
|
||||
iterator end() { return {}; }
|
||||
|
||||
private:
|
||||
friend class query_result_iterator<record>;
|
||||
|
||||
[[nodiscard]] record create() const;
|
||||
void bind(const record& obj) const;
|
||||
bool fetch(record& obj) const;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<query_result_impl> impl_;
|
||||
std::vector<object::attribute> prototype_;
|
||||
};
|
||||
|
||||
inline record query_result<record>::create() const {
|
||||
record rec;
|
||||
int index{0};
|
||||
for (const auto &col: prototype_) {
|
||||
rec.append({
|
||||
col.name(),
|
||||
col.type(),
|
||||
col.attributes().options(),
|
||||
col.attributes().size(),
|
||||
index++
|
||||
});
|
||||
}
|
||||
return rec;
|
||||
|
||||
}
|
||||
|
||||
inline void query_result<record>::bind(const record &obj) const {
|
||||
impl_->bind(obj);
|
||||
}
|
||||
|
||||
inline bool query_result<record>::fetch(record &obj) const {
|
||||
return impl_->fetch(obj);
|
||||
}
|
||||
|
||||
inline query_result_iterator<record>::self & query_result_iterator<record>::operator++() {
|
||||
record_ = result_->create();
|
||||
result_->bind(record_);
|
||||
if (!result_->fetch(record_)) {
|
||||
record_.clear();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline query_result_iterator<record>::self query_result_iterator<record>::operator++(int) {
|
||||
self tmp(result_, record_);
|
||||
|
||||
record_ = result_->create();
|
||||
result_->bind(record_);
|
||||
if (!result_->fetch(record_)) {
|
||||
record_.clear();
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
}
|
||||
// namespace matador::sql
|
||||
#endif //QUERY_QUERY_RESULT_HPP
|
||||
|
|
|
|||
|
|
@ -92,7 +92,6 @@ add_library(matador-orm STATIC
|
|||
../../include/matador/sql/internal/statement_object_resolver.hpp
|
||||
../../include/matador/sql/producer_resolver_factory.hpp
|
||||
../../include/matador/sql/query_context.hpp
|
||||
../../include/matador/sql/query_record_result.hpp
|
||||
../../include/matador/sql/query_result.hpp
|
||||
../../include/matador/sql/record.hpp
|
||||
../../include/matador/sql/resolver_service.hpp
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "matador/sql/backend_provider.hpp"
|
||||
#include "matador/sql/dialect.hpp"
|
||||
#include "matador/sql/query_record_result.hpp"
|
||||
|
||||
#include "matador/query/query.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
#include "matador/sql/executor.hpp"
|
||||
#include "matador/sql/field.hpp"
|
||||
#include "matador/sql/statement.hpp"
|
||||
#include "matador/sql/query_record_result.hpp"
|
||||
|
||||
namespace matador::query {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#include "matador/sql/statement.hpp"
|
||||
#include "matador/sql/record.hpp"
|
||||
#include "matador/sql/field.hpp"
|
||||
#include "matador/sql/query_record_result.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
|
|
|||
|
|
@ -519,8 +519,6 @@ TEST_CASE_METHOD(QueryFixture, "Execute select statement with group by and order
|
|||
for (const auto &r: *result) {
|
||||
const auto age_count_val = r.at<int>(0);
|
||||
const auto age_val = r.at<int>(1);
|
||||
const auto ec = expected_values.front().first;
|
||||
const auto ea = expected_values.front().second;
|
||||
REQUIRE(age_count_val == expected_values.front().first);
|
||||
REQUIRE(age_val == expected_values.front().second);
|
||||
expected_values.pop_front();
|
||||
|
|
|
|||
Loading…
Reference in New Issue