mirror of
https://github.com/getml/sqlgen.git
synced 2026-02-18 06:38:35 -06:00
Added an Iterator
This commit is contained in:
@@ -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
25
include/Iterator.hpp
Normal 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
|
||||
Reference in New Issue
Block a user