Added an Iterator

This commit is contained in:
Dr. Patrick Urbanke
2025-03-22 03:25:51 +01:00
parent 7b7f72f43c
commit bf4f1a256e
2 changed files with 28 additions and 3 deletions

View File

@@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include "Iterator.hpp"
#include "Result.hpp"
#include "dynamic/CreateTable.hpp"
#include "dynamic/Insert.hpp"
@@ -15,12 +16,11 @@ namespace sqlgen {
/// database connections.
struct Connection {
/// Executes a statement.
/// TODO: Abstract away the different statements using a lambda function.
/// TODO: Abstract away the different statements using rfl::TaggedUnion.
virtual Result<Nothing> execute(const CreateTable& _stmt) = 0;
/// Reads the results of a SelectFrom statement.
virtual Result<std::vector<std::vector<std::string>>> read(
const dynamic::SelectFrom& _query) = 0;
virtual Result<Iterator> read(const dynamic::SelectFrom& _query) = 0;
/// Writes data into a table. Each vector in data MUST have the same length as
/// _stmt.columns.

25
include/Iterator.hpp Normal file
View File

@@ -0,0 +1,25 @@
#ifndef SQLGEN_ITERATOR_HPP_
#define SQLGEN_ITERATOR_HPP_
#include <string>
#include <vector>
#include "Result.hpp"
namespace sqlgen {
/// Abstract base class for an iterator to be returned by Connection::read(...).
struct Iterator {
/// Whether the end of the available data has been reached.
virtual bool end() const = 0;
/// Returns the next batch of rows.
/// If _batch_size is greater than the number of rows left, returns all
/// of the rows left.
virtual Result<std::vector<std::vector<std::string>>> next(
const size_t _batch_size) = 0;
};
} // namespace sqlgen
#endif