Introduce SqlFieldType Abstraction and Enhance MySQL Result Handling;#2463
Conversation
b7ba272 to
c2ad4c8
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a SqlFieldType enumeration and related metadata abstractions for MySQL result handling, and moves setBody(const char*, size_t) from private to public in the HttpResponse interface.
Changes:
- New
SqlFieldTypeenum andColumnMetastruct added to the ORM public API, with MySQL mapping and integration intoMysqlResultImpl,ResultImpl,Result, andField. setBody(const char*, size_t)promoted fromprivatetopublicinHttpResponseand moved to a public section inHttpResponseImpl.- Trantor submodule pointer updated.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
trantor |
Submodule bumped to a newer commit |
orm_lib/src/mysql_impl/MysqlResultImpl.h |
Adds mysqlTypeToSql, mysqlFieldTypeToName helper functions and ColumnMeta population in constructor |
orm_lib/src/mysql_impl/MysqlResultImpl.cc |
Implements columnMeta() accessor |
orm_lib/src/ResultImpl.h |
Adds default columnMeta() virtual method returning a static dummy |
orm_lib/src/Result.cc |
Implements new metadata accessor methods on Result |
orm_lib/inc/drogon/orm/Result.h |
Declares SqlFieldType, ColumnMeta, and new public accessor methods |
orm_lib/inc/drogon/orm/Field.h |
Exposes per-field metadata helpers via Field |
lib/src/HttpResponseImpl.h |
Moves setBody(const char*, size_t) from private to public section |
lib/inc/drogon/HttpResponse.h |
Promotes setBody(const char*, size_t) to public virtual API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Hi @an-tao In a previous change, I mistakenly modified the access level of This PR reverts that change and restores the original access level to maintain proper encapsulation and consistency with the existing Drogon implementation. Please consider this PR for merging into the main branch. |
Summary
This pull request introduces a new
SqlFieldTypeenumeration and enhances MySQL result handling to provide explicit SQL field type representation and improved type safety.Additionally, this PR improves binary HTTP response handling by exposing a more efficient raw buffer body-setting method at both the
HttpResponseinterface level and itsHttpResponseImplimplementation.The goal is to provide structured SQL field type abstraction for MySQL while preserving backward compatibility and improving performance in binary response scenarios.
Motivation
SQL Layer
Currently, Drogon does not provide a unified abstraction for SQL field types in MySQL result handling.
To improve type clarity and extensibility, this PR introduces:
SqlFieldTypeenumeration to represent SQL-native data types.SqlFieldTypemapping logic.This enables stronger type awareness and prepares the foundation for future database-related enhancements.
HTTP Binary Body Handling
When constructing binary HTTP responses, the existing usage pattern often requires converting raw buffers into temporary
std::stringobjects before calling:This may introduce unnecessary memory copies in large-payload or high-throughput scenarios.
To improve efficiency, direct raw buffer assignment support was enabled by exposing:
at the HttpResponse interface level and updating its visibility in HttpResponseImpl.
This allows more efficient binary body handling without intermediate string construction.
Changes Introduced
1. Introduction of SqlFieldType
Added new SqlFieldType enumeration.
Implemented MySQL-native type mapping to the new enum.
Integrated the enum into MySQL result processing logic.
2. MySQL Result Enhancements
Extended MysqlResultImpl to expose and utilize SqlFieldType.
Added helper methods for improved field access and type interpretation.
Updated Result and ResultImpl where necessary to support the new abstraction.
3. HTTP Response API Enhancement
Changed visibility of:
in HttpResponse from private to public.
Updated HttpResponseImpl accordingly.
Enables direct raw buffer assignment for binary responses.
Reduces unnecessary memory copies in performance-sensitive scenarios.
The existing
remains unchanged and fully supported.
4. Related Adjustments
Updated affected components (
field.*,HttpResponse.*, and related implementations) to maintain consistent integration.PostgreSQL and SQLite implementations remain unaffected.
Compatibility
No breaking changes to existing public APIs.
Existing behavior remains unchanged unless the new functionality is explicitly used.
The new SqlFieldType abstraction is additive.
HTTP response behavior remains backward compatible.
Stability
Tested under active usage for approximately one month in a production-like environment.
No regressions or performance issues were observed.
Binary response handling validated under load conditions.
Notes
I welcome feedback regarding:
The design and scope of the new SqlFieldType abstraction
Public API exposure of
setBody(const char*, size_t)API surface considerations
Alternative approaches if preferred by maintainers