Hyper API for C++ 0.0.18825
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/Time.hpp>
11#include <hyperapi/optional.hpp>
12#include <hyperapi/hyperapi.h>
13
14#include <string>
15#include <vector>
16
17namespace hyperapi {
18
24class 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
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
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
Defines a Hyper connection.
Maps an expression to a column
Definition Inserter.hpp:27
const Name & getColumnName() const noexcept
Returns the name of the column.
Definition Inserter.hpp:32
optional< std::string > getExpression() const noexcept
Returns the expression mapped to the column.
Definition Inserter.hpp:37
ColumnMapping(Name name, std::string expression)
Creates a column mapping.
ColumnMapping(Name name)
Creates a column mapping.
An inserter.
Definition Inserter.hpp:24
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:198
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:18
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:15