Method: Sequel::Dataset#ordered_expression_sql_append

Defined in:
lib/sequel/dataset/sql.rb

#ordered_expression_sql_append(sql, oe) ⇒ Object

Append literalization of ordered expression to SQL string.



604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/sequel/dataset/sql.rb', line 604

def ordered_expression_sql_append(sql, oe)
  if emulate = requires_emulating_nulls_first?
    case oe.nulls
    when :first
      null_order = 0
    when :last
      null_order = 2
    end

    if null_order
      literal_append(sql, Sequel.case({{oe.expression=>nil}=>null_order}, 1))
      sql << ", "
    end
  end

  literal_append(sql, oe.expression)
  sql << (oe.descending ? ' DESC' : ' ASC')

  unless emulate
    case oe.nulls
    when :first
      sql << " NULLS FIRST"
    when :last
      sql << " NULLS LAST"
    end
  end
end