-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add new includes method for Array queries. #733
Conversation
private def check_using_array!(_value : Array.class) | ||
end | ||
|
||
private def check_using_array!(_value) |
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.
These aren't actually used right now, but I wanted to leave them in as a template to the compile-time pattern. I do plan on eventually figuring out how to use it.
module Avram::IncludesCriteria(T, V) | ||
macro included | ||
# WHERE `value` = ANY(column) | ||
def includes(value) : 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.
I also debated on contains
, but with includes
, we could also add an excludes
method... What would be the opposite of contains
, omits
? 🤷♂️
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 Avram DSL here is close enough to sql that I think includes makes sense.
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.
Actually, I misunderstood the purpose of this when I said that. But I still think that includes is as good a name as any. Sorry for the email spam from my github comments 🤪
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.
😂 cool. Second confirmation is what I needed. Thanks
Fixes #640
I'm only adding the
includes
method for now, and with somewhat limited support. One issue I would like to figure out before going full support is how to catch this method at compile-time so you only call it on Array columns. I tried several different patterns, but there's a few issues with it that I'll open up in a separate issue.This PR allows you query for records with Array columns where a specific value exists in that column.
If you try to call this on a non-array column, Postgres will throw a runtime error when you run the query.