Class: Json2sql::UpdateModel
- Inherits:
-
Object
- Object
- Json2sql::UpdateModel
- Defined in:
- lib/json2sql/update_model.rb
Overview
Builds an UPDATE statement for a single table.
Input Hash:
"columns" => { "col" => value, ... } – columns to SET
"and" => { ... } – WHERE conditions
"or" => { ... } – WHERE conditions (OR)
Value types follow the same rules as InsertModel.
Instance Method Summary collapse
- #build(params) ⇒ Object
-
#initialize(sql, table, relation) ⇒ UpdateModel
constructor
A new instance of UpdateModel.
Constructor Details
#initialize(sql, table, relation) ⇒ UpdateModel
Returns a new instance of UpdateModel.
14 15 16 17 18 19 20 21 |
# File 'lib/json2sql/update_model.rb', line 14 def initialize(sql, table, relation) @sql = sql @table = table.to_s @relation = relation end |
Instance Method Details
#build(params) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/json2sql/update_model.rb', line 23 def build(params) @sql << "UPDATE " @sql << Sanitizer.keyword_wrap(@table) @sql << " SET " build_columns(params) WhereModel.new(@sql, @table, @relation).build(params) end |