Module: Sequel::DatasetQuery

Defined in:
lib/sequel/extensions/query.rb

Instance Method Summary collapse

Instance Method Details

#query(&block) ⇒ Object

Translates a query block into a dataset. Query blocks are an alternative to Sequel’s usual method chaining, by using instance_eval with a proxy object:

dataset = DB[:items].query do
  select :x, :y, :z
  filter{(x > 1) & (y > 2)}
  reverse :z
end

Which is the same as:

dataset = DB[:items].select(:x, :y, :z).filter{(x > 1) & (y > 2)}.reverse(:z)


55
56
57
58
59
# File 'lib/sequel/extensions/query.rb', line 55

def query(&block)
  query = Dataset::Query.new(self)
  query.instance_eval(&block)
  query.dataset
end