ores.cpp.repository.entity_header
Table of Contents
sqlgen-side struct mirroring the table shape. repository profile.
See the Template variable reference for the complete list of available variables and their semantics.
Template
The full template source. Edit here and re-tangle with
compass build --direct tangle_codegen_templates to regenerate
library/templates/cpp_domain_type_entity.hpp.mustache.
{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/cpp_repository.org. Edit the org source. }}
{{{cpp_license}}}
{{#domain_entity}}
#ifndef ORES_{{component_core_upper}}_REPOSITORY_{{entity_singular_upper}}_ENTITY_HPP
#define ORES_{{component_core_upper}}_REPOSITORY_{{entity_singular_upper}}_ENTITY_HPP
#include <string>
#include <optional>
#include <ostream>
#include "ores.database/repository/db_types.hpp"
#include "sqlgen/PrimaryKey.hpp"
namespace ores::{{component}}::repository {
using db_timestamp = ores::database::repository::db_timestamp;
/**
* @brief Represents a {{entity_title_lower}} in the database.
*/
struct {{entity_singular}}_entity {
constexpr static const char* schema = "public";
constexpr static const char* tablename = "{{sql.tablename}}";
{{#primary_key.columns}}
sqlgen::PrimaryKey<std::string> {{column}};
{{/primary_key.columns}}
{{#has_tenant_id}}
std::string tenant_id;
{{/has_tenant_id}}
{{#has_workspace_id}}
std::string workspace_id;
{{/has_workspace_id}}
{{#has_audit_columns}}
int version = 0;
{{/has_audit_columns}}
{{#natural_keys}}
{{#is_uuid}}
std::string {{column}}{{#default_value}} = {{{default_value}}}{{/default_value}};
{{/is_uuid}}
{{#is_date}}
std::string {{column}};
{{/is_date}}
{{#is_timestamp}}
std::string {{column}};
{{/is_timestamp}}
{{^is_uuid}}{{^is_date}}{{^is_timestamp}}
{{{cpp_type}}} {{column}}{{#default_value}} = {{{default_value}}}{{/default_value}};
{{/is_timestamp}}{{/is_date}}{{/is_uuid}}
{{/natural_keys}}
{{#columns}}
{{#is_optional_uuid}}
std::optional<std::string> {{name}};
{{/is_optional_uuid}}
{{#is_uuid}}
std::string {{name}};
{{/is_uuid}}
{{#is_optional_timestamp}}
std::optional<sqlgen::Timestamp<"%Y-%m-%d %H:%M:%S">> {{name}};
{{/is_optional_timestamp}}
{{#is_required_timestamp}}
std::string {{name}};
{{/is_required_timestamp}}
{{#is_nullable_string}}
std::optional<std::string> {{name}};
{{/is_nullable_string}}
{{#is_already_optional}}
{{{cpp_type}}} {{name}};
{{/is_already_optional}}
{{#is_enum}}
std::string {{name}};
{{/is_enum}}
{{#is_simple}}
{{{cpp_type}}} {{name}}{{#default_value}} = {{{default_value}}}{{/default_value}};
{{/is_simple}}
{{/columns}}
{{#has_audit_columns}}
std::string modified_by;
std::string performed_by;
std::string change_reason_code;
std::string change_commentary;
{{/has_audit_columns}}
db_timestamp valid_from = "9999-12-31 23:59:59";
db_timestamp valid_to = "9999-12-31 23:59:59";
};
std::ostream& operator<<(std::ostream& s, const {{entity_singular}}_entity& v);
}
#endif
{{/domain_entity}}
{{#junction}}
#ifndef ORES_{{component_core_upper}}_REPOSITORY_{{name_singular_upper}}_ENTITY_HPP
#define ORES_{{component_core_upper}}_REPOSITORY_{{name_singular_upper}}_ENTITY_HPP
#include <string>
#include <optional>
#include <ostream>
#include "ores.database/repository/db_types.hpp"
#include "sqlgen/PrimaryKey.hpp"
namespace ores::{{component}}::repository {
using db_timestamp = ores::database::repository::db_timestamp;
/**
* @brief Represents a {{name_title_lower}} in the database.
*
* Junction table with composite primary key ({{left.column}}, {{right.column}}, valid_from).
*/
struct {{name_singular}}_entity {
constexpr static const char* schema = "public";
constexpr static const char* tablename = "{{sql.tablename}}";
sqlgen::PrimaryKey<std::string> {{left.column}};
{{#has_tenant_id}}
std::string tenant_id;
{{/has_tenant_id}}
std::string {{right.column}};
int version = 0;
{{#columns}}
{{{cpp_type}}} {{name}}{{#default_value}} = {{{default_value}}}{{/default_value}};
{{/columns}}
std::string modified_by;
std::string performed_by;
std::string change_reason_code;
std::string change_commentary;
db_timestamp valid_from = "9999-12-31 23:59:59";
db_timestamp valid_to = "9999-12-31 23:59:59";
};
std::ostream& operator<<(std::ostream& s, const {{name_singular}}_entity& v);
}
#endif
{{/junction}}
Design notes
Domain entity vs junction: unified on db_timestamp (2026-07-15)
Both the {{#domain_entity}} and {{#junction}} sections now use the
db_timestamp type alias (ores::database::repository::db_timestamp,
imported via db_types.hpp) for valid_from=/=valid_to, and both use the
component_core_upper-based include guard.
This was previously a documented, deliberate divergence (the junction
section used raw sqlgen::Timestamp<"%Y-%m-%d %H:%M:%S"> and a
component_upper-based guard instead), justified by "the composite-PK
interaction with sqlgen's db_timestamp alias has not been validated" —
but the existing hand-authored party_currency_entity.hpp=/
=party_country_entity.hpp (real, currently-compiling junction entities)
already use db_timestamp and the CORE-prefixed guard in production, which
is exactly the validation the old note said was missing. Unified the
template to match what already ships, while adding a codegen junction
facet for tenor_convention_resolution (see the
Retire legacy codegen profile
system; add junction support to physical-space codegen story).
Capture Unify junction entity timestamp type to db_timestamp alias can be closed as done.
See also
- Parent facet: ores.cpp.repository
- Template variable reference