-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
SQL Comparison Operators #42
Comments
At this moment the @jodosha do you have something in mind of how the API for these operator should be? |
@jodosha what do you think about adopting https://github.com/rails/arel? |
@joneslee85 In which context? Repository, Adapter? |
@jodosha you can use sequel's where block condition. You can use it like this: def self.where_age_greater_than(gt)
query do
where{ age > gt }
end
end I made an test implementation for this. coenert/model@6cdfd861a1ebe6783410690effb5faebc1dd3c51 |
@coenert nice! This way we don't need to use arel. |
@jodosha In Repository, I really like their powerful query builder. |
@joneslee85 ehm, i think the only way to adopt ARel is to use it as an sql query builder in our sql_adapter, ARel is just made to build queries without knowing the db. But sequel already provides most of the functions ARel has. @jodosha what's your opinion about using sequel's(or ARel's) api to build our queries(like my example)? The problem of this is that you need to wrap their documentation and you don't always know if there are little not documented features added that you don't want. |
@coenert @carloslopes @joneslee85 Let's clarify one thing first: query API is not part of a repository. A repository is a client of that API, which is implemented by the adapters. ARel: I really like it, but we can achieve the same results using Sequel for relational databases. Now, I'm aware of the power of the lambda based API of Sequel. That wasn't introduced it in On the other hand we can have SQL literals, but they are dangerous for injections, and the author encourages to use of lambdas. Another con is couple repository implementation with specific SQL fragments, whereas lambdas are Ruby, so they are abstracted. The way to follow are lambdas. @coenert Would you like to take care of this and create a PR? I noticed that you didn't tested the condition that triggers def where(condition = nil, &blk)
condition or blk or raise ArgumentError.new('You need to specify an condition.')
# ...
end One unresolved issue is about database functions: how to express them with that API? dataset.update(:updated_at => Sequel.function(:NOW))
dataset.update(:updated_at => Sequel.lit('NOW()')) But I see it cumbersome to use in situations like this: where{ function(:DATE, created_at) < function(:NOW) } |
@jodosha yes, i wil create a PR when i have time. |
@jodosha I agree to use Sequel that is already a dependency to solve this is the better way. @coenert solution is simple and effective. 👍 |
@jodosha The only way to add the class ::Sequel::SQL::VirtualRow
def function(name, *args)
return Sequel.function(name, *args)
end
end With this you can use function in you where queries: where{ function(:DATE, Date.today) < function(:NOW) } Do you agree with this implementation? |
@coenert In my experience, reopening libraries is always source of maintenance pain. |
@jodosha I can imagine your concerns. I think there are 2 ways of implementing functions in the lambda.
For the long term i prefer option 2 because if you use Sequels implementation you are adding functions(and bugs) you don't know about, and because we always have the attributes to our disposal we don't have to implement method_missing. |
I have the following method in a repository:
Calling the class method
active
viaWidgetRepository.active
results in the following error:I do not see any examples or documentation for this functionality within Lotus. Any help would be appreciated.
The text was updated successfully, but these errors were encountered: