class Arel::Visitors::ToSql - arel-4.0.2 Documentation

# class Arel::Visitors::ToSql

### Public Class Methods

new(connection) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 56
    def initialize connection
      @connection     = connection
      @schema_cache   = connection.schema_cache
      @quoted_tables  = {}
      @quoted_columns = {}
    end

### Private Instance Methods

build_subselect(key, o) click to toggle source

FIXME: we should probably have a 2-pass visitor for this

    # File lib/arel/visitors/to_sql.rb, line 73
    def build_subselect key, o
      stmt             = Nodes::SelectStatement.new
      core             = stmt.cores.first
      core.froms       = o.relation
      core.wheres      = o.wheres
      core.projections = [key]
      stmt.limit       = o.limit
      stmt.orders      = o.orders
      stmt
    end

column_cache(table) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 147
    def column_cache(table)
      @schema_cache.columns_hash(table)
    end

column_for(attr) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 137
    def column_for attr
      return unless attr
      name    = attr.name.to_s
      table   = attr.relation.table_name

      return nil unless table_exists? table

      column_cache(table)[name]
    end

literal(o, a;) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 555
    def literal o, a; o end

Also aliased as: visit_Arel_Nodes_BindParam, visit_Arel_Nodes_SqlLiteral, visit_Arel_SqlLiteral, visit_Bignum, visit_Fixnum
quote(value, column = nil) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 595
    def quote value, column = nil
      return value if Arel::Nodes::SqlLiteral === value
      @connection.quote value, column
    end

quote_column_name(name) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 605
    def quote_column_name name
      @quoted_columns[name] ||= Arel::Nodes::SqlLiteral === name ? name : @connection.quote_column_name(name)
    end

quote_table_name(name) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 600
    def quote_table_name name
      return name if Arel::Nodes::SqlLiteral === name
      @quoted_tables[name] ||= @connection.quote_table_name(name)
    end

quoted(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 563
    def quoted o, a
      quote(o, column_for(a))
    end

Also aliased as: visit_ActiveSupport_Multibyte_Chars, visit_ActiveSupport_StringInquirer, visit_BigDecimal, visit_Class, visit_Date, visit_DateTime, visit_FalseClass, visit_Float, visit_Hash, visit_NilClass, visit_String, visit_Symbol, visit_Time, visit_TrueClass
table_exists?(name) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 133
    def table_exists? name
      @schema_cache.table_exists? name
    end

visit_ActiveSupport_Multibyte_Chars(o, a)
Alias for: quoted
visit_ActiveSupport_StringInquirer(o, a)
Alias for: quoted
visit_Arel_Attributes_Attribute(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 544
    def visit_Arel_Attributes_Attribute o, a
      join_name = o.relation.table_alias || o.relation.name
      "#{quote_table_name join_name}.#{quote_column_name o.name}"
    end

Also aliased as: visit_Arel_Attributes_Integer, visit_Arel_Attributes_Float, visit_Arel_Attributes_Decimal, visit_Arel_Attributes_String, visit_Arel_Attributes_Time, visit_Arel_Attributes_Boolean
visit_Arel_Attributes_Boolean(o, a)
Alias for: visit_Arel_Attributes_Attribute
visit_Arel_Attributes_Decimal(o, a)
Alias for: visit_Arel_Attributes_Attribute
visit_Arel_Attributes_Float(o, a)
Alias for: visit_Arel_Attributes_Attribute
visit_Arel_Attributes_Integer(o, a)
Alias for: visit_Arel_Attributes_Attribute
visit_Arel_Attributes_String(o, a)
Alias for: visit_Arel_Attributes_Attribute
visit_Arel_Attributes_Time(o, a)
Alias for: visit_Arel_Attributes_Attribute
visit_Arel_Nodes_Addition(o, a)
Alias for: visit_Arel_Nodes_InfixOperation
visit_Arel_Nodes_And(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 501
    def visit_Arel_Nodes_And o, a
      o.children.map { |x| visit x, a }.join ' AND '
    end

visit_Arel_Nodes_As(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 536
    def visit_Arel_Nodes_As o, a
      "#{visit o.left, a} AS #{visit o.right, a}"
    end

visit_Arel_Nodes_Ascending(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 356
    def visit_Arel_Nodes_Ascending o, a
      "#{visit o.expr, a} ASC"
    end

visit_Arel_Nodes_Assignment(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 509
    def visit_Arel_Nodes_Assignment o, a
      right = quote(o.right, column_for(o.left))
      "#{visit o.left, a} = #{right}"
    end

visit_Arel_Nodes_Avg(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 399
    def visit_Arel_Nodes_Avg o, a
      "AVG(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
        visit x, a }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
    end

visit_Arel_Nodes_Between(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 408
    def visit_Arel_Nodes_Between o, a
      a = o.left if Arel::Attributes::Attribute === o.left
      "#{visit o.left, a} BETWEEN #{visit o.right, a}"
    end

visit_Arel_Nodes_Bin(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 238
    def visit_Arel_Nodes_Bin o, a
      visit o.expr, a
    end

visit_Arel_Nodes_BindParam(o, a;)
Alias for: literal
visit_Arel_Nodes_Count(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 378
    def visit_Arel_Nodes_Count o, a
      "COUNT(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
        visit x, a
      }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
    end

visit_Arel_Nodes_CurrentRow(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 310
    def visit_Arel_Nodes_CurrentRow o, a
      "CURRENT ROW"
    end

visit_Arel_Nodes_DeleteStatement(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 65
    def visit_Arel_Nodes_DeleteStatement o, a
      [
        "DELETE FROM #{visit o.relation}",
        ("WHERE #{o.wheres.map { |x| visit x }.join AND}" unless o.wheres.empty?)
      ].compact.join ' '
    end

visit_Arel_Nodes_Descending(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 360
    def visit_Arel_Nodes_Descending o, a
      "#{visit o.expr, a} DESC"
    end

visit_Arel_Nodes_Distinct(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 242
    def visit_Arel_Nodes_Distinct o, a
      DISTINCT
    end

visit_Arel_Nodes_DistinctOn(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 246
    def visit_Arel_Nodes_DistinctOn o, a
      raise NotImplementedError, 'DISTINCT ON not implemented for this db'
    end

visit_Arel_Nodes_Division(o, a)
Alias for: visit_Arel_Nodes_InfixOperation
visit_Arel_Nodes_DoesNotMatch(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 438
    def visit_Arel_Nodes_DoesNotMatch o, a
      a = o.left if Arel::Attributes::Attribute === o.left
      "#{visit o.left, a} NOT LIKE #{visit o.right, a}"
    end

visit_Arel_Nodes_Equality(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 514
    def visit_Arel_Nodes_Equality o, a
      right = o.right

      a = o.left if Arel::Attributes::Attribute === o.left
      if right.nil?
        "#{visit o.left, a} IS NULL"
      else
        "#{visit o.left, a} = #{visit right, a}"
      end
    end

visit_Arel_Nodes_Except(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 270
    def visit_Arel_Nodes_Except o, a
      "( #{visit o.left, a} EXCEPT #{visit o.right, a} )"
    end

visit_Arel_Nodes_Exists(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 120
    def visit_Arel_Nodes_Exists o, a
      "EXISTS (#{visit o.expressions, a})#{
        o.alias ? " AS #{visit o.alias, a}" : ''}"
    end

visit_Arel_Nodes_Extract(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 374
    def visit_Arel_Nodes_Extract o, a
      "EXTRACT(#{o.field.to_s.upcase} FROM #{visit o.expr, a})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
    end

visit_Arel_Nodes_False(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 129
    def visit_Arel_Nodes_False o, a
      "FALSE"
    end

visit_Arel_Nodes_Following(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 306
    def visit_Arel_Nodes_Following o, a
      "#{o.expr ? visit(o.expr, a) : 'UNBOUNDED'} FOLLOWING"
    end

visit_Arel_Nodes_GreaterThan(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 418
    def visit_Arel_Nodes_GreaterThan o, a
      a = o.left if Arel::Attributes::Attribute === o.left
      "#{visit o.left, a} > #{visit o.right, a}"
    end

visit_Arel_Nodes_GreaterThanOrEqual(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 413
    def visit_Arel_Nodes_GreaterThanOrEqual o, a
      a = o.left if Arel::Attributes::Attribute === o.left
      "#{visit o.left, a} >= #{visit o.right, a}"
    end

visit_Arel_Nodes_Group(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 364
    def visit_Arel_Nodes_Group o, a
      visit o.expr, a
    end

visit_Arel_Nodes_Grouping(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 348
    def visit_Arel_Nodes_Grouping o, a
      "(#{visit o.expr, a})"
    end

visit_Arel_Nodes_Having(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 327
    def visit_Arel_Nodes_Having o, a
      "HAVING #{visit o.expr, a}"
    end

visit_Arel_Nodes_In(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 483
    def visit_Arel_Nodes_In o, a
      if Array === o.right && o.right.empty?
        '1=0'
      else
        a = o.left if Arel::Attributes::Attribute === o.left
        "#{visit o.left, a} IN (#{visit o.right, a})"
      end
    end

visit_Arel_Nodes_InfixOperation(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 582
    def visit_Arel_Nodes_InfixOperation o, a
      "#{visit o.left, a} #{o.operator} #{visit o.right, a}"
    end

Also aliased as: visit_Arel_Nodes_Addition, visit_Arel_Nodes_Subtraction, visit_Arel_Nodes_Multiplication, visit_Arel_Nodes_Division
visit_Arel_Nodes_InnerJoin(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 458
    def visit_Arel_Nodes_InnerJoin o, a
      s = "INNER JOIN #{visit o.left, a}"
      if o.right
        s << SPACE
        s << visit(o.right, a)
      end
      s
    end

visit_Arel_Nodes_InsertStatement(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 108
    def visit_Arel_Nodes_InsertStatement o, a
      [
        "INSERT INTO #{visit o.relation, a}",

        ("(#{o.columns.map { |x|
        quote_column_name x.name
      }.join ', '})" unless o.columns.empty?),

        (visit o.values, a if o.values),
      ].compact.join ' '
    end

visit_Arel_Nodes_Intersect(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 266
    def visit_Arel_Nodes_Intersect o, a
      "( #{visit o.left, a} INTERSECT #{visit o.right, a} )"
    end

visit_Arel_Nodes_JoinSource(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 443
    def visit_Arel_Nodes_JoinSource o, a
      [
        (visit(o.left, a) if o.left),
        o.right.map { |j| visit j, a }.join(' ')
      ].compact.join ' '
    end

visit_Arel_Nodes_LessThan(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 428
    def visit_Arel_Nodes_LessThan o, a
      a = o.left if Arel::Attributes::Attribute === o.left
      "#{visit o.left, a} < #{visit o.right, a}"
    end

visit_Arel_Nodes_LessThanOrEqual(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 423
    def visit_Arel_Nodes_LessThanOrEqual o, a
      a = o.left if Arel::Attributes::Attribute === o.left
      "#{visit o.left, a} <= #{visit o.right, a}"
    end

visit_Arel_Nodes_Limit(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 335
    def visit_Arel_Nodes_Limit o, a
      "LIMIT #{visit o.expr, a}"
    end

visit_Arel_Nodes_Lock(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 344
    def visit_Arel_Nodes_Lock o, a
      visit o.expr, a
    end

visit_Arel_Nodes_Matches(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 433
    def visit_Arel_Nodes_Matches o, a
      a = o.left if Arel::Attributes::Attribute === o.left
      "#{visit o.left, a} LIKE #{visit o.right, a}"
    end

visit_Arel_Nodes_Max(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 389
    def visit_Arel_Nodes_Max o, a
      "MAX(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
        visit x, a }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
    end

visit_Arel_Nodes_Min(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 394
    def visit_Arel_Nodes_Min o, a
      "MIN(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
        visit x, a }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
    end

visit_Arel_Nodes_Multiplication(o, a)
Alias for: visit_Arel_Nodes_InfixOperation
visit_Arel_Nodes_NamedFunction(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 368
    def visit_Arel_Nodes_NamedFunction o, a
      "#{o.name}(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
        visit x, a
      }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
    end

visit_Arel_Nodes_NamedWindow(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 274
    def visit_Arel_Nodes_NamedWindow o, a
      "#{quote_column_name o.name} AS #{visit_Arel_Nodes_Window o, a}"
    end

visit_Arel_Nodes_Not(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 471
    def visit_Arel_Nodes_Not o, a
      "NOT (#{visit o.expr, a})"
    end

visit_Arel_Nodes_NotEqual(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 525
    def visit_Arel_Nodes_NotEqual o, a
      right = o.right

      a = o.left if Arel::Attributes::Attribute === o.left
      if right.nil?
        "#{visit o.left, a} IS NOT NULL"
      else
        "#{visit o.left, a} != #{visit right, a}"
      end
    end

visit_Arel_Nodes_NotIn(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 492
    def visit_Arel_Nodes_NotIn o, a
      if Array === o.right && o.right.empty?
        '1=1'
      else
        a = o.left if Arel::Attributes::Attribute === o.left
        "#{visit o.left, a} NOT IN (#{visit o.right, a})"
      end
    end

visit_Arel_Nodes_Offset(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 331
    def visit_Arel_Nodes_Offset o, a
      "OFFSET #{visit o.expr, a}"
    end

visit_Arel_Nodes_On(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 467
    def visit_Arel_Nodes_On o, a
      "ON #{visit o.expr, a}"
    end

visit_Arel_Nodes_Or(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 505
    def visit_Arel_Nodes_Or o, a
      "#{visit o.left, a} OR #{visit o.right, a}"
    end

visit_Arel_Nodes_OuterJoin(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 454
    def visit_Arel_Nodes_OuterJoin o, a
      "LEFT OUTER JOIN #{visit o.left, a} #{visit o.right, a}"
    end

visit_Arel_Nodes_Over(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 314
    def visit_Arel_Nodes_Over o, a
      case o.right
        when nil
          "#{visit o.left, a} OVER ()"
        when Arel::Nodes::SqlLiteral
          "#{visit o.left, a} OVER #{visit o.right, a}"
        when String, Symbol
          "#{visit o.left, a} OVER #{quote_column_name o.right.to_s}"
        else
          "#{visit o.left, a} OVER #{visit o.right, a}"
      end
    end

visit_Arel_Nodes_Preceding(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 302
    def visit_Arel_Nodes_Preceding o, a
      "#{o.expr ? visit(o.expr, a) : 'UNBOUNDED'} PRECEDING"
    end

visit_Arel_Nodes_Range(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 294
    def visit_Arel_Nodes_Range o, a
      if o.expr
        "RANGE #{visit o.expr, a}"
      else
        "RANGE"
      end
    end

visit_Arel_Nodes_Rows(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 286
    def visit_Arel_Nodes_Rows o, a
      if o.expr
        "ROWS #{visit o.expr, a}"
      else
        "ROWS"
      end
    end

visit_Arel_Nodes_SelectCore(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 189
    def visit_Arel_Nodes_SelectCore o, a
      str = "SELECT"

      str << " #{visit(o.top, a)}"            if o.top
      str << " #{visit(o.set_quantifier, a)}" if o.set_quantifier

      unless o.projections.empty?
        str << SPACE
        len = o.projections.length - 1
        o.projections.each_with_index do |x, i|
          str << visit(x, a)
          str << COMMA unless len == i
        end
      end

      str << " FROM #{visit(o.source, a)}" if o.source && !o.source.empty?

      unless o.wheres.empty?
        str << WHERE
        len = o.wheres.length - 1
        o.wheres.each_with_index do |x, i|
          str << visit(x, a)
          str << AND unless len == i
        end
      end

      unless o.groups.empty?
        str << GROUP_BY
        len = o.groups.length - 1
        o.groups.each_with_index do |x, i|
          str << visit(x, a)
          str << COMMA unless len == i
        end
      end

      str << " #{visit(o.having, a)}" if o.having

      unless o.windows.empty?
        str << WINDOW
        len = o.windows.length - 1
        o.windows.each_with_index do |x, i|
          str << visit(x, a)
          str << COMMA unless len == i
        end
      end

      str
    end

visit_Arel_Nodes_SelectStatement(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 161
    def visit_Arel_Nodes_SelectStatement o, a
      str = ''

      if o.with
        str << visit(o.with, a)
        str << SPACE
      end

      o.cores.each { |x| str << visit_Arel_Nodes_SelectCore(x, a) }

      unless o.orders.empty?
        str << SPACE
        str << ORDER_BY
        len = o.orders.length - 1
        o.orders.each_with_index { |x, i|
          str << visit(x, a)
          str << COMMA unless len == i
        }
      end

      str << " #{visit(o.limit, a)}" if o.limit
      str << " #{visit(o.offset, a)}" if o.offset
      str << " #{visit(o.lock, a)}" if o.lock

      str.strip!
      str
    end

visit_Arel_Nodes_SqlLiteral(o, a;)
Alias for: literal
visit_Arel_Nodes_StringJoin(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 450
    def visit_Arel_Nodes_StringJoin o, a
      visit o.left, a
    end

visit_Arel_Nodes_Subtraction(o, a)
Alias for: visit_Arel_Nodes_InfixOperation
visit_Arel_Nodes_Sum(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 384
    def visit_Arel_Nodes_Sum o, a
      "SUM(#{o.distinct ? 'DISTINCT ' : ''}#{o.expressions.map { |x|
        visit x, a }.join(', ')})#{o.alias ? " AS #{visit o.alias, a}" : ''}"
    end

visit_Arel_Nodes_TableAlias(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 404
    def visit_Arel_Nodes_TableAlias o, a
      "#{visit o.relation, a} #{quote_table_name o.name}"
    end

visit_Arel_Nodes_Top(o, a) click to toggle source

FIXME: this does nothing on most databases, but does on MSSQL

    # File lib/arel/visitors/to_sql.rb, line 340
    def visit_Arel_Nodes_Top o, a
      ""
    end

visit_Arel_Nodes_True(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 125
    def visit_Arel_Nodes_True o, a
      "TRUE"
    end

visit_Arel_Nodes_Union(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 258
    def visit_Arel_Nodes_Union o, a
      "( #{visit o.left, a} UNION #{visit o.right, a} )"
    end

visit_Arel_Nodes_UnionAll(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 262
    def visit_Arel_Nodes_UnionAll o, a
      "( #{visit o.left, a} UNION ALL #{visit o.right, a} )"
    end

visit_Arel_Nodes_UnqualifiedColumn(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 540
    def visit_Arel_Nodes_UnqualifiedColumn o, a
      "#{quote_column_name o.name}"
    end

visit_Arel_Nodes_UpdateStatement(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 84
          def visit_Arel_Nodes_UpdateStatement o, a
            if o.orders.empty? && o.limit.nil?
              wheres = o.wheres
            else
              key = o.key
              unless key
                warn("(#{caller.first}) Using UpdateManager without setting UpdateManager#key is
    deprecated and support will be removed in Arel 4.0.0.  Please set the primary
    key on UpdateManager using UpdateManager#key= '#{key.inspect}'
    ") if $VERBOSE
                key = o.relation.primary_key
              end

              wheres = [Nodes::In.new(key, [build_subselect(key, o)])]
            end

            [
              "UPDATE #{visit o.relation, a}",
              ("SET #{o.values.map { |value| visit value, a }.join ', '}" unless o.values.empty?),
              ("WHERE #{wheres.map { |x| visit x, a }.join ' AND '}" unless wheres.empty?),
            ].compact.join ' '
          end

visit_Arel_Nodes_Values(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 151
    def visit_Arel_Nodes_Values o, a
      "VALUES (#{o.expressions.zip(o.columns).map { |value, attr|
        if Nodes::SqlLiteral === value
          visit value, a
        else
          quote(value, attr && column_for(attr))
        end
      }.join ', '})"
    end

visit_Arel_Nodes_Window(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 278
    def visit_Arel_Nodes_Window o, a
      s = [
        ("ORDER BY #{o.orders.map { |x| visit(x, a) }.join(', ')}" unless o.orders.empty?),
        (visit o.framing, a if o.framing)
      ].compact.join ' '
      "(#{s})"
    end

visit_Arel_Nodes_With(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 250
    def visit_Arel_Nodes_With o, a
      "WITH #{o.children.map { |x| visit x, a }.join(', ')}"
    end

visit_Arel_Nodes_WithRecursive(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 254
    def visit_Arel_Nodes_WithRecursive o, a
      "WITH RECURSIVE #{o.children.map { |x| visit x, a }.join(', ')}"
    end

visit_Arel_SelectManager(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 352
    def visit_Arel_SelectManager o, a
      "(#{o.to_sql.rstrip})"
    end

visit_Arel_SqlLiteral(o, a;)
Alias for: literal
visit_Arel_Table(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 475
    def visit_Arel_Table o, a
      if o.table_alias
        "#{quote_table_name o.name} #{quote_table_name o.table_alias}"
      else
        quote_table_name o.name
      end
    end

visit_Array(o, a) click to toggle source

    # File lib/arel/visitors/to_sql.rb, line 591
    def visit_Array o, a
      o.map { |x| visit x, a }.join(', ')
    end

visit_BigDecimal(o, a)
Alias for: quoted
visit_Bignum(o, a;)
Alias for: literal
visit_Class(o, a)
Alias for: quoted
visit_Date(o, a)
Alias for: quoted
visit_DateTime(o, a)
Alias for: quoted
visit_FalseClass(o, a)
Alias for: quoted
visit_Fixnum(o, a;)
Alias for: literal
visit_Float(o, a)
Alias for: quoted
visit_Hash(o, a)
Alias for: quoted
visit_NilClass(o, a)
Alias for: quoted
visit_String(o, a)
Alias for: quoted
visit_Symbol(o, a)
Alias for: quoted
visit_Time(o, a)
Alias for: quoted
visit_TrueClass(o, a)
Alias for: quoted