Sha256: d3c495a84263edb07c89a1bc88f458c6e30273d13383f3bc076383e9da04ae7d
Contents?: true
Size: 1.44 KB
Versions: 2
Compression:
Stored size: 1.44 KB
Contents
module DataMapper module Adapters class DataObjectsAdapter < AbstractAdapter def adjust(attributes, query) # TODO: if the query contains any links, a limit or an offset # use a subselect to get the rows to be updated properties = [] bind_values = [] # make the order of the properties consistent query.model.properties(name).each do |property| next unless attributes.key?(property) properties << property bind_values << attributes[property] end statement, conditions_bind_values = adjust_statement(properties, query) bind_values.concat(conditions_bind_values) execute(statement, *bind_values) end module SQL private def adjust_statement(properties, query) conditions_statement, bind_values = conditions_statement(query.conditions) statement = "UPDATE #{quote_name(query.model.storage_name(name))}" statement << " SET #{set_adjustment_statement(properties)}" statement << " WHERE #{conditions_statement}" unless conditions_statement.blank? return statement, bind_values end def set_adjustment_statement(properties) properties.map { |p| "#{quote_name(p.field)} = #{quote_name(p.field)} + ?" }.join(', ') end end # module SQL include SQL end # class DataObjectsAdapter end # module Adapters end # module DataMapper
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dm-adjust-0.10.1 | lib/dm-adjust/adapters/data_objects_adapter.rb |
dm-adjust-0.10.0 | lib/dm-adjust/adapters/data_objects_adapter.rb |