fix: Repo.exists? generates valid SQL with SELECT 1#69
Conversation
Repo.exists? was generating invalid SQL with an empty SELECT clause: `SELECT FROM "users"` instead of `SELECT 1 FROM "users"` This caused a syntax error: "near FROM: syntax error" The fix adds a clause to handle empty field lists in select_fields/3, matching the behaviour of ecto_sqlite3 adapter.
WalkthroughThe changes add a new private clause in the LibSQL adapter's select_fields function to handle empty field selections by returning "1" instead of constructing fields, and introduce a comprehensive test module validating Repo.exists?/2 behaviour across various query scenarios including empty selects and transactions. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Thanks very much @ricardo-valero good pick up! Merged 👍 |
Summary
Repo.exists?generating invalid SQL with empty SELECT clauseRepo.exists?/2functionalityProblem
Repo.exists?was generating invalid SQL:Instead of:
This caused:
SQLite failure: near "FROM": syntax errorSolution
Added a clause to handle empty field lists in
select_fields/3:This matches the behaviour of the ecto_sqlite3 adapter.
Testing
test/exists_query_test.exsSummary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.