SQT
A C++ ORM framework for SQLite
Loading...
Searching...
No Matches

◆ SQT_COLUMN_FIELD_2

#define SQT_COLUMN_FIELD_2 ( COLUMN_NAME,
INSTANCE_NAME,
FIELD )

Defines a column with a custom instance name that binds to the specified field of the entity type.

Parameters
COLUMN_NAMEThe name of the column in the database.
INSTANCE_NAMEThe name of the column instance.
FIELDThe field of the entity type to which the column is bound.

This macro is similar to the SQT_COLUMN_FIELD macro, except that it allows specifying a custom name for the column instance. This is useful in scenarios where the auto-generated instance name would conflict with other names generated by the framework.

The instance name is also used to generate the class name of the column type, which is formed by appending the instance name to the prefix ColumnType_.

Example usage:

struct MyEntity {
int value{};
};
SQT_TABLE_BEGIN(MyEntityTable, MyEntity)
SQT_COLUMN_FIELD_2(Value, CustomValue, value)
#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
#define SQT_COLUMN_FIELD_2(COLUMN_NAME, INSTANCE_NAME, FIELD)
Defines a column with a custom instance name that binds to the specified field of the entity type.
Definition table_definition.h:332

The following code demonstrates the generated definition of the Value column in the table type:

class TableType {
public:
// The class name of the column type is generated by appending the instance name to
// "ColumnType_".
class ColumnType_CustomValue {
public:
// The column name in the database.
static constexpr std::string_view Name = "ID";
// Other definitions are omitted.
};
// The instance of the column.
ColumnType_CustomValue CustomValue;
};
See also
SQT_COLUMN_FIELD