Begins the definition of a table type for the specified entity type.
- Parameters
-
| TABLE_NAME | The name of the table. It will be the table name in the database. |
| ENTITY_TYPE | The entity type for which the table type is being defined. If this macro is used in a different namespace from the entity type, the namespace must be explicitly specified. |
This macro opens the definition of a table type, which must be closed using the SQT_TABLE_END macro. Within the definition, the following macros can be used:
- Defining columns:
- SQT_COLUMN_FIELD
- SQT_COLUMN_FIELD_2
- SQT_COLUMN_ACCESSOR
- SQT_COLUMN_ACCESSOR_2
- SQT_COLUMN_CUSTOM
- SQT_COLUMN_CUSTOM_2
- Defining primary key:
- SQT_PRIMARY_KEY
- SQT_PRIMARY_KEY_AUTO_INC
- Defining indexes:
- SQT_INDEX
- SQT_INDEX_2
- SQT_INDEX_UNIQUE
- SQT_INDEX_UNIQUE_2
This macro can be used in any namespace, including the anonymous namespace. If the entity type is defined in a different namespace, ENTITY_TYPE must be prefixed with its namespace to ensure proper resolution.
- Note
- While identical table names can exist in different namespaces, this is discouraged as it may cause name conflicts when used within the same database.
Example usage:
namespace my_scope {
class MyEntity { };
}
#define SQT_TABLE_BEGIN(TABLE_NAME, ENTITY_TYPE)
Begins the definition of a table type for the specified entity type.
Definition table_definition.h:141
#define SQT_TABLE_END
Ends the definition of a table type.
Definition table_definition.h:854
The following class demonstrates the expected interface of a defined table type:
public:
using EntityType = ENTITY_TYPE;
static constexpr const TableType& GetInstance() noexcept;
constexpr sqt::ColumnsView<EntityType> GetColumns() const noexcept;
constexpr sqt::ColumnsView<EntityType> GetPrimaryKeyColumns() const noexcept;
constexpr sqt::ColumnsView<EntityType> GetNonPrimaryKeyColumns() const noexcept;
template<sqt::ColumnType COLUMN>
constexpr const sqt::Column<EntityType>* GetColumn() const noexcept;
TableType(const TableType&) = delete;
TableType& operator=(const TableType&) = delete;
TableType(TableType&&) = delete;
TableType& operator=(TableType&&) = delete;
private:
constexpr TableType() noexcept;
};
An interface that provides access to information about a table.
Definition abstract_table.h:24
- Note
- After defining a table type, it must be registered in the framework using the SQT_REGISTER macro.
After registration, the helper templates sqt::TableType<> and sqt::Table<> allow access to the table type and its singleton instance.
- Note
- While it is legal to define multiple table types for the same entity type, only one table type can be registered for each entity type. Attempting to register multiple table types for the same entity type will result in a compilation error.
- See also
- SQT_COLUMN_FIELD
-
SQT_COLUMN_ACCESSOR
-
SQT_COLUMN_CUSTOM
-
SQT_PRIMARY_KEY
-
SQT_PRIMARY_KEY_AUTO_INC
-
SQT_INDEX
-
SQT_INDEX_UNIQUE
-
SQT_TABLE_END
-
SQT_REGISTER
-
sqt::TableType<>
-
sqt::Table<>
-
sqt::AbstractTable