Skip to content

Add Boolean Conversion Support to JasyncRow #431

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

Merged
merged 3 commits into from
May 27, 2025

Conversation

Sung-Heon
Copy link
Contributor

@Sung-Heon Sung-Heon commented May 18, 2025

Description

This PR adds support for boolean type conversion in the JasyncRow class. Previously, the class supported conversions for various data types but did not explicitly handle boolean values. With these changes, the class can now properly convert various input data types (Numbers, Strings, Booleans) to Boolean values.

This enhancement is particularly important for MySQL databases, which represent boolean values as TINYINT(1) where 0 means false and any non-zero value (typically 1) means true. Our implementation correctly handles this MySQL-specific behavior by treating any non-zero numeric value as true.

Changes Made

  • Extended the get method in JasyncRow to handle boolean conversions with the following mapping:
    • Numbers: 0 → false, non-zero → true (aligned with MySQL's TINYINT(1) representation of booleans)
    • Strings: Using Kotlin's built-in Boolean parsing
    • Boolean values: Preserved as-is
    • Added proper handling for primitive boolean type
  • Added comprehensive test cases in JasyncRowTest to validate all conversion scenarios

Testing

  • Created a dedicated test class JasyncRowTest with a test method testBooleanConversion that verifies:
    • Boolean to Boolean conversion
    • Number to Boolean conversion (0 → false, non-zero → true)
    • String to Boolean conversion ("true" → true, "false" → false)
    • Accessing Boolean values by index
    • Tests pass successfully, confirming the implementation works as expected

Related Issue

#430

Additional Notes

This change enables more flexible type handling in the database access layer, making it easier to work with boolean values returned from MySQL queries. Since MySQL stores boolean values as TINYINT(1), this implementation ensures a seamless conversion between the database representation and the application-level Boolean type, improving type safety and code readability.

@oshai
Copy link
Contributor

oshai commented May 19, 2025

Thanks!

@Sung-Heon
Copy link
Contributor Author

I refactored. please run workflow again?

@oshai oshai merged commit 4fe7c77 into jasync-sql:master May 27, 2025
3 checks passed
@oshai
Copy link
Contributor

oshai commented May 27, 2025

Thanks!

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.

2 participants