Class | Proc
In: | lib/sequel/extensions/sql_expr.rb
Parent: | Object

### Methods

sql_expr

### Public Instance methods

sql_expr()

Evaluates the proc as a virtual row block. If a hash or array of two element arrays is returned, they are converted to a Sequel::SQL::BooleanExpression. Otherwise, unless the object returned is already an Sequel::SQL::Expression, convert the object to an Sequel::SQL::GenericComplexExpression.

      proc{a(b)}.sql_expr + 1  # a(b) + 1
      proc{{a=>b}}.sql_expr | true  # (a = b) OR TRUE
      proc{1}.sql_expr + :a  # 1 + a

[Source]

        # File lib/sequel/extensions/sql_expr.rb, line 89
    89:   def sql_expr
    90:     o = Sequel.virtual_row(&self)
    91:     if Sequel.condition_specifier?(o)
    92:       Sequel::SQL::BooleanExpression.from_value_pairs(o, :AND)
    93:     elsif o.is_a?(Sequel::SQL::Expression)
    94:       o
    95:     else
    96:       Sequel::SQL::GenericComplexExpression.new(:NOOP, o)
    97:     end
    98:   end

[Validate]