added connection impl class
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
#ifndef QUERY_QUERY_RESULT_HPP
|
||||
#define QUERY_QUERY_RESULT_HPP
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace matador::sql {
|
||||
|
||||
template < typename Type >
|
||||
class query_result;
|
||||
|
||||
template < typename Type >
|
||||
class query_result_iterator
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = Type;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
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<Type> &res, Type *obj = nullptr)
|
||||
: obj_(obj)
|
||||
, result_(res)
|
||||
{}
|
||||
query_result_iterator(query_result_iterator&& x) noexcept
|
||||
: obj_(std::move(x.obj_))
|
||||
, result_(x.result_)
|
||||
{}
|
||||
|
||||
query_result_iterator& operator=(query_result_iterator&& x) noexcept
|
||||
{
|
||||
result_ = x.result_;
|
||||
obj_ = std::move(x.obj_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~query_result_iterator() = default;
|
||||
|
||||
bool operator==(const query_result_iterator& rhs)
|
||||
{
|
||||
return obj_ == rhs.obj_;
|
||||
}
|
||||
|
||||
bool operator!=(const query_result_iterator& rhs)
|
||||
{
|
||||
return obj_ != rhs.obj_;
|
||||
}
|
||||
|
||||
pointer operator->()
|
||||
{
|
||||
return obj_.get();
|
||||
}
|
||||
|
||||
reference operator&()
|
||||
{
|
||||
return &obj_.get();
|
||||
}
|
||||
|
||||
std::unique_ptr<Type> operator*()
|
||||
{
|
||||
return std::move(obj_);
|
||||
}
|
||||
|
||||
pointer get()
|
||||
{
|
||||
return obj_.get();
|
||||
}
|
||||
|
||||
pointer release()
|
||||
{
|
||||
return obj_.release();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<Type> obj_;
|
||||
query_result<Type> &result_;
|
||||
};
|
||||
|
||||
template < typename Type >
|
||||
class query_result
|
||||
{
|
||||
public:
|
||||
query_result(std::string sql) : sql_(std::move(sql)) {}
|
||||
|
||||
[[nodiscard]] const std::string& str() const { return sql_; }
|
||||
|
||||
Type begin() { return {}; }
|
||||
private:
|
||||
std::string sql_;
|
||||
};
|
||||
|
||||
}
|
||||
#endif //QUERY_QUERY_RESULT_HPP
|
||||
Reference in New Issue
Block a user