Skip to content

feat(orm): map rows and add synchronous CRUD - #100

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

Antruly merged 3 commits into
masterfrom
feat/orm-crud

Conversation

@Antruly

@Antruly Antruly commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Closes #91. Parent: #88. Stacked on #98 (feat/orm-sql) and #96 (feat/orm-model); retarget to master after #96/#98 merge.

What changed

Adds the synchronous single-table execution layer:

  • src/orm/uvcpp_orm_repository.h
    • find_by_pk<T>, find_all<T> (constructed SQL or SELECT builder), insert<T>, update<T>, remove<T>, count<T>;
    • executes through the existing uvcpp_db_client / uvcpp_db_params; no new connection or transaction;
    • maps by exact column name; missing nullable columns become empty nullable<T>; missing non-null columns fail before mapping any row;
    • SQL NULL vs empty string preserved; BLOB, bool, floating point, all integer widths and nullable variants supported;
    • checked integer conversion rejects out-of-range values instead of truncating;
    • update/remove use the single primary key; insert skips auto-increment and read-only columns and can回填 last_insert_id;
    • affected == 0 is OK with affected 0; execution failure keeps the backend uvcpp_db_status and db.last_error().
  • New statuses: NOT_FOUND, MAPPING_FAILED, MISSING_COLUMN, TYPE_MISMATCH, NULL_VIOLATION, DB_ERROR, INVALID_ARGUMENT.
  • doc/orm-guide.md — first single-table CRUD guide with the transaction/async boundaries stated as future work.
  • tests/functional/orm_sqlite_func.cpp — real SQLite CRUD coverage.
  • Static-build test linkage for orm_* execution tests.

Verification

[orm_sqlite] checks=117 failures=0
[PASS] orm_sqlite: all 117 checks passed

ctest -R '^test_orm_(model|sql|sqlite)_func$|^test_db_sqlite_func$'
1/4 test_db_sqlite_func   Passed
2/4 test_orm_model_func   Passed
3/4 test_orm_sql_func     Passed
4/4 test_orm_sqlite_func  Passed
100% tests passed, 0 tests failed out of 4

C++11 -pedantic-errors -Wall -Wextra -fsyntax-only exits 0. Static library build also passes the 117 checks. With ORM=OFF there are no orm_* tests and test_db_sqlite_func still passes.

Covered in the SQLite test: insert/auto id, primary-key and condition lookups, count with limit, update/delete/0-row results, NULL vs empty string, integer bounds, double/bool/BLOB, missing/unexpected columns, type mismatch, NULL into non-null, unique conflict and invalid arguments.

Known limits / unverified

  • MySQL, PostgreSQL, ODBC and MongoDB real servers are not verified; this PR runs SQLite only.
  • Transactions and async are intentionally not implemented here; [ORM] 事务与异步集成 #92 owns them.
  • SQLite binds a zero-length BLOB as NULL in the existing db layer, so the test uses a non-empty BLOB and the limitation is documented; src/db/ was not changed.
  • find_all(const uvcpp_orm_sql_result&, ..., total) derives COUNT(*) from the builder-shaped SELECT. It rejects raw SELECT lists containing placeholders; use the builder overload or explicit count<T>() in that case.
  • Full ctest and C ABI verification were not run; this change adds no C ABI surface.

Add find_by_pk/find_all/insert/update/remove/count on uvcpp_db_client, with exact column binding, nullable/NULL handling, checked integer conversion, BLOB/string mapping, primary-key based update/remove and explicit DB status propagation.

Add the SQLite CRUD test (117 checks), a first ORM guide, and link the SQLite client for ORM execution tests in static builds.
Register the ORM public headers in the snippet gate and wrap the executable examples in main() so the documentation gate builds every block.
@Antruly
Antruly changed the base branch from feat/orm-sql to master November 27, 2026 06:16
@Antruly

Antruly commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Local review before merge: SQLite ORM CRUD 117/117, ORM model 192/192, ORM SQL 295/295, DB SQLite 196 passed / 0 failed / 1 N/A, static build passes, ORM=OFF leaves no ORM tests. Guide snippets compile against the installed package; MySQL/PostgreSQL/ODBC and transactions/async are explicitly unverified/out of scope.

@Antruly
Antruly merged commit 41a99b8 into master Nov 27, 2026
4 of 6 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] 结果映射与 CRUD

1 participant