Skip to content

feat(orm): add model metadata contract - #96

Merged
Antruly merged 3 commits into
masterfrom
feat/orm-model
Nov 27, 2026
Merged

Antruly merged 3 commits into
masterfrom
feat/orm-model

Conversation

@Antruly

@Antruly Antruly commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Closes #89. Parent: #88. Milestone: 1.12.0.

What changed

Adds the ORM model contract and metadata layer:

  • uvcpp::nullable<T> — explicit SQL NULL vs. a present zero-length string; no exceptions.
  • uvcpp::uvcpp_orm_type — exact C++ type mapping for bool, signed/unsigned 8/16/32/64-bit integers, float, double, std::string, std::vector<uint8_t> and nullable<T>.
  • uvcpp::uvcpp_orm_column / model_traits<T> / validate_model<T>() — table name, column name/type/offset/size/flags, primary key lookup, duplicate/flag/auto-increment validation.
  • UVCPP_ORM_MODEL / UVCPP_ORM_FIELD / UVCPP_ORM_MODEL_END declaration macros.
  • UVCPP_BUILD_ORM (default OFF, requires UVCPP_ENABLE_DB=ON); forced OFF with a configure warning when DB is off.
  • tests/functional/orm_model_func.cpp and CMake discovery filtering: with ORM off the test is absent, not green.
  • Installs include/orm/ headers when ORM is enabled, and registers UVCPP_ORM_ENABLE in the config contract.

This layer does not generate SQL, execute CRUD, open connections, or change any DB/C ABI behavior. SQL construction, CRUD, transactions/async and benchmarks follow in #90–#95.

Verification

Environment: Linux x86_64, g++ 13.3.0, CMake Release, SQLite 3.45.1.

$ cmake ... -DUVCPP_ENABLE_DB=ON -DUVCPP_ENABLE_DB_SQLITE=ON \
    -DUVCPP_BUILD_ORM=ON -DUVCPP_BUILD_TESTS=ON
-- ORM module enabled (UVCPP_ORM_ENABLE=1)
-- Including orm module in build (model metadata)

$ ./build-orm/tests/functional/test_orm_model_func
[orm_model] start
[orm_model] checks=192 failures=0
[PASS] orm_model: all 192 checks passed

$ ctest --test-dir build-orm -R '^test_db_sqlite_func$|^test_orm_model_func$' --output-on-failure
1/2 Test #13: test_db_sqlite_func .............. Passed 0.10 sec
2/2 Test #31: test_orm_model_func .............. Passed 0.00 sec
100% tests passed, 0 tests failed out of 2

C++11 compile:

$ g++ -std=c++11 -pedantic-errors -c \
    -I build-orm/include -I src tests/functional/orm_model_func.cpp
exit=0

ORM off:

-- ORM module disabled (UVCPP_ORM_ENABLE=0)
-- Excluding orm module from build
1/1 Test #13: test_db_sqlite_func .................. Passed
Total Tests: 0        # ctest -N -R orm_model

Also verified:

  • Static build and install to a temporary prefix; installed headers compile and link a standalone consumer.
  • UVCPP_BUILD_ORM=ON with UVCPP_ENABLE_DB=OFF is forced OFF with the CMake warning above.
  • test_orm_model_func covers nullable empty/value/empty-string/move/reset/value_or, every supported type mapping, macro-generated offsets/order/flags, and all validation failure paths.

Unverified

  • MSVC and macOS compilation (only g++ 13.3.0 is available on this machine).
  • Full functional suite; this PR runs the ORM model test plus the existing SQLite DB test.
  • offsetof on aggregates containing std::string is conditionally supported in C++11; it works on g++ 13.3, and the limitation is documented in the header. MSVC needs confirmation in the CI matrix ([ORM] 跨后端测试与 CI #93).

Review focus

  • API shape for nullable<T>, model_traits<T> and the three macros before dependent SQL/CRUD work starts.
  • Flag/validation semantics: exactly one primary key, integer auto-increment, duplicate column names (ASCII case-insensitive), nullable/not_null conflict.
  • Whether UVCPP_BUILD_ORM default OFF is the right release default (turn-on belongs to [ORM] 文档、示例与发布门禁 #94 packaging/release).

Add the C++11 nullable value type, ORM type mapping, model traits macros, column metadata and validate_model<T>() for the 1.12.0 single-table ORM. The layer is header-only except for the status-name helper and reuses uvcpp_db_value; it does not generate SQL or touch the db client.

Gate the module behind UVCPP_BUILD_ORM, force it off when DB is disabled, and exclude orm tests when the module is off so an untested configuration is absent rather than green.
The ORM build option and module hooks necessarily insert lines in the root CMakeLists. Update every CMakeLists.txt line citation that moved and refresh the line-reference lock after checking the new targets resolve to the same blocks.
@Antruly

Antruly commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Local review before merge: ORM model tests 192/192, DB SQLite still passes, ORM=OFF has no ORM target, C++11 pedantic build, installed headers compile a standalone consumer, check_docs and check_doc_lines pass. GitHub Actions is still queued on shared runners; the only previous failure was the wsdl install-deps job, unrelated to this diff.

@Antruly
Antruly merged commit b6d55b7 into master Nov 27, 2026
46 of 49 checks passed
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.

[ORM] 模型契约与元数据

1 participant