Class: Riddle::Query::Delete

Inherits:
Object
  • Object
show all
Defined in:
lib/riddle/query/delete.rb

Instance Method Summary collapse

Constructor Details

#initialize(index, *ids) ⇒ Delete

Returns a new instance of Delete.



4
5
6
7
# File 'lib/riddle/query/delete.rb', line 4

def initialize(index, *ids)
  @index = index
  @ids   = ids.flatten
end

Instance Method Details

#to_sqlObject



9
10
11
12
13
14
15
# File 'lib/riddle/query/delete.rb', line 9

def to_sql
  if @ids.length > 1
    "DELETE FROM #{@index} WHERE id IN (#{@ids.join(', ')})"
  else
    "DELETE FROM #{@index} WHERE id = #{@ids.first}"
  end
end