Module: Sequel::SQL::OperatorBuilders

Included in:
Sequel, VirtualRow
Defined in:
lib/sequel/sql.rb

Overview

This adds methods to create SQL expressions using operators:

Sequel.+(1, :a)   # (1 + a)
Sequel.-(1, :a)   # (1 - a)
Sequel.*(1, :a)   # (1 * a)
Sequel./(1, :a)   # (1 / a)
Sequel.&(:b, :a)   # (b AND a)
Sequel.|(:b, :a)   # (b OR a)

Instance Method Summary collapse

Instance Method Details

#**(a, b) ⇒ Object

Return NumericExpression for the exponentiation:

Sequel.**(2, 3) # SQL: power(2, 3)

847
848
849
# File 'lib/sequel/sql.rb', line 847

def **(a, b)
  SQL::NumericExpression.new(:**, a, b)
end

#~(arg) ⇒ Object

Invert the given expression. Returns a Sequel::SQL::BooleanExpression created from this argument, not matching all of the conditions.

Sequel.~(nil) # SQL: NOT NULL
Sequel.~([[:a, true]]) # SQL: a IS NOT TRUE
Sequel.~([[:a, 1], [:b, [2, 3]]]) # SQL: a != 1 OR b NOT IN (2, 3)

857
858
859
860
861
862
863
# File 'lib/sequel/sql.rb', line 857

def ~(arg)
  if condition_specifier?(arg)
    SQL::BooleanExpression.from_value_pairs(arg, :OR, true)
  else
    SQL::BooleanExpression.invert(arg)
  end
end