Introduce SqlFieldType Abstraction and Enhance MySQL Result Handling; Expose Efficient Binary setBody API#2463
Open
karthikeyan-netizen wants to merge 11 commits intodrogonframework:masterfrom
Conversation
b7ba272 to
c2ad4c8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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