Hyper API for C++  0.0.15530
Hyper client library for C++ applications
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/Time.hpp>
11 #include <hyperapi/optional.hpp>
12 #include <hyperapi/hyperapi.h>
13 
14 #include <string>
15 #include <vector>
16 
17 namespace hyperapi {
18 
24 class Inserter final {
25  public:
27  class ColumnMapping final {
28  public:
32  const Name& getColumnName() const noexcept { return name; }
33 
37  optional<std::string> getExpression() const noexcept { return expression; }
38 
44  ColumnMapping(Name name);
45 
52  ColumnMapping(Name name, std::string expression);
53 
54  private:
56  const Name name;
58  const optional<std::string> expression;
60  std::string asSelectListExpression() const;
61 
62  friend class Inserter;
63  };
64 
73  Inserter(Connection& connection, const TableName& name);
74 
85  Inserter(Connection& connection, const TableName& name, std::vector<std::string> columns);
86 
96  Inserter(Connection& connection, hyperapi::TableDefinition tableDefinition);
97 
107  Inserter(Connection& connection, const hyperapi::TableDefinition& tableDefinition, std::vector<std::string> columns);
108 
149  Inserter(Connection& connection, const hyperapi::TableDefinition& tableDefinition, std::vector<Inserter::ColumnMapping> columnMappings, std::vector<TableDefinition::Column> inserterDefinition);
150 
191  Inserter(Connection& connection, const TableName& name, std::vector<Inserter::ColumnMapping> columnMappings, std::vector<TableDefinition::Column> inserterDefinition);
192 
198  Inserter() : tableDefinition(TableName({})), streamDefinition(TableName({})) {}
199 
203  ~Inserter() noexcept;
204 
206  Inserter(Inserter&& other) noexcept;
207 
209  Inserter& operator=(Inserter&& other) noexcept;
210 
212  Inserter(const Inserter&) = delete;
213  Inserter& operator=(const Inserter&) = delete;
214 
247  template <typename ValueType>
248  Inserter& add(ValueType value);
249 
258  template <typename... ValueTypes>
259  Inserter& addRow(ValueTypes... values);
260 
271  Inserter& endRow();
272 
276  bool isOpen() const noexcept;
277 
288  void execute();
289 
296  void close() noexcept;
297 
298  private:
303  void newChunk() noexcept;
304 
310  void sendChunk();
311 
312  private:
314  hyperapi::TableDefinition tableDefinition;
316  internal::HyperTableDefinition tableDefinitionHandle;
318  hyperapi::TableDefinition streamDefinition;
320  internal::HyperTableDefinition streamDefinitionHandle;
322  hyper_inserter_t* inserter = nullptr;
324  std::vector<uint8_t> currentChunk;
326  size_t chunkOffset = 0;
328  size_t headerSize = 0;
330  hyper_field_index_t currentField = 0;
332  std::string selectList;
333 
334  friend class InserterTest;
335  friend struct internal::ValueInserter;
336 };
337 }
338 
339 #include <hyperapi/impl/Inserter.impl.hpp>
340 
341 #endif
hyperapi::Inserter
An inserter.
Definition: Inserter.hpp:24
hyperapi::Inserter::endRow
Inserter & endRow()
Advances the inserter to the next row.
hyperapi::Inserter::add
Inserter & add(ValueType value)
Sets the current field to the given value.
hyperapi::Inserter::Inserter
Inserter()
Constructs an Inserter object that does not represent an inserter.
Definition: Inserter.hpp:198
hyperapi::Inserter::~Inserter
~Inserter() noexcept
Destroys the inserter.
hyperapi::Name
Represents an escaped SQL name.
Definition: Name.hpp:18
hyperapi::Inserter::ColumnMapping
Maps an expression to a column
Definition: Inserter.hpp:27
hyperapi::TableDefinition
A table definition.
Definition: TableDefinition.hpp:44
TableDefinition.hpp
hyperapi::optional< std::string >
Connection.hpp
hyperapi::Connection
Defines a Hyper connection.
Definition: Connection.hpp:42
hyperapi::Inserter::isOpen
bool isOpen() const noexcept
Returns whether the inserter is open.
Time.hpp
hyperapi::Inserter::addRow
Inserter & addRow(ValueTypes... values)
Inserts all given values.
hyperapi
The primary namespace of the Hyper API for C++.
Definition: ByteSpan.hpp:15
hyperapi::Inserter::ColumnMapping::getExpression
optional< std::string > getExpression() const noexcept
Returns the expression mapped to the column.
Definition: Inserter.hpp:37
hyperapi::Inserter::ColumnMapping::getColumnName
const Name & getColumnName() const noexcept
Returns the name of the column.
Definition: Inserter.hpp:32
hyperapi::Inserter::close
void close() noexcept
Closes the inserter.
hyperapi::Inserter::ColumnMapping::ColumnMapping
ColumnMapping(Name name)
Creates a column mapping.
hyperapi::TableName
Represents an escaped SQL table name.
Definition: TableName.hpp:15
hyperapi::Inserter::execute
void execute()
Submits the previously added data.
optional.hpp