Created
April 17, 2018 10:15
-
-
Save c910335/b956346af7f0db34dbfda3ec3d42b315 to your computer and use it in GitHub Desktop.
Granite::ORM::Base.where
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Granite::ORM::Base | |
def self.where(**conditions) | |
params = [] of DB::Any | |
clause = String.build do |s| | |
s << "WHERE " | |
s << conditions.map do |k, v| | |
if v.nil? | |
"#{k} IS NULL" | |
else | |
params << v | |
"#{k} = ?" | |
end | |
end.join(" AND ") | |
end | |
all(clause, params) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment