lintel 0.2.0
Loading...
Searching...
No Matches
Cursor.h
Go to the documentation of this file.
1#ifndef LINTEL_CURSOR_H
2#define LINTEL_CURSOR_H
3
4#include <cstddef>
5#include <memory>
6#include <string>
7#include <vector>
8
13
14namespace lintel {
15namespace db {
31 class Cursor
32 {
33 private:
34 std::shared_ptr<postgresql::Cursor> m_cursor = nullptr;
35 std::shared_ptr<sqlite::Cursor> m_cursorSQLite = nullptr;
36
38 std::vector<db::Arguments> m_batch;
40 std::size_t m_pos = 0;
41 bool m_started = false;
42 bool m_exhausted = false;
43
45 static constexpr std::size_t kDefaultFetchSize = 100;
47 std::size_t m_fetchSize = kDefaultFetchSize;
49 std::string m_cursorName;
51 bool m_noScroll = true;
52
54 bool m_needsInit = false;
55 std::string m_query;
56 std::vector<std::string> m_params;
57 std::shared_ptr<postgresql::Connection> m_pgConn;
58 std::shared_ptr<sqlite::Connection> m_sqliteConn;
59
64 void start();
65
70 void initBackendCursor();
71
75 void fillBatch();
76
78 [[nodiscard]] bool hasCurrent() const;
79
81 [[nodiscard]] const db::Arguments &currentOf() const;
82
86 void advance();
87
88 public:
96 {
97 private:
98 Cursor &m_cursor;
99 bool m_end;
100
102 [[nodiscard]] bool reachedEnd() const;
103
104 public:
105 using iterator_category = std::input_iterator_tag;
107 using difference_type = std::ptrdiff_t;
108 using pointer = const Arguments *;
109 using reference = const Arguments &;
110
117 explicit Iterator(Cursor &cursor, bool end = false);
118
120
122
123 bool operator==(const Iterator &other) const;
124
125 bool operator!=(const Iterator &other) const;
126
128 };
129
131 Cursor() = default;
132
140 Cursor &setFetchSize(std::size_t rows);
141
147 Cursor &setCursorName(const std::string &name);
148
155
162 std::vector<db::Arguments> fetchNext(std::size_t maxRows);
163
166
169
170 private:
171 friend class Statement;
172
176 Cursor(std::shared_ptr<postgresql::Cursor> cursor, std::shared_ptr<sqlite::Cursor> cursorSQLite);
177 };
178}// namespace db
179
180}// namespace lintel
181#endif// LINTEL_CURSOR_H
Definition Arguments.h:77
Definition Cursor.h:96
bool operator!=(const Iterator &other) const
bool operator==(const Iterator &other) const
Iterator(Cursor &cursor, bool end=false)
reference operator*() const
std::input_iterator_tag iterator_category
Definition Cursor.h:105
const Iterator operator++(int)
std::ptrdiff_t difference_type
Definition Cursor.h:107
Definition Cursor.h:32
Cursor & setFetchSize(std::size_t rows)
std::vector< db::Arguments > fetchNext(std::size_t maxRows)
Cursor & setCursorName(const std::string &name)
Cursor & setNoScroll(bool enable)
Definition Statement.h:17
Definition BaseFeature.h:6
constexpr std::string_view type_name()
Definition TypeName.h:9