Skip to content

Instantly share code, notes, and snippets.

@c910335
Created April 17, 2018 10:15
Show Gist options
  • Save c910335/b956346af7f0db34dbfda3ec3d42b315 to your computer and use it in GitHub Desktop.
Save c910335/b956346af7f0db34dbfda3ec3d42b315 to your computer and use it in GitHub Desktop.
Granite::ORM::Base.where
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