Class: Rooq::DSL::UpdateQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/rooq/dsl/update_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ UpdateQuery

Returns a new instance of UpdateQuery.



8
9
10
11
12
13
# File 'lib/rooq/dsl/update_query.rb', line 8

def initialize(table)
  @table = table
  @set_values = {}
  @conditions = nil
  @returning_fields = []
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



6
7
8
# File 'lib/rooq/dsl/update_query.rb', line 6

def conditions
  @conditions
end

#returning_fieldsObject (readonly)

Returns the value of attribute returning_fields.



6
7
8
# File 'lib/rooq/dsl/update_query.rb', line 6

def returning_fields
  @returning_fields
end

#set_valuesObject (readonly)

Returns the value of attribute set_values.



6
7
8
# File 'lib/rooq/dsl/update_query.rb', line 6

def set_values
  @set_values
end

#tableObject (readonly)

Returns the value of attribute table.



6
7
8
# File 'lib/rooq/dsl/update_query.rb', line 6

def table
  @table
end

Instance Method Details

#returning(*fields) ⇒ Object



24
25
26
# File 'lib/rooq/dsl/update_query.rb', line 24

def returning(*fields)
  dup_with(returning_fields: fields.flatten)
end

#set(field, value) ⇒ Object



15
16
17
18
# File 'lib/rooq/dsl/update_query.rb', line 15

def set(field, value)
  new_set_values = @set_values.merge(field => value)
  dup_with(set_values: new_set_values)
end

#to_sql(dialect = Rooq::Dialect::PostgreSQL.new) ⇒ Object



28
29
30
# File 'lib/rooq/dsl/update_query.rb', line 28

def to_sql(dialect = Rooq::Dialect::PostgreSQL.new)
  dialect.render_update(self)
end

#where(condition) ⇒ Object



20
21
22
# File 'lib/rooq/dsl/update_query.rb', line 20

def where(condition)
  dup_with(conditions: condition)
end