Defines a column that binds to the specified field of the entity type.
- Parameters
-
| COLUMN_NAME | The name of the column in the database. It will be also used as the instance name of the column. |
| FIELD | The field of the entity type to which the column is bound. |
This macro must be used between the SQT_TABLE_BEGIN and SQT_TABLE_END macros.
Each column name must be unique within a table definition to avoid conflicts.
A field is a public member variable of the entity type. The framework reads from and writes to the field when performing mapping between entity instances and database rows. The type of the field must satisfy the requirements of the sqt::BasicValueType concept.
Example usage:
struct MyEntity {
int id{};
std::string name;
};
#define SQT_COLUMN_FIELD(COLUMN_NAME, FIELD)
Defines a column that binds to the specified field of the entity type.
Definition table_definition.h:273
#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 code demonstrates the generated definition of the ID column in the table type:
class TableType {
public:
using EntityType = ENTITY_TYPE;
public:
static constexpr std::string_view Name = "ID";
class ValueSource;
using ValueType = int;
using ValueTraits = sqt::BasicValueTraitsMappingT<ValueType>;
IDType(const IDType&) = delete;
IDType& operator=(const IDType&) = delete;
IDType(IDType&&) = delete;
IDType& operator=(IDType&&) = delete;
constexpr auto operator=(const ValueType&) const noexcept;
constexpr auto Asc() const noexcept;
constexpr auto Desc() const noexcept;
friend constexpr auto operator==(const IDType&, const ValueType&) const noexcept;
friend constexpr auto operator==(const IDType&, sqt::Placeholder) const noexcept;
friend constexpr auto operator==(const ValueType&, const IDType&) const noexcept;
friend constexpr auto operator==(sqt::Placeholder, const IDType&) const noexcept;
};
ColumnType_ID ID;
};
Represents a column in a table that is associated with a specific entity type.
Definition column.h:34
The class name and the instance name of the column is auto-generated from the used-defined column name, this may cause name collision with other names generated by the framework. To resolve the collision, use the SQT_COLUMN_FIELD_2 overload macro to provide a custom instance name of the column.
To define a column that binds to a pair of accessor methods, use the SQT_COLUMN_ACCESSOR or SQT_COLUMN_ACCESSOR_2 macros. To define a column that binds to a custom value source, use the
SQT_COLUMN_CUSTOM or SQT_COLUMN_CUSTOM_2` macros.
- See also
- SQT_TABLE_BEGIN
-
SQT_TABLE_END
-
SQT_COLUMN_ACCESSOR
-
SQT_COLUMN_ACCESSOR_2
-
SQT_COLUMN_CUSTOM
-
SQT_COLUMN_CUSTOM_2
-
SQT_COLUMN_FIELD_2
-
sqt::BasicValueType
-
sqt::Column<>