Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]Support for tinyInt1isBit Flag to Handle TINYINT(1) as Boolean #299

Closed
jchrys opened this issue Jan 22, 2025 · 0 comments · Fixed by #300
Closed

[feature]Support for tinyInt1isBit Flag to Handle TINYINT(1) as Boolean #299

jchrys opened this issue Jan 22, 2025 · 0 comments · Fixed by #300
Labels
enhancement New feature or request
Milestone

Comments

@jchrys
Copy link
Collaborator

jchrys commented Jan 22, 2025

Feature Request

Summary

Enable seamless mapping of TINYINT(1) to Boolean in r2dbc-mysql by implementing the tinyInt1isBit flag with true as the default behavior. This enhancement aligns with the common MySQL convention of using TINYINT(1) for boolean values, simplifying development workflows and improving compatibility with existing schemas.

Problem Statement

Currently, r2dbc-mysql does not treat TINYINT(1) as Boolean by default. This creates challenges for developers who rely on the widespread convention of TINYINT(1) being used for boolean fields in MySQL schemas. The following issues arise:

  • Developers are forced to modify their database schemas (e.g., switching to BIT(1)), which is often impractical for legacy systems.
  • Custom converters or manual getter/setter logic must be implemented to handle boolean mappings, adding unnecessary complexity to the application code.

Given that TINYINT(1) is commonly treated as a boolean in many MySQL connectors (e.g., mysql-connector-j), r2dbc-mysql should adopt the same behavior by default to minimize friction and provide an intuitive developer experience.

Proposed Solution

  1. Implement the tinyInt1isBit flag in r2dbc-mysql.
  2. Set the default value of tinyInt1isBit to true, ensuring that:
    • TINYINT(1) columns are automatically mapped to Boolean fields in Java entities.
    • Developers can explicitly disable this behavior if they prefer TINYINT(1) to be treated as Integer.

Example Configuration for Overriding Default Behavior:

spring:
  r2dbc:
    url: r2dbc:mysql://<host>/<database>?tinyInt1isBit=false

Benefits

  1. Seamless Integration:
    Treating TINYINT(1) as Boolean by default aligns with developer expectations and reduces the need for schema changes or custom logic.

  2. Compatibility with MySQL Ecosystem:
    This change aligns r2dbc-mysql with other popular MySQL connectors (e.g., Hibernate, JDBC), which treat TINYINT(1) as boolean by default.

  3. Flexibility:
    Developers who require TINYINT(1) to be treated as Integer can easily disable the feature by setting tinyInt1isBit=false.

References

@jchrys jchrys added the enhancement New feature or request label Jan 22, 2025
@jchrys jchrys added this to the Next milestone Jan 23, 2025
@jchrys jchrys linked a pull request Jan 31, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant