Class: DB::Model::Statement::Update

Inherits:
Object
  • Object
show all
Defined in:
lib/db/model/statement/update.rb

Instance Method Summary collapse

Constructor Details

#initialize(source, assignment, where) ⇒ Update

Returns a new instance of Update.



10
11
12
13
14
# File 'lib/db/model/statement/update.rb', line 10

def initialize(source, assignment, where)
  @source = source
  @assignment = assignment
  @where = where
end

Instance Method Details

#call(context) ⇒ Object



31
32
33
# File 'lib/db/model/statement/update.rb', line 31

def call(context)
  to_sql(context).call
end

#to_sql(context) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/db/model/statement/update.rb', line 16

def to_sql(context)
  statement = context.query("UPDATE")
  
  statement.identifier(@source.type)
  
  @assignment.append_to(statement)
  
  if @where
    statement.clause "WHERE"
    @where.append_to(statement)
  end
  
  return statement
end