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

◆ SQT_COLUMN_ACCESSOR

#define SQT_COLUMN_ACCESSOR ( COLUMN_NAME,
GETTER,
SETTER )

Defines a column that binds to the specified accessor methods 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.
GETTERA const member function of the entity type that retrieves the column value from an entity instance.
SETTERA non-const member function of the entity type that assigns the column value to an entity instance.

This macro is similar to SQT_COLUMN_FIELD, except that it binds to a pair of accessor methods instead of a public member variable.

The getter method must be a const member function that takes no arguments and returns a value. The return type must satisfy the requirements of the sqt::BasicValueType concept. The column's value type is deduced from this return type.

The setter method must be a non-const member function that accepts a value convertible from the getter's return type as its parameter.

Example usage:

class MyEntity {
public:
int GetID() const {
return id_;
}
void SetID(int id) {
id_ = id;
}
const std::string& GetName() const {
return name_;
}
void SetName(std::string_view name) {
name_ = std::string{ name };
}
private:
int id_{};
std::string name_;
};
SQT_TABLE_BEGIN(MyEntityTable, MyEntity)
SQT_COLUMN_ACCESSOR(ID, GetID, SetID)
SQT_COLUMN_ACCESSOR(Name, GetName, SetName)
#define SQT_COLUMN_ACCESSOR(COLUMN_NAME, GETTER, SETTER)
Defines a column that binds to the specified accessor methods of the entity type.
Definition table_definition.h:398
#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
See also
SQT_COLUMN_ACCESSOR_2
SQT_COLUMN_FIELD