Hyper API for C++ 0.0.20746
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
11#include <hyperapi/impl/infra.hpp>
12#include <hyperapi/optional.hpp>
13#include <ostream>
14#include <string>
15#include <vector>
16#include <hyperapi/hyperapi.h>
17
18namespace hyperapi {
19
23enum Nullability : bool {
25 Nullable = true,
27 NotNullable = false
28};
29
31std::ostream& operator<<(std::ostream& os, Nullability nullability);
32
34enum class Persistence {
39};
40
44class TableDefinition final {
45 public:
47 using column_index_type = hyper_field_index_t;
48
50 class Column final {
51 public:
55 const Name& getName() const noexcept { return name_; }
56
60 const SqlType& getType() const noexcept { return type_; }
61
65 Nullability getNullability() const noexcept { return nullability_; }
66
70 const std::string& getCollation() const noexcept { return collation_; }
71
80
90 Column(Name name, SqlType type, std::string collation, Nullability nullability = Nullability::Nullable);
91
92 private:
94 const Name name_;
96 const SqlType type_;
98 const Nullability nullability_;
100 const std::string collation_;
101 };
102
103 public:
111
119 explicit TableDefinition(TableName name, std::vector<Column> columns, Persistence persistence = Persistence::Permanent);
120
124 const std::vector<Column>& getColumns() const noexcept { return columns_; }
125
132 const Column& getColumn(hyper_field_index_t columnIndex) const;
133
139 const Column* getColumnByName(const Name& s) const noexcept;
140
147
151 size_t getColumnCount() const noexcept { return columns_.size(); }
152
156 Persistence getPersistence() const noexcept { return persistence_; }
157
161 const TableName& getTableName() const noexcept { return name_; }
162
169
171 TableDefinition& addColumn(const Column& c) noexcept;
172
179
186
187 private:
189 TableName name_;
191 Persistence persistence_;
193 std::vector<Column> columns_;
194
195 friend class internal::HyperTableDefinition;
196};
197}
198
199#include <hyperapi/impl/TableDefinition.impl.hpp>
200
201#endif
Represents an escaped SQL name.
Definition Name.hpp:18
A Hyper SQL type.
Definition SqlType.hpp:44
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:15
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.