Class: SQB::Delete

Inherits:
Base
  • Object
show all
Includes:
Filtering, Limiting, Ordering
Defined in:
lib/sqb/delete.rb

Constant Summary

Constants included from Ordering

Ordering::VALID_ORDERS

Instance Attribute Summary

Attributes inherited from Base

#options, #prepared_arguments

Instance Method Summary collapse

Methods included from Limiting

#limit

Methods included from Ordering

#no_order!, #order, #order!

Methods included from Filtering

#or, #where

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SQB::Base

Instance Method Details

#to_sqlObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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