Support inequality operators when parsing queries#29
Conversation
Very rudimentary but works great so far
WalkthroughUpdated private SQL binding parsing in lib/feeb/db/query/binding.ex to split on " ?" and adjust atom extraction position. Added a new ExUnit test module validating parse_params/3 across several SELECT statements with varying placeholder counts. No public API changes. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Binding as Binding.parse_params/3
participant Parser as parse_kv (private)
Client->>Binding: parse_params(:select, sql, [])
activate Binding
Binding->>Parser: parse_kv(sql)
note right of Parser: Tokenize by " ?"<br/>Extract key from second-to-last token
Parser-->>Binding: [{:key, :placeholder}, ...]
Binding-->>Client: bindings list
deactivate Binding
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
lib/feeb/db/query/binding.ex (1)
45-52: Consider edge cases for robustness.The current implementation assumes:
- A space always precedes the
?placeholder (e.g.,id = ?works, butid=?would extract the wrong token)- Simple column names without functions or complex expressions
While these assumptions are reasonable for typical SQL usage, consider whether documentation or validation would help prevent subtle bugs.
test/db/query/binding_test.exs (1)
8-14: Consider adding edge case tests for completeness.While the current test cases cover common scenarios well, consider adding tests for edge cases such as:
- Operators without spaces (e.g.,
"select * from users where id=?")- Multiple consecutive spaces
- Different whitespace characters (tabs, newlines)
This would help catch potential parsing issues early and document expected behavior for unusual inputs.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/feeb/db/query/binding.ex(1 hunks)test/db/query/binding_test.exs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
test/db/query/binding_test.exs (1)
lib/feeb/db/query/binding.ex (1)
parse_params(16-21)
lib/feeb/db/query/binding.ex (1)
lib/feeb/db/query.ex (1)
defp handle_atstring(<<98, 105, 110, 100, 32, 91, raw_bindings::binary>>, qs, id, q) do(398-408)
🔇 Additional comments (3)
lib/feeb/db/query/binding.ex (2)
45-52: LGTM! Logic correctly supports inequality operators.The change from splitting on
" = ?"to" ?"combined with extractingEnum.at(-2)correctly handles various comparison operators (=,>,<,>=,<=). The logic successfully extracts the column name before the operator for all tested cases.
45-52: parse_params callers scope verified
Only one invocation in lib/feeb/db/query.ex remains; no additional callers affected by the updatedparse_kvlogic.test/db/query/binding_test.exs (1)
1-20: LGTM! Good test coverage for the new inequality operator support.The test cases effectively validate the updated
parse_params/3behavior across various operators (=,>=,>,<,<=) and combinations withAND/ORclauses. The parameterized test structure usingEnum.eachis clean and maintainable.
Very rudimentary but works great so far ✅
Summary by CodeRabbit