Skip to content

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

@jchrys

Description

@jchrys

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions