Class: ExampleQuery
- Inherits:
-
Object
- Object
- ExampleQuery
- Includes:
- Squirrell
- Defined in:
- lib/generators/sqrl/install/templates/example_query.rb
Constant Summary
Constants included from Squirrell
Instance Method Summary collapse
-
#arel ⇒ Object
#arelis where you might put Arel code. -
#finder ⇒ Object
#finderexecute the code in the method and pass directly to#process. -
#process(result) ⇒ Object
process handles the result of the query before passing it to the caller.
-
#raw_sql ⇒ Object
#raw_sqlis for raw sql code.
Methods included from Squirrell
Instance Method Details
#arel ⇒ Object
#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.
25 26 27 28 29 |
# 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 ⇒ Object
#finder execute the code in the method and pass directly to #process. Great for ActiveRecord find_by, where, etc.
18 19 20 |
# 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) ⇒ Object
process handles the result of the query before passing it to the caller. It’s defined by default like this.
12 13 14 |
# File 'lib/generators/sqrl/install/templates/example_query.rb', line 12 def process(result) result end |
#raw_sql ⇒ Object
#raw_sql is for raw sql code. It gets executed and passed to process.
32 33 34 |
# File 'lib/generators/sqrl/install/templates/example_query.rb', line 32 def raw_sql "SELECT * FROM users WHERE name = '#{@name}'" end |