Method: Sequel::SQL::Builders#delay

Defined in:
lib/sequel/sql.rb

#delay(&block) ⇒ Object

Return a delayed evaluation that uses the passed block. This is used to delay evaluations of the code to runtime. For example, with the following code:

ds = DB[:table].where{column > Time.now}

The filter is fixed to the time that where was called. Unless you are only using the dataset once immediately after creating it, that’s probably not desired. If you just want to set it to the time when the query is sent to the database, you can wrap it in Sequel.delay:

ds = DB[:table].where{column > Sequel.delay{Time.now}}

Note that for dates and timestamps, you are probably better off using Sequel::CURRENT_DATE and Sequel::CURRENT_TIMESTAMP instead of this generic delayed evaluation facility.

Raises:



412
413
414
415
# File 'lib/sequel/sql.rb', line 412

def delay(&block)
  raise(Error, "Sequel.delay requires a block") unless block
  SQL::DelayedEvaluation.new(block)
end