Hyper API for C++  0.0.15530
Hyper client library for C++ applications
TableDefinition.hpp
Go to the documentation of this file.
1 
5 #ifndef TABLEAU_HYPER_TABLEDEFINITION_HPP
6 #define TABLEAU_HYPER_TABLEDEFINITION_HPP
7 
9 #include <hyperapi/SqlType.hpp>
10 #include <hyperapi/TableName.hpp>
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 
18 namespace hyperapi {
19 
23 enum Nullability : bool {
25  Nullable = true,
27  NotNullable = false
28 };
29 
31 std::ostream& operator<<(std::ostream& os, Nullability nullability);
32 
34 enum class Persistence {
36  Permanent,
38  Temporary
39 };
40 
44 class 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 
79  Column(Name name, SqlType type, Nullability nullability = Nullability::Nullable);
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:
110  explicit TableDefinition(TableName name, Persistence persistence = Persistence::Permanent);
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 
168  TableDefinition& addColumn(Column&& c) noexcept;
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
hyperapi::Persistence
Persistence
Possible persistence levels for database objects.
Definition: TableDefinition.hpp:34
hyperapi::TableDefinition::getColumns
const std::vector< Column > & getColumns() const noexcept
Returns all columns.
Definition: TableDefinition.hpp:124
hyperapi::SqlType
A Hyper SQL type.
Definition: SqlType.hpp:43
hyperapi::TableDefinition::setPersistence
TableDefinition & setPersistence(Persistence p) noexcept
Sets the table's persistence.
hyperapi::TableDefinition::TableDefinition
TableDefinition(TableName name, Persistence persistence=Persistence::Permanent)
Creates a table definition with the given name and no columns.
hyperapi::TableDefinition::Column::getCollation
const std::string & getCollation() const noexcept
Returns the collation of the column.
Definition: TableDefinition.hpp:70
hyperapi::Nullable
The column can contain NULL values.
Definition: TableDefinition.hpp:25
hyperapi::TableDefinition::column_index_type
hyper_field_index_t column_index_type
Type of a column index.
Definition: TableDefinition.hpp:47
hyperapi::Persistence::Temporary
Temporary: Only available in the own session, not persisted.
hyperapi::Name
Represents an escaped SQL name.
Definition: Name.hpp:18
hyperapi::NotNullable
The column cannot contain NULL values.
Definition: TableDefinition.hpp:27
hyperapi::TableDefinition::getColumn
const Column & getColumn(hyper_field_index_t columnIndex) const
Returns the column at the given position.
hyperapi::TableDefinition
A table definition.
Definition: TableDefinition.hpp:44
HyperException.hpp
hyperapi::TableDefinition::getColumnPositionByName
optional< hyper_field_index_t > getColumnPositionByName(const Name &s) const noexcept
Returns the position of the column with the given name.
hyperapi::optional
Surrogate for C++17 std::optional
Definition: optional.hpp:40
hyperapi::TableDefinition::Column::getName
const Name & getName() const noexcept
Returns the name of the column.
Definition: TableDefinition.hpp:55
hyperapi::operator<<
std::ostream & operator<<(std::ostream &os, const DatabaseName &name)
Stream output operator.
Definition: DatabaseName.hpp:48
hyperapi::Nullability
Nullability
The nullability of a column.
Definition: TableDefinition.hpp:23
SqlType.hpp
hyperapi::TableDefinition::getPersistence
Persistence getPersistence() const noexcept
Returns the table persistence.
Definition: TableDefinition.hpp:156
hyperapi
The primary namespace of the Hyper API for C++.
Definition: ByteSpan.hpp:15
hyperapi::TableDefinition::Column
A Column of a table definition.
Definition: TableDefinition.hpp:50
hyperapi::TableDefinition::Column::getNullability
Nullability getNullability() const noexcept
Returns the Nullability of the column.
Definition: TableDefinition.hpp:65
hyperapi::TableDefinition::getColumnCount
size_t getColumnCount() const noexcept
Returns the numbers of columns.
Definition: TableDefinition.hpp:151
hyperapi::Persistence::Permanent
Permanent.
hyperapi::TableDefinition::addColumn
TableDefinition & addColumn(Column &&c) noexcept
Adds a column to the definition.
hyperapi::TableName
Represents an escaped SQL table name.
Definition: TableName.hpp:15
hyperapi::TableDefinition::getTableName
const TableName & getTableName() const noexcept
Returns the name of the table.
Definition: TableDefinition.hpp:161
TableName.hpp
hyperapi::TableDefinition::Column::Column
Column(Name name, SqlType type, Nullability nullability=Nullability::Nullable)
Creates a column.
hyperapi::TableDefinition::getColumnByName
const Column * getColumnByName(const Name &s) const noexcept
Returns the column with the given name.
hyperapi::TableDefinition::setTableName
TableDefinition & setTableName(TableName n) noexcept
Sets the table's name.
hyperapi::TableDefinition::Column::getType
const SqlType & getType() const noexcept
Returns the type of the column.
Definition: TableDefinition.hpp:60
optional.hpp