Module: Lore::Query_Shortcuts
- Included in:
- Model, Table_Accessor
- Defined in:
- lib/lore/query_shortcuts.rb
Instance Method Summary collapse
- #all(what = nil) ⇒ Object
-
#all_with(condition) ⇒ Object
Returns Refined_Select instance with WHERE statement set to condition.
-
#delete ⇒ Object
Example:.
-
#delete_all ⇒ Object
Deletes all entities of model class, i.e.
-
#each(&block) ⇒ Object
Wrapper for .
-
#find(amount, offset = 0) ⇒ Object
Returns Refined_Select instance with limit set to amount.
-
#set(values) ⇒ Object
Example:.
-
#value_of(what = nil) ⇒ Object
Example: .
Instance Method Details
#all(what = nil) ⇒ Object
301 302 303 |
# File 'lib/lore/query_shortcuts.rb', line 301 def all(what=nil) Refined_Select.new(self, :condition => true, :what => what) end |
#all_with(condition) ⇒ Object
Returns Refined_Select instance with WHERE statement set to condition. Same as
Accessor.find(:all).with(condition)
or
Accessor.all.with(condition)
334 335 336 |
# File 'lib/lore/query_shortcuts.rb', line 334 def all_with(condition) Refined_Select.new(self, :condition => condition) end |
#delete ⇒ Object
Example:
Accessor.delete.where(...).perform
350 351 352 |
# File 'lib/lore/query_shortcuts.rb', line 350 def delete Refined_Delete.new(self) end |
#delete_all ⇒ Object
Deletes all entities of model class, i.e. empties its tables (!). Example:
Car.delete_all
359 360 361 362 363 |
# File 'lib/lore/query_shortcuts.rb', line 359 def delete_all delete { |entity| entity.where(true) } end |
#each(&block) ⇒ Object
Wrapper for
Accessor.all.entities.each { |e| ... }
309 310 311 |
# File 'lib/lore/query_shortcuts.rb', line 309 def each(&block) all.entities.each(&block) end |
#find(amount, offset = 0) ⇒ Object
Returns Refined_Select instance with limit set to amount. Example:
Car.find(10).with(...) ...
318 319 320 321 322 323 324 |
# File 'lib/lore/query_shortcuts.rb', line 318 def find(amount, offset=0) if amount == :all then all() else Refined_Select.new(self, :limit => amount, :offset => offset) end end |
#set(values) ⇒ Object
Example:
Accessor.set(:attribute => 'value').where(...).perform
342 343 344 |
# File 'lib/lore/query_shortcuts.rb', line 342 def set(values) Refined_Update.new(self, :update_values => values) end |
#value_of(what = nil) ⇒ Object
Example:
Users.value_of.sum(:user_id)
297 298 299 |
# File 'lib/lore/query_shortcuts.rb', line 297 def value_of(what=nil) Refined_Select.new(self, :condition => true, :what => what) end |