Skip to content

Map member _orm_name annotations to column names; ignore foreign annotations - #1570

Draft
trueqbit wants to merge 2 commits into
devfrom
feature/reflected-column-names
Draft

trueqbit wants to merge 2 commits into
devfrom
feature/reflected-column-names

Conversation

@trueqbit

@trueqbit trueqbit commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The _orm_name / orm_name() annotation, so far only honored at class scope for the names of reflected tables and views, now also names a column when placed on a non-static data member:

struct [[="users"_orm_name]] User {
    [[="user_id"_orm_name, =primary_key()]] int64 userId;
    [[=orm_name("display_name")]] std::string displayName;
};

auto storage = make_storage("", make_table<User>());

This works for make_table<T>() and make_view<T>() alike (a view's renamed columns appear in its CREATE VIEW column list), and for members inherited from base classes.

In addition, reflected tables and views now ignore annotations of other libraries, so a struct can carry e.g. serialization annotations next to sqlite_orm's.

Changes

Column names from member annotations

  • dbo_name_literal is renamed to mapped_name_literal, and dev/schema/dbo_name.h moves to dev/schema/orm_name.h: the name is no longer only a database object's. The public spellings are unchanged.
  • mapped_name_of<refl> resolves the name of any entity, class or member, entirely at compile time into a static string: the value of its name annotation, or its reflected identifier (replacing extract_type_identifier). It rejects more than one name annotation per entity. Run-time code of the factories therefore holds no reflection-dependent expression, which g++-16 rejects outside a constant-evaluated context.
  • make_reflected_column<member> builds a column from a member's annotations; make_reflected_table uses it.

Annotations of other libraries

  • An annotation counts as sqlite_orm's own if its type is declared within namespace sqlite_orm (is_declared_within, which judges a class template specialization by its template's scope). All others are skipped.
  • sqlite_orm's own annotations are still validated by the consuming factories (validate_column_definition, validate_base_table_definition), so a misplaced one remains a compile error.
  • splice_annotations_within<refl, ns> replaces splice_annotations / extract_type_annotations; extract_orm_annotations<refl> applies the sqlite_orm policy.
  • Views accept a mapped name as their only sqlite_orm annotation, at class scope and on members. Previously, member annotations of a view were silently dropped.

Tests

  • Renamed columns keep their constraints, with the name annotation before or after them; schema sync checked via table_xinfo.
  • Renamed column from a base class member.
  • Foreign annotations at class scope and on members of a table, and of a view (serialized CREATE VIEW).
  • Compile-time checks of is_declared_within.

🤖 Generated with Claude Code

The `_orm_name`/`orm_name()` annotation, so far only honored at class scope
for table and view names, now also names the column when placed on a
non-static data member, both for reflected tables and views.

* Rename `dbo_name_literal` to `mapped_name_literal` and move
  dev/schema/dbo_name.h to dev/schema/orm_name.h: the name is no longer
  only a database object's.
* `resolve_mapped_name<refl>` falls back to the reflected identifier of
  any entity, class or member, replacing `extract_type_identifier`, and
  rejects more than one name annotation.
* `make_reflected_column<member>` builds a column from a member's
  annotations; `make_reflected_table` uses it.
* Reflected views honor member name annotations, which show in the
  CREATE VIEW column list, and reject column constraints instead of
  silently dropping them.

Co-Authored-By: Claude Opus 5.5
A struct mapped by reflection may carry annotations of other libraries,
e.g. for serialization. Until now these were spliced as table elements or
column constraints and failed the definition's validation.

An annotation now counts as sqlite_orm's own if its type is declared
within namespace `sqlite_orm`; all others are skipped. sqlite_orm's own
annotations are still validated by the factories consuming them, so a
misplaced one remains a compile error.

* `splice_annotations_within<refl, ns>` replaces `splice_annotations`
  and `extract_type_annotations`, built on `is_declared_within`, which
  judges a class template specialization by its template's scope.
* `extract_orm_annotations<refl>` applies the `sqlite_orm` policy for
  reflected tables, columns and views.
* Views accept a mapped name as their only sqlite_orm annotation, at
  class scope and on members, replacing the narrower column-constraint
  check.
* The consteval `mapped_name_of<refl>` replaces `resolve_mapped_name`:
  it resolves the name entirely at compile time into a static string, so
  the factories' run-time code holds no reflection-dependent expression,
  which g++-16 rejects outside a constant-evaluated context.

Co-Authored-By: Claude Opus 5.5
@trueqbit
trueqbit force-pushed the feature/reflected-column-names branch from 150b47a to 406997a Compare October 6, 2026 16:00

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant