Skip to content

Introduce SqlFieldType Abstraction and Enhance MySQL Result Handling; Expose Efficient Binary setBody API#2463

Open
karthikeyan-netizen wants to merge 11 commits intodrogonframework:masterfrom
karthikeyan-netizen:feature/extend-sqlfieldtype-mysql-support
Open

Introduce SqlFieldType Abstraction and Enhance MySQL Result Handling; Expose Efficient Binary setBody API#2463
karthikeyan-netizen wants to merge 11 commits intodrogonframework:masterfrom
karthikeyan-netizen:feature/extend-sqlfieldtype-mysql-support

Conversation

@karthikeyan-netizen
Copy link

@karthikeyan-netizen karthikeyan-netizen commented Mar 2, 2026

Summary

This pull request introduces a new SqlFieldType enumeration 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 HttpResponse interface level and its HttpResponseImpl implementation.

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:

  • A new SqlFieldType enumeration to represent SQL-native data types.
  • Internal MySQL-to-SqlFieldType mapping logic.
  • Helper methods for safer and clearer type interpretation when accessing result fields.

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::string objects before calling:

virtual void setBody(const std::string &body) = 0;

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:

virtual void setBody(const char* body, size_t len) = 0;

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:

virtual void setBody(const char* body, size_t len) = 0;

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

virtual void setBody(const std::string &body) = 0;

remains unchanged and fully supported.

  • No existing functionality has been removed or modified.

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

@karthikeyan-netizen karthikeyan-netizen changed the title Feature: Extend SqlFieldType and Enhance MySQL Result Handling Feature: Extend SqlFieldType and Enhance MySQL Result Handling; Expose Efficient Binary setBody API Mar 2, 2026
@karthikeyan-netizen karthikeyan-netizen changed the title Feature: Extend SqlFieldType and Enhance MySQL Result Handling; Expose Efficient Binary setBody API Introduce SqlFieldType Abstraction and Enhance MySQL Result Handling; Expose Efficient Binary setBody API Mar 3, 2026
@karthikeyan-netizen karthikeyan-netizen force-pushed the feature/extend-sqlfieldtype-mysql-support branch from b7ba272 to c2ad4c8 Compare March 6, 2026 11:06
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