Skip to content

Fix quote method to use database adapter for MySQL compatibility#15

Merged
takaokouji merged 6 commits intomasterfrom
fix/quote-method-mysql-compatibility
Jan 21, 2026
Merged

Fix quote method to use database adapter for MySQL compatibility#15
takaokouji merged 6 commits intomasterfrom
fix/quote-method-mysql-compatibility

Conversation

@takaokouji
Copy link
Collaborator

Summary

  • Fix quote() method to use _model_class.connection.quote_column_name() instead of hardcoded double quotes
  • This ensures proper quoting for different databases (MySQL uses backticks, PostgreSQL/SQLite use double quotes)
  • Add unit tests for quote method behavior
  • Add MySQL and PostgreSQL services to docker-compose for multi-database testing

Test plan

  • Run quote method tests with SQLite (default)
  • Run quote method tests with MySQL via Docker
  • Run quote method tests with PostgreSQL via Docker
  • Full test suite passes on Rails 6.1 and 7.0

Docker commands for testing

# Test with MySQL
docker-compose run --rm rails-6.1-mysql

# Test with PostgreSQL
docker-compose run --rm rails-6.1-postgres

🤖 Generated with Claude Code

takaokouji and others added 6 commits January 21, 2026 09:42
The quote method was hardcoding double quotes (") which only works for
PostgreSQL/SQLite. MySQL requires backticks (`). This change delegates
to the Rails connection adapter's quote_column_name method to use the
correct quoting style for each database.

Changes:
- Fix quote() to use _model_class.connection.quote_column_name()
- Add unit tests for quote method with mock MySQL adapter
- Add MySQL and PostgreSQL services to docker-compose for testing
- Add mysql2 gem to Gemfile

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add `resource` and `resources` methods to ResourceSetOperationResult and
ResourcesSetOperationResult for backward compatibility with 0.9.x API.

In 0.9.x, operation results had a `resource` accessor. In 0.10+, resources
are accessed via `resource_set`. These new methods allow existing code
that uses `result.resource` to continue working without modification.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract common resource/resources methods into ResourceSetResultMethods module
- Use iterator pattern with each_resource for efficiency
- Include module in ResourceSetOperationResult and ResourcesSetOperationResult

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The find_by_key signature tests were not needed based on the actual
patch requirements. Keep only the resource/resources method tests
for ResourceSetOperationResult backward compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
In 0.9.x, apply_filters was a public method that could be called from
outside the resource class. In the current version, it was moved to
the protected section. This change restores public accessibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
In 0.10+, find_fragments uses ActiveRecord-specific methods (records.pluck)
which fails for PORO (Plain Old Ruby Object) models. This change adds
automatic detection of non-ActiveRecord models and falls back to a
find_by_key-based implementation.

Detection: _model_class.respond_to?(:all)
Fallback: find_fragments_for_non_active_record uses find_by_key

This eliminates the need for PORO resources to override find_fragments,
maintaining 0.9.x compatibility where create/find_by_key worked without
the subsequent re-fetch via find_fragments.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@takaokouji takaokouji merged commit 67957b0 into master Jan 21, 2026
60 checks passed
@takaokouji takaokouji deleted the fix/quote-method-mysql-compatibility branch January 21, 2026 02:17
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