-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for array values in WHERE clause of CQL queries #7
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
base: master
Are you sure you want to change the base?
Conversation
This commit enhances the CQL query functionality by allowing array values in the WHERE clause. It introduces tests to verify that queries can handle single and multiple array conditions correctly. Additionally, the column type validation is updated to accept both single values and arrays, ensuring robust handling of various input types in query conditions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces support for array values in SQL WHERE clauses within the CQL module, improves type handling for columns, and enhances query-building logic. The key changes include:
- Updating method signatures in query handling to accept arrays.
- Adjusting column type definitions and validation to support single values and arrays.
- Adding new tests to verify proper handling of array-based conditions.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/query.cr | Updates to where and condition-building methods to handle array values. |
src/expression/expressions.cr | Adjustments in the Expression::InCondition initialization to accept varying types. |
src/column.cr | Changes to column type declaration and validation logic to support arrays. |
spec/core/query_spec.cr | New test cases for verifying correct behavior with array values in selections. |
raise Error.new "Expected column `#{name}` to be #{type}, but got #{value.class}" | ||
def validate!(value : T | Array(T)) forall T | ||
return if value.class == JSON::Any | ||
return if value.class == T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updated validate! method only checks the class of the input value and does not iterate over array elements when an Array is provided, which may cause valid array inputs to be rejected. Consider iterating through the array and validating each element against the expected type.
return if value.class == T | |
if value.is_a?(Array) | |
value.each do |element| | |
unless element.is_a?(T) | |
raise Error.new "Expected all elements of column `#{name}` to be #{type}, but got #{element.class}" | |
end | |
end | |
return | |
end | |
return if value.is_a?(T) |
Copilot uses AI. Check for mistakes.
@@ -726,12 +725,24 @@ module CQL | |||
end | |||
|
|||
# Expects hash with String keys now | |||
private def build_condition_from_hash(hash : Hash(Symbol | String, DB::Any)) | |||
private def build_condition_from_hash(hash : Hash(Symbol | String, T | Array(T))) forall T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] There are two overloads of build_condition_from_hash with similar logic; consolidating them could reduce duplication and improve code clarity.
Copilot uses AI. Check for mistakes.
This pull request introduces support for handling array values in SQL
WHERE
clauses, improves type handling in theCQL
module, and enhances query-building functionality. The changes include updates to allow arrays in conditions, adjustments to type definitions, and modifications to validation and query-building logic.Support for array values in
WHERE
clauses:WHERE
clauses, including single and multiple array conditions (spec/core/query_spec.cr
).where
method to acceptHash
values containing arrays, enabling more flexible query conditions (src/query.cr
).Type handling improvements:
type
property inCQL::Column
to support single types and arrays of types (src/column.cr
).validate!
method inCQL::Column
to handle both single values and arrays, ensuring proper validation for array-based conditions (src/column.cr
).Query-building enhancements:
build_condition_from_hash
andget_expression
methods to handle array values, enabling the generation ofIN
conditions in SQL queries (src/query.cr
). [1] [2]build_condition_from_hash
method by removing redundant logic and ensuring compatibility with array-based conditions (src/query.cr
).