initial matador ng commit
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#ifndef QUERY_QUERY_RESULT_HPP
|
||||
#define QUERY_QUERY_RESULT_HPP
|
||||
|
||||
#include "matador/sql/query_result_impl.hpp"
|
||||
#include "matador/sql/column_definition.hpp"
|
||||
|
||||
#include "matador/sql/internal/query_result_impl.hpp"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@@ -20,7 +22,7 @@ public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = Type;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using self = query_result_iterator<Type>; /**< Shortcut for this class. */
|
||||
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 */
|
||||
|
||||
@@ -78,7 +80,7 @@ public:
|
||||
obj_.reset();
|
||||
}
|
||||
|
||||
return std::move(tmp);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
pointer operator->()
|
||||
@@ -119,43 +121,43 @@ record* create_prototype<record>(const std::vector<column_definition> &prototype
|
||||
|
||||
}
|
||||
|
||||
template < typename Type >
|
||||
class query_result
|
||||
{
|
||||
template<typename Type>
|
||||
class query_result final {
|
||||
public:
|
||||
using iterator = query_result_iterator<Type>;
|
||||
using creator_func = std::function<Type*()>;
|
||||
|
||||
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)) {}
|
||||
|
||||
query_result(std::unique_ptr<query_result_impl> impl, std::vector<column_definition> record_prototype)
|
||||
: record_prototype_(std::move(record_prototype))
|
||||
, impl_(std::move(impl)) {}
|
||||
|
||||
iterator begin() { return std::move(++iterator(this)); }
|
||||
iterator end() { return {}; }
|
||||
|
||||
private:
|
||||
friend class query_result_iterator<Type>;
|
||||
|
||||
Type* create() { return detail::create_prototype<Type>(record_prototype_); }
|
||||
Type* create();
|
||||
void bind(const Type& obj);
|
||||
bool fetch(Type& obj);
|
||||
|
||||
void bind(const Type &obj)
|
||||
{
|
||||
impl_->bind(obj);
|
||||
}
|
||||
|
||||
bool fetch(Type &obj)
|
||||
{
|
||||
return impl_->fetch(obj);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<column_definition> record_prototype_;
|
||||
protected:
|
||||
std::unique_ptr<query_result_impl> impl_;
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
Type *query_result<Type>::create() {
|
||||
return detail::create_prototype<Type>(impl_->prototype());
|
||||
}
|
||||
template<typename Type>
|
||||
void query_result<Type>::bind(const Type &obj) {
|
||||
impl_->bind(obj);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
bool query_result<Type>::fetch(Type &obj) {
|
||||
return impl_->fetch(obj);
|
||||
}
|
||||
|
||||
} // namespace matador::sql
|
||||
#endif //QUERY_QUERY_RESULT_HPP
|
||||
|
||||
Reference in New Issue
Block a user