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

◆ SQT_COLUMN_CUSTOM

#define SQT_COLUMN_CUSTOM ( COLUMN_NAME,
VALUE_SOURCE )

Defines a column that binds to the specified custom value source.

Parameters
COLUMN_NAMEThe name of the column in the database. It will be also used as the instance name of the column.
VALUE_SOURCEA type that satisfies the sqt::ValueSourceType concept, which defines the value type and methods for retrieving and setting values in an entity instance.

This macro is similar to SQT_COLUMN_FIELD, except that it binds to a custom value source. It is useful if the column value is not directly accessible through a field or accessor methods. For example, the column value may be derived from multiple fields or requires some computation or transformation before getting or setting it.

The sqt::ValueSourceType concept specifies the interface that a value source must implement:

  • The value type for the column.
  • Methods to retrieve and set the value in an entity instance.

Example usage:

struct MyEntity {
int id{};
std::string name;
};
// Define the value source type for the ID column.
struct IDValueSource {
using ValueType = int;
static int GetValueFromEntity(const MyEntity& entity) {
return entity.id;
}
static void SetValueToEntity(MyEntity& entity, int value) {
entity.id = value;
}
};
SQT_TABLE_BEGIN(MyEntityTable, MyEntity)
// Define the ID column with the custom value source.
SQT_COLUMN_CUSTOM(ID, IDValueSource)
// Define the Name column with an inline custom value source.
SQT_COLUMN_CUSTOM(Name, struct NameValueSource {
using ValueType = std::string;
static const std::string& GetValueFromEntity(const MyEntity& entity) {
return entity.name;
}
static void SetValueToEntity(MyEntity& entity, std::string value) {
entity.name = std::move(value);
}
})
#define SQT_COLUMN_CUSTOM(COLUMN_NAME, VALUE_SOURCE)
Defines a column that binds to the specified custom value source.
Definition table_definition.h:498
#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::ValueSourceType
SQT_COLUMN_CUSTOM_2
SQT_COLUMN_FIELD