removed query_record_result and moved content to query_result
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user