Hyper API for C++ 0.0.24081
Hyper client library for C++ applications
Loading...
Searching...
No Matches
Inserter.hpp
Go to the documentation of this file.
1
5#ifndef TABLEAU_HYPER_INSERTER_HPP
6#define TABLEAU_HYPER_INSERTER_HPP
7
10#include <hyperapi/optional.hpp>
11#include <hyperapi/hyperapi.h>
12
13#include <string>
14#include <vector>
15
16namespace hyperapi {
17
23class Inserter final {
24 public:
26 class ColumnMapping final {
27 public:
31 const Name& getColumnName() const noexcept { return name_; }
32
36 optional<std::string> getExpression() const noexcept { return expression_; }
37
44
51 ColumnMapping(Name name, std::string expression);
52
53 private:
55 const Name name_;
57 const optional<std::string> expression_;
59 std::string asSelectListExpression() const;
60
61 friend class Inserter;
62 };
63
72 Inserter(Connection& connection, const TableName& name);
73
84 Inserter(Connection& connection, const TableName& name, std::vector<std::string> columns);
85
95 Inserter(Connection& connection, hyperapi::TableDefinition tableDefinition);
96
108 Inserter(Connection& connection, const hyperapi::TableDefinition& tableDefinition, std::vector<std::string> columns);
109
150 Inserter(Connection& connection, const hyperapi::TableDefinition& tableDefinition, std::vector<Inserter::ColumnMapping> columnMappings, std::vector<TableDefinition::Column> inserterDefinition);
151
192 Inserter(Connection& connection, const TableName& name, std::vector<Inserter::ColumnMapping> columnMappings, std::vector<TableDefinition::Column> inserterDefinition);
193
199 Inserter() : tableDefinition_(TableName({})), streamDefinition_(TableName({})) {}
200
204 ~Inserter() noexcept;
205
207 Inserter(Inserter&& other) noexcept;
208
210 Inserter& operator=(Inserter&& other) noexcept;
211
213 Inserter(const Inserter&) = delete;
214 Inserter& operator=(const Inserter&) = delete;
215
249 template <typename ValueType>
250 Inserter& add(ValueType value);
251
260 template <typename... ValueTypes>
261 Inserter& addRow(ValueTypes... values);
262
274
278 bool isOpen() const noexcept;
279
290 void execute();
291
298 void close() noexcept;
299
300 private:
305 void newChunk() noexcept;
306
312 void sendChunk();
313
314 private:
316 hyperapi::TableDefinition tableDefinition_;
318 internal::HyperTableDefinition tableDefinitionHandle_;
320 hyperapi::TableDefinition streamDefinition_;
322 internal::HyperTableDefinition streamDefinitionHandle_;
324 hyper_inserter_t* inserter_ = nullptr;
326 std::vector<uint8_t> currentChunk_;
328 size_t chunkOffset_ = 0;
330 size_t headerSize_ = 0;
332 hyper_field_index_t currentField_ = 0;
334 std::string selectList_;
335
336 friend class InserterTest;
337 friend struct internal::ValueInserter;
338};
339}
340
341#include <hyperapi/impl/Inserter.impl.hpp>
342
343#endif
Defines a Hyper connection.
Maps an expression to a column
Definition Inserter.hpp:26
const Name & getColumnName() const noexcept
Returns the name of the column.
Definition Inserter.hpp:31
optional< std::string > getExpression() const noexcept
Returns the expression mapped to the column.
Definition Inserter.hpp:36
ColumnMapping(Name name, std::string expression)
Creates a column mapping.
ColumnMapping(Name name)
Creates a column mapping.
An inserter.
Definition Inserter.hpp:23
Inserter(Connection &connection, hyperapi::TableDefinition tableDefinition)
Creates an inserter on a table.
void execute()
Submits the previously added data.
Inserter & endRow()
Advances the inserter to the next row.
Inserter(Connection &connection, const hyperapi::TableDefinition &tableDefinition, std::vector< std::string > columns)
Creates an inserter on a table.
Inserter & addRow(ValueTypes... values)
Inserts all given values.
Inserter & add(ValueType value)
Sets the current field to the given value.
bool isOpen() const noexcept
Returns whether the inserter is open.
Inserter(Connection &connection, const TableName &name, std::vector< Inserter::ColumnMapping > columnMappings, std::vector< TableDefinition::Column > inserterDefinition)
Creates an inserter for an existing table.
Inserter(Connection &connection, const hyperapi::TableDefinition &tableDefinition, std::vector< Inserter::ColumnMapping > columnMappings, std::vector< TableDefinition::Column > inserterDefinition)
Creates an inserter for an existing table.
Inserter()
Constructs an Inserter object that does not represent an inserter.
Definition Inserter.hpp:199
void close() noexcept
Closes the inserter.
Inserter(Connection &connection, const TableName &name)
Creates an inserter on a table.
~Inserter() noexcept
Destroys the inserter.
Inserter(Connection &connection, const TableName &name, std::vector< std::string > columns)
Creates an inserter on a table.
Represents an escaped SQL name.
Definition Name.hpp:15
Represents an escaped SQL table name.
Definition TableName.hpp:15
Surrogate for C++17 std::optional
Definition optional.hpp:40
The primary namespace of the Hyper API for C++.
Definition ByteSpan.hpp:14