Module: Lore::Query_Shortcuts

Included in:
Model, Table_Accessor
Defined in:
lib/lore/query_shortcuts.rb

Instance Method Summary collapse

Instance Method Details

#all(what = nil) ⇒ Object



333
334
335
# File 'lib/lore/query_shortcuts.rb', line 333

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)


366
367
368
# File 'lib/lore/query_shortcuts.rb', line 366

def all_with(condition)
  Refined_Select.new(self, :condition => condition)
end

#deleteObject

Example:

Accessor.delete.where(...).perform


382
383
384
# File 'lib/lore/query_shortcuts.rb', line 382

def delete
  Refined_Delete.new(self)
end

#delete_allObject

Deletes all entities of model class, i.e. empties its tables (!). Example:

Car.delete_all


391
392
393
394
395
# File 'lib/lore/query_shortcuts.rb', line 391

def delete_all
  delete { |entity|
    entity.where(true)
  }
end

#each(&block) ⇒ Object

Wrapper for

Accessor.all.entities.each { |e| ... }


341
342
343
# File 'lib/lore/query_shortcuts.rb', line 341

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(...) ...


350
351
352
353
354
355
356
# File 'lib/lore/query_shortcuts.rb', line 350

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


374
375
376
# File 'lib/lore/query_shortcuts.rb', line 374

def set(values)
  Refined_Update.new(self, :update_values => values)
end

#value_of(what = nil) ⇒ Object

Example:

Users.value_of.sum(:user_id)


329
330
331
# File 'lib/lore/query_shortcuts.rb', line 329

def value_of(what=nil)
  Refined_Select.new(self, :condition => true, :what => what)
end