Hyper API for C++ 0.0.24081
Hyper client library for C++ applications
Loading...
Searching...
No Matches
TableDefinition.hpp
Go to the documentation of this file.
1
5#ifndef TABLEAU_HYPER_TABLEDEFINITION_HPP
6#define TABLEAU_HYPER_TABLEDEFINITION_HPP
7
10#include <hyperapi/impl/infra.hpp>
11#include <hyperapi/optional.hpp>
12#include <ostream>
13#include <string>
14#include <vector>
15#include <hyperapi/hyperapi.h>
16
17namespace hyperapi {
18
22enum Nullability : bool {
24 Nullable = true,
26 NotNullable = false
27};
28
30std::ostream& operator<<(std::ostream& os, Nullability nullability);
31
33enum class Persistence {
38};
39
43class TableDefinition final {
44 public:
46 using column_index_type = hyper_field_index_t;
47
49 class Column final {
50 public:
54 const Name& getName() const noexcept { return name_; }
55
59 const SqlType& getType() const noexcept { return type_; }
60
64 Nullability getNullability() const noexcept { return nullability_; }
65
69 const std::string& getCollation() const noexcept { return collation_; }
70
79
89 Column(Name name, SqlType type, std::string collation, Nullability nullability = Nullability::Nullable);
90
91 private:
93 const Name name_;
95 const SqlType type_;
97 const Nullability nullability_;
99 const std::string collation_;
100 };
101
102 public:
110
118 explicit TableDefinition(TableName name, std::vector<Column> columns, Persistence persistence = Persistence::Permanent);
119
123 const std::vector<Column>& getColumns() const noexcept { return columns_; }
124
131 const Column& getColumn(hyper_field_index_t columnIndex) const;
132
138 const Column* getColumnByName(const Name& s) const noexcept;
139
146
150 size_t getColumnCount() const noexcept { return columns_.size(); }
151
155 Persistence getPersistence() const noexcept { return persistence_; }
156
160 const TableName& getTableName() const noexcept { return name_; }
161
168
170 TableDefinition& addColumn(const Column& c) noexcept;
171
178
185
186 private:
188 TableName name_;
190 Persistence persistence_;
192 std::vector<Column> columns_;
193
194 friend class internal::HyperTableDefinition;
195};
196}
197
198#include <hyperapi/impl/TableDefinition.impl.hpp>
199
200#endif
Represents an escaped SQL name.
Definition Name.hpp:15
A Hyper SQL type.
Definition SqlType.hpp:46
A Column of a table definition.
const SqlType & getType() const noexcept
Returns the type of the column.
const Name & getName() const noexcept
Returns the name of the column.
const std::string & getCollation() const noexcept
Returns the collation of the column.
Nullability getNullability() const noexcept
Returns the Nullability of the column.
Column(Name name, SqlType type, Nullability nullability=Nullability::Nullable)
Creates a column.
Column(Name name, SqlType type, std::string collation, Nullability nullability=Nullability::Nullable)
Creates a column.
TableDefinition & setPersistence(Persistence p) noexcept
Sets the table's persistence.
size_t getColumnCount() const noexcept
Returns the numbers of columns.
TableDefinition & addColumn(Column &&c) noexcept
Adds a column to the definition.
TableDefinition(TableName name, Persistence persistence=Persistence::Permanent)
Creates a table definition with the given name and no columns.
optional< hyper_field_index_t > getColumnPositionByName(const Name &s) const noexcept
Returns the position of the column with the given name.
const Column * getColumnByName(const Name &s) const noexcept
Returns the column with the given name.
TableDefinition(TableName name, std::vector< Column > columns, Persistence persistence=Persistence::Permanent)
Creates a table definition with the given name and columns.
Persistence getPersistence() const noexcept
Returns the table persistence.
const Column & getColumn(hyper_field_index_t columnIndex) const
Returns the column at the given position.
TableDefinition & setTableName(TableName n) noexcept
Sets the table's name.
hyper_field_index_t column_index_type
Type of a column index.
TableDefinition & addColumn(const Column &c) noexcept
Adds a column to the definition.
const TableName & getTableName() const noexcept
Returns the name of the table.
const std::vector< Column > & getColumns() const noexcept
Returns all columns.
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
Nullability
The nullability of a column.
@ NotNullable
The column cannot contain NULL values.
@ Nullable
The column can contain NULL values.
std::ostream & operator<<(std::ostream &os, const DatabaseName &name)
Stream output operator.
Persistence
Possible persistence levels for database objects.
@ Temporary
Temporary: Only available in the own session, not persisted.