From bf4f1a256ef17c1c640670ef78523f5160dd23e4 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Sat, 22 Mar 2025 03:25:51 +0100 Subject: [PATCH] Added an Iterator --- include/Connection.hpp | 6 +++--- include/Iterator.hpp | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 include/Iterator.hpp diff --git a/include/Connection.hpp b/include/Connection.hpp index 7d7ce32..7995f42 100644 --- a/include/Connection.hpp +++ b/include/Connection.hpp @@ -4,6 +4,7 @@ #include #include +#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 execute(const CreateTable& _stmt) = 0; /// Reads the results of a SelectFrom statement. - virtual Result>> read( - const dynamic::SelectFrom& _query) = 0; + virtual Result read(const dynamic::SelectFrom& _query) = 0; /// Writes data into a table. Each vector in data MUST have the same length as /// _stmt.columns. diff --git a/include/Iterator.hpp b/include/Iterator.hpp new file mode 100644 index 0000000..dfcf751 --- /dev/null +++ b/include/Iterator.hpp @@ -0,0 +1,25 @@ +#ifndef SQLGEN_ITERATOR_HPP_ +#define SQLGEN_ITERATOR_HPP_ + +#include +#include + +#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>> next( + const size_t _batch_size) = 0; +}; + +} // namespace sqlgen + +#endif