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_exec with a proxy object:

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

Which is the same as:

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


53
54
55
56
57
# File 'lib/sequel/extensions/query.rb', line 53

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