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

◆ SQT_COLUMN_FIELD

#define SQT_COLUMN_FIELD ( COLUMN_NAME,
FIELD )

Defines a column that binds to the specified field of the entity type.

Parameters
COLUMN_NAMEThe name of the column in the database. It will be also used as the instance name of the column.
FIELDThe 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;
};
SQT_TABLE_BEGIN(MyEntityTable, MyEntity)
SQT_COLUMN_FIELD(Name, 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;
// The class name of the column type is generated by appending the column name to
// "ColumnType_".
class ColumnType_ID : public sqt::Column<EntityType> {
public:
// The name of the column.
static constexpr std::string_view Name = "ID";
// The value source type determines the column's value type and provides methods for
// reading from and writing to an entity instance
class ValueSource;
// The value type of the column, which is obtained from the ValueSource.
using ValueType = int;
// The value traits type that defines how the value is bound to and retrieved from the
// database statement.
using ValueTraits = sqt::BasicValueTraitsMappingT<ValueType>;
// Forbids copying.
IDType(const IDType&) = delete;
IDType& operator=(const IDType&) = delete;
// Forbids moving.
IDType(IDType&&) = delete;
IDType& operator=(IDType&&) = delete;
// Assignment operator that generates an assignment expression.
constexpr auto operator=(const ValueType&) const noexcept;
// Ordering operator that generates an ordering term expression.
constexpr auto Asc() const noexcept;
constexpr auto Desc() const noexcept;
// Comparison operators that generate predicate expressions.
// Here shows only the == operator. Other operators (!=, <, <=, >, >=) are omitted.
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;
};
// The instance of the column, which is defined as a public member variable of the table
// type. The name of the variable is the same as the column name.
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<>