class SQB::Delete

Public Instance Methods

to_sql() click to toggle source
# File lib/sqb/delete.rb, line 13
def to_sql
  [].tap do |query|
    query << "DELETE FROM"
    query << escape_and_join(@options[:database_name], @table_name)

    if @where && !@where.empty?
      query << "WHERE"
      query << @where.join(' AND ')
    end

    if @orders && !@orders.empty?
      query << "ORDER BY"
      query << @orders.join(', ')
    end

    if @limit
      query << "LIMIT #{@limit.to_i}"
    end
  end.join(' ')
end