relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
Loading...
Searching...
No Matches
streaming_result.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "lazy_result.hpp"
4
5#include <optional>
6#include <string>
7#include <utility>
8#include <vector>
9
10namespace relx::result {
11
13template <typename DataSource>
15public:
18 public:
19 streaming_iterator(DataSource& source, bool at_end = false)
20 : source_(source), current_row_(), at_end_(at_end) {
21 if (!at_end_) {
22 advance();
23 }
24 }
25
26 LazyRow operator*() const { return current_row_; }
27
29 advance();
30 return *this;
31 }
32
33 bool operator!=(const streaming_iterator& other) const { return at_end_ != other.at_end_; }
34
35 private:
36 DataSource& source_;
37 LazyRow current_row_;
38 bool at_end_;
39
40 void advance() {
41 auto next_row_data = source_.get_next_row();
42 if (next_row_data) {
43 current_row_ = LazyRow(std::move(*next_row_data), source_.get_column_names());
44 } else {
45 at_end_ = true;
46 }
47 }
48 };
49
50 StreamingResultSet(DataSource source) : source_(std::move(source)) {}
51
53
54 streaming_iterator end() { return streaming_iterator(source_, true); }
55
56private:
57 DataSource source_;
58};
59
60} // namespace relx::result
Lazy row that defers cell parsing until accessed.
streaming_iterator(DataSource &source, bool at_end=false)
bool operator!=(const streaming_iterator &other) const
Streaming result set for very large datasets.
STL namespace.