Class: Json2sql::DeleteModel

Inherits:
Object
  • Object
show all
Defined in:
lib/json2sql/delete_model.rb

Overview

Builds a DELETE FROM statement for a single table.

Input Hash:

"and" => { ... }   – WHERE conditions (required to avoid deleting all rows)
"or"  => { ... }   – WHERE conditions (OR)

Instance Method Summary collapse

Constructor Details

#initialize(sql, table, relation) ⇒ DeleteModel

Returns a new instance of DeleteModel.



11
12
13
14
15
16
17
18
# File 'lib/json2sql/delete_model.rb', line 11

def initialize(sql, table, relation)

  @sql = sql

  @table = table.to_s

  @relation = relation
end

Instance Method Details

#build(params) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/json2sql/delete_model.rb', line 20

def build(params)

  @sql << "DELETE FROM "

  @sql << Sanitizer.keyword_wrap(@table)

  WhereModel.new(@sql, @table, @relation).build(params)
end