class ExampleQuery
Public Instance Methods
arel()
click to toggle source
`#arel` is where you might put Arel code. As long as the return value of the method responds to `to_sql`, you're good. The code will be converted to SQL, executed, and passed into process.
# File lib/generators/sqrl/install/templates/example_query.rb, line 25 def arel users = User.arel_table users.where(users[:name].eq(@name)) .project(users[:email]) end
finder()
click to toggle source
`#finder` execute the code in the method and pass directly to `#process`. Great for ActiveRecord `find_by`, `where`, etc.
# File lib/generators/sqrl/install/templates/example_query.rb, line 18 def finder User.find_by(id: @id, name: @name, email: @email) end
process(result)
click to toggle source
process handles the result of the query before passing it to the caller. It's defined by default like this.
# File lib/generators/sqrl/install/templates/example_query.rb, line 12 def process(result) result end
raw_sql()
click to toggle source
`#raw_sql` is for raw sql code. It gets executed and passed to process.
# File lib/generators/sqrl/install/templates/example_query.rb, line 32 def raw_sql "SELECT * FROM users WHERE name = '#{@name}'" end