Class: Arel::UpdateManager
- Inherits:
-
TreeManager
- Object
- TreeManager
- Arel::UpdateManager
- Includes:
- TreeManager::StatementMethods
- Defined in:
- lib/arel/update_manager.rb
Instance Attribute Summary
Attributes inherited from TreeManager
Instance Method Summary collapse
- #group(columns) ⇒ Object
- #having(expr) ⇒ Object
-
#initialize(table = nil) ⇒ UpdateManager
constructor
A new instance of UpdateManager.
- #set(values) ⇒ Object
-
#table(table) ⇒ Object
UPDATE
table
.
Methods included from TreeManager::StatementMethods
#key, #key=, #offset, #order, #take, #where, #wheres=
Methods inherited from TreeManager
#initialize_copy, #to_dot, #to_sql
Methods included from FactoryMethods
#cast, #coalesce, #create_and, #create_false, #create_join, #create_on, #create_string_join, #create_table_alias, #create_true, #grouping, #lower
Constructor Details
#initialize(table = nil) ⇒ UpdateManager
Returns a new instance of UpdateManager.
7 8 9 |
# File 'lib/arel/update_manager.rb', line 7 def initialize(table = nil) @ast = Nodes::UpdateStatement.new(table) end |
Instance Method Details
#group(columns) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/arel/update_manager.rb', line 33 def group(columns) columns.each do |column| column = Nodes::SqlLiteral.new(column) if String === column column = Nodes::SqlLiteral.new(column.to_s) if Symbol === column @ast.groups.push Nodes::Group.new column end self end |
#having(expr) ⇒ Object
44 45 46 47 |
# File 'lib/arel/update_manager.rb', line 44 def having(expr) @ast.havings << expr self end |
#set(values) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/arel/update_manager.rb', line 18 def set(values) case values when String, Nodes::BoundSqlLiteral @ast.values = [values] else @ast.values = values.map { |column, value| Nodes::Assignment.new( Nodes::UnqualifiedColumn.new(column), value ) } end self end |
#table(table) ⇒ Object
UPDATE table
13 14 15 16 |
# File 'lib/arel/update_manager.rb', line 13 def table(table) @ast.relation = table self end |