ores.refdata.country

Table of Contents

ISO 3166-1 country definitions used for reference data. Countries use alpha-2, alpha-3, and numeric codes per the ISO standard.

Flags

Columns

alpha2_code

ISO 3166-1 alpha-2 code (e.g., "US", "GB").

No :name generator block is defined for this primary key. The synthetic generate_synthetic_country function will produce an empty prefix; this is intentional — the fictional generator (generate_fictional_countries, injected via paste) is the authoritative test-data source for country and does not rely on the template-generated synthetic path.

alpha3_code

ISO 3166-1 alpha-3 code (e.g., "USA", "GBR").

std::string(faker::location::countryCode()) + "X"

numeric_code

ISO 3166-1 numeric code (e.g., "840", "826").

std::to_string(faker::number::integer(10001, 99999))

name

Short name of the country (e.g., "United States").

std::string(faker::location::country())

official_name

Official name of the country (e.g., "United States of America").

"Republic of " + std::string(faker::location::country())

image_id

Optional reference to a flag image in the images table.

std::nullopt

coding_scheme_code

Optional coding scheme code for the country.

std::nullopt

SQL

Flags

Extra drops

drop function if exists ores_refdata_validate_country_fn;

Validation function

Insert trigger

Validations

column validation_function
change_reason_code ores_dq_validate_change_reason_fn

Indexes

alpha3

numeric

C++

Flags

Repository

Domain includes

#include <boost/uuid/uuid.hpp>
#include <chrono>
#include <optional>
#include <string>

Entity includes

#include <optional>
#include <string>

Conventions

Table display

column header
alpha2_code Alpha-2 Code
alpha3_code Alpha-3 Code
numeric_code Numeric Code
name Name
official_name Official Name
modified_by Modified By
version Version

Qt

Detail fields

field label widget type is_key is_required placeholder
alpha2_code Alpha-2 Code codeEdit line_edit true true Enter country alpha2 code
alpha3_code Alpha-3 Code alpha3CodeEdit line_edit   true Enter country alpha3 code
numeric_code Numeric Code numericCodeEdit line_edit   true Enter ISO numeric code
name Name nameEdit line_edit   true Enter display name
official_name Official Name officialNameEdit line_edit   true Enter official country name

Columns (Qt model)

enum_name field header type width
Alpha2Code alpha2_code Alpha-2 Code string 80
Alpha3Code alpha3_code Alpha-3 Code string 80
NumericCode numeric_code Numeric Code string 80
Name name Name string 200
OfficialName official_name Official Name string 200
Version version Version int 80
ModifiedBy modified_by Modified By string 120
RecordedAt recorded_at Recorded At timestamp 150

Custom service constructor init

, junction_repo_(ctx_)

Custom service includes

#include <boost/uuid/uuid.hpp>
#include "ores.refdata.core/repository/party_country_repository.hpp"

Custom service .cpp includes

#include <algorithm>
#include <boost/uuid/uuid_io.hpp>
#include <unordered_set>

Custom service methods

/**
 * @brief Lists countries visible to a specific party, with pagination.
 *
 * @param party_id The UUID of the party.
 * @param offset Number of records to skip.
 * @param limit Maximum number of records to return.
 * @return Vector of visible countries for the requested page.
 */
std::vector<domain::country> list_countries_for_party(const boost::uuids::uuid& party_id,
                                                      std::uint32_t offset,
                                                      std::uint32_t limit);

/**
 * @brief Gets the total count of countries visible to a specific party.
 *
 * @param party_id The UUID of the party.
 * @return Number of countries the party is permitted to see.
 */
std::uint32_t count_countries_for_party(const boost::uuids::uuid& party_id);

Custom service members

repository::party_country_repository junction_repo_;

Custom service implementations

std::vector<domain::country> country_service::list_countries_for_party(
    const boost::uuids::uuid& party_id, std::uint32_t offset, std::uint32_t limit) {
    BOOST_LOG_SEV(lg(), debug) << "Listing countries for party: " << party_id
                               << " offset=" << offset << " limit=" << limit;

    const auto junctions = junction_repo_.read_latest_by_party(party_id);
    std::unordered_set<std::string> visible;
    visible.reserve(junctions.size());
    for (const auto& j : junctions)
        visible.insert(j.country_alpha2_code);

    auto all = repo_.read_latest(ctx_);
    std::vector<domain::country> filtered;
    filtered.reserve(visible.size());
    for (auto& c : all) {
        if (visible.count(c.alpha2_code))
            filtered.push_back(std::move(c));
    }

    if (offset >= filtered.size())
        return {};
    const auto end = std::min<std::size_t>(offset + limit, filtered.size());
    return std::vector<domain::country>(filtered.begin() + offset, filtered.begin() + end);
}

std::uint32_t country_service::count_countries_for_party(const boost::uuids::uuid& party_id) {
    BOOST_LOG_SEV(lg(), debug) << "Counting countries for party: " << party_id;
    const auto junctions = junction_repo_.read_latest_by_party(party_id);
    return static_cast<std::uint32_t>(junctions.size());
}

Custom generator declarations

/**
 * @brief Generates a set of fictional countries.
 *
 * These are intentionally fake countries with made-up codes that do not
 * correspond to any real ISO 3166-1 codes. Useful for testing and demo
 * purposes where real country data should not be used.
 *
 * @param n Number of countries to generate. If n is 0 or greater than the
 *          available set (50), returns all available fictional countries.
 */
ORES_REFDATA_API_EXPORT std::vector<domain::country>
generate_fictional_countries(std::size_t n, utility::generation::generation_context& ctx);

/**
 * @brief Generates the ISO 3166-1 "ZZ" user-assigned sentinel country.
 *
 * Represents "supranational / not country-specific" — used by calendar
 * rows (e.g. TARGET) with no single owning country. ZZ is one of ISO
 * 3166-1's own reserved user-assigned code elements (AA, QM-QZ, XA-XZ,
 * ZZ), never allocated to a real country, so this is real reference
 * data rather than fictional test data.
 */
ORES_REFDATA_API_EXPORT domain::country
generate_country_sentinel(utility::generation::generation_context& ctx);

Custom generator implementations

std::vector<domain::country>
generate_fictional_countries(std::size_t n, utility::generation::generation_context& ctx) {
    const auto modified_by = ctx.env().get_or(generation_keys::modified_by, "system");
    const auto now = ctx.past_timepoint();

    std::vector<domain::country> all;
    all.reserve(50);

    all.push_back({.alpha2_code = "AL", .alpha3_code = "AER", .numeric_code = "10001",
                   .name = "Aerilon", .official_name = "Republic of Aerilon",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "AR", .alpha3_code = "ARC", .numeric_code = "10002",
                   .name = "Arcturia", .official_name = "Federation of Arcturia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "BA", .alpha3_code = "BAL", .numeric_code = "10003",
                   .name = "Balthoria", .official_name = "Kingdom of Balthoria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "BE", .alpha3_code = "BEL", .numeric_code = "10004",
                   .name = "Belloria", .official_name = "Principality of Belloria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "CA", .alpha3_code = "CAL", .numeric_code = "10005",
                   .name = "Calandria", .official_name = "Empire of Calandria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "CD", .alpha3_code = "CLD", .numeric_code = "10006",
                   .name = "Caledonia", .official_name = "Commonwealth of Caledonia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "DA", .alpha3_code = "DAE", .numeric_code = "10007",
                   .name = "Daeloria", .official_name = "Republic of Daeloria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "DE", .alpha3_code = "DEL", .numeric_code = "10008",
                   .name = "Delvadia", .official_name = "Duchy of Delvadia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "ER", .alpha3_code = "ERI", .numeric_code = "10009",
                   .name = "Eriador", .official_name = "United Realms of Eriador",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "ES", .alpha3_code = "EST", .numeric_code = "10010",
                   .name = "Esteria", .official_name = "Republic of Esteria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "FE", .alpha3_code = "FEL", .numeric_code = "10011",
                   .name = "Feloria", .official_name = "Federation of Feloria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "FN", .alpha3_code = "FEN", .numeric_code = "10012",
                   .name = "Fendaria", .official_name = "Republic of Fendaria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "GA", .alpha3_code = "GAL", .numeric_code = "10013",
                   .name = "Galdoria", .official_name = "Kingdom of Galdoria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "GR", .alpha3_code = "GRN", .numeric_code = "10014",
                   .name = "Grendoria", .official_name = "Empire of Grendoria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "HE", .alpha3_code = "HEL", .numeric_code = "10015",
                   .name = "Helvetia", .official_name = "Confederation of Helvetia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "HY", .alpha3_code = "HYD", .numeric_code = "10016",
                   .name = "Hydronia", .official_name = "Republic of Hydronia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "IR", .alpha3_code = "IRI", .numeric_code = "10017",
                   .name = "Iridia", .official_name = "Commonwealth of Iridia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "IT", .alpha3_code = "ITH", .numeric_code = "10018",
                   .name = "Ithaca", .official_name = "Republic of Ithaca",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "JE", .alpha3_code = "JET", .numeric_code = "10019",
                   .name = "Jethro", .official_name = "Kingdom of Jethro",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "JO", .alpha3_code = "JOR", .numeric_code = "10020",
                   .name = "Jorvik", .official_name = "Kingdom of Jorvik",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "KA", .alpha3_code = "KAE", .numeric_code = "10021",
                   .name = "Kaelor", .official_name = "Empire of Kaelor",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "KR", .alpha3_code = "KRY", .numeric_code = "10022",
                   .name = "Krynn", .official_name = "Federation of Krynn",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "LU", .alpha3_code = "LUM", .numeric_code = "10023",
                   .name = "Luminia", .official_name = "Republic of Luminia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "LY", .alpha3_code = "LYS", .numeric_code = "10024",
                   .name = "Lysandria", .official_name = "Principality of Lysandria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "MA", .alpha3_code = "MAL", .numeric_code = "10025",
                   .name = "Maldoria", .official_name = "Kingdom of Maldoria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "MR", .alpha3_code = "MRP", .numeric_code = "10026",
                   .name = "Mariposa", .official_name = "Republic of Mariposa",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "NE", .alpha3_code = "NEK", .numeric_code = "10027",
                   .name = "Nektonia", .official_name = "Federation of Nektonia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "NT", .alpha3_code = "NTH", .numeric_code = "10028",
                   .name = "Netharia", .official_name = "Commonwealth of Netharia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "OR", .alpha3_code = "ORI", .numeric_code = "10029",
                   .name = "Orinoco", .official_name = "Republic of Orinoco",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "OL", .alpha3_code = "ORL", .numeric_code = "10030",
                   .name = "Orlanthia", .official_name = "Empire of Orlanthia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "PA", .alpha3_code = "PAL", .numeric_code = "10031",
                   .name = "Paldoria", .official_name = "Kingdom of Paldoria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "PY", .alpha3_code = "PYR", .numeric_code = "10032",
                   .name = "Pyrrhia", .official_name = "Republic of Pyrrhia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "QU", .alpha3_code = "QUE", .numeric_code = "10033",
                   .name = "Quentaria", .official_name = "Duchy of Quentaria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "QN", .alpha3_code = "QUI", .numeric_code = "10034",
                   .name = "Quinaria", .official_name = "Federation of Quinaria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "RE", .alpha3_code = "REN", .numeric_code = "10035",
                   .name = "Rendellia", .official_name = "Republic of Rendellia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "RI", .alpha3_code = "RIV", .numeric_code = "10036",
                   .name = "Rivenia", .official_name = "Commonwealth of Rivenia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "SE", .alpha3_code = "SER", .numeric_code = "10037",
                   .name = "Serendia", .official_name = "Kingdom of Serendia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "SI", .alpha3_code = "SIL", .numeric_code = "10038",
                   .name = "Sildoria", .official_name = "Empire of Sildoria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "TA", .alpha3_code = "TAN", .numeric_code = "10039",
                   .name = "Tandor", .official_name = "Republic of Tandor",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "TE", .alpha3_code = "TEN", .numeric_code = "10040",
                   .name = "Tenebria", .official_name = "Federation of Tenebria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "UL", .alpha3_code = "ULD", .numeric_code = "10041",
                   .name = "Uldoria", .official_name = "Kingdom of Uldoria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "UT", .alpha3_code = "UTP", .numeric_code = "10042",
                   .name = "Utopia", .official_name = "Republic of Utopia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "VA", .alpha3_code = "VAL", .numeric_code = "10043",
                   .name = "Valoria", .official_name = "Empire of Valoria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "VL", .alpha3_code = "VLT", .numeric_code = "10044",
                   .name = "Valtaria", .official_name = "Principality of Valtaria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "WI", .alpha3_code = "WIN", .numeric_code = "10045",
                   .name = "Wintervale", .official_name = "Commonwealth of Wintervale",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "WY", .alpha3_code = "WYS", .numeric_code = "10046",
                   .name = "Wysteria", .official_name = "Republic of Wysteria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "XA", .alpha3_code = "XAN", .numeric_code = "10047",
                   .name = "Xandria", .official_name = "Kingdom of Xandria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "XE", .alpha3_code = "XEN", .numeric_code = "10048",
                   .name = "Xenoria", .official_name = "Federation of Xenoria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "YS", .alpha3_code = "YSL", .numeric_code = "10049",
                   .name = "Yslandia", .official_name = "Republic of Yslandia",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});
    all.push_back({.alpha2_code = "ZE", .alpha3_code = "ZEP", .numeric_code = "10050",
                   .name = "Zephyria", .official_name = "Empire of Zephyria",
                   .modified_by = modified_by, .change_reason_code = "system.test",
                   .change_commentary = "Synthetic test data", .recorded_at = now});

    if (n == 0 || n >= all.size())
        return all;

    return std::vector<domain::country>(all.begin(), all.begin() + n);
}

domain::country generate_country_sentinel(utility::generation::generation_context& ctx) {
    const auto modified_by = ctx.env().get_or(generation_keys::modified_by, "system");
    const auto now = ctx.past_timepoint();

    return domain::country{.alpha2_code = "ZZ", .alpha3_code = "ZZZ", .numeric_code = "999",
                           .name = "Supranational / Not Country-Specific",
                           .official_name = "Supranational / Not Country-Specific",
                           .modified_by = modified_by, .change_reason_code = "system.initial_load",
                           .change_commentary = "ISO 3166-1 user-assigned sentinel for "
                                                 "supranational calendars", .recorded_at = now};
}

Custom repository methods

The following method goes beyond the standard repository template: an unfiltered read_all. Pagination, the active-count aggregate, batch delete, and read_at_timepoint (both overloads, via has_as_of_lookup: true) are now generated by the standard template and are no longer carried here.

Repository impl includes

No extra includes needed — <sqlgen/postgres.hpp>, bitemporal_operations.hpp, and helpers.hpp are already in the standard template output.


Repository implementations

std::vector<domain::country> country_repository::read_all(context ctx) {
    BOOST_LOG_SEV(lg(), debug) << "Reading all country versions.";
    const auto tid = ctx.tenant_id().to_string();
    const auto query = sqlgen::read<std::vector<country_entity>> |
                       where("tenant_id"_c == tid) |
                       order_by("valid_from"_c.desc());

    return execute_read_query<country_entity, domain::country>(
        ctx,
        query,
        [](const auto& entities) { return country_mapper::map(entities); },
        lg(),
        "Reading all countries.");
}

read_all (no filter overload)

/**
 * @brief Reads all versions of all countries (no key filter), newest first.
 */
std::vector<domain::country> read_all(context ctx);

See also

Emacs 29.3 (Org mode 9.6.15)