Sha256: f98bd713d962ff26f6519fd3aa3da818e2c3c2a7d4366aaa424b608e3564b631

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

module DataMapper
  module Adapters
    class DataObjectsAdapter
      def adjust(attributes, query)
        statement = adjust_statement(attributes.keys, query)
        bind_values = attributes.values + query.bind_values
        execute(statement, *bind_values)
      end

      module SQL
        private

        def adjust_statement(properties, query)
          repository = query.repository

          statement = "UPDATE #{quote_table_name(query.model.storage_name(repository.name))}"
          statement << " SET #{set_adjustment_statement(repository, properties)}"
          statement << " WHERE #{conditions_statement(query)}" if query.conditions.any?
          statement
        rescue => e
           DataMapper.logger.error("QUERY INVALID: #{query.inspect} (#{e})")
           raise e
        end

        def set_adjustment_statement(repository, properties)
          properties.map { |p| [quote_column_name(p.field(repository.name))] * 2 * " = " + " + (?)" } * ", "
        end

      end # module SQL

      include SQL
    end # class DataObjectsAdapter
  end # module Adapters
end # module DataMapper

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dm-adjust-0.9.11 lib/dm-adjust/adapters/data_objects_adapter.rb
dm-adjust-0.9.4 lib/dm-adjust/adapters/data_objects_adapter.rb
dm-adjust-0.9.6 lib/dm-adjust/adapters/data_objects_adapter.rb
dm-adjust-0.9.10 lib/dm-adjust/adapters/data_objects_adapter.rb
dm-adjust-0.9.2 lib/dm-adjust/adapters/data_objects_adapter.rb
dm-adjust-0.9.3 lib/dm-adjust/adapters/data_objects_adapter.rb
dm-adjust-0.9.5 lib/dm-adjust/adapters/data_objects_adapter.rb
dm-adjust-0.9.7 lib/dm-adjust/adapters/data_objects_adapter.rb
dm-adjust-0.9.8 lib/dm-adjust/adapters/data_objects_adapter.rb
dm-adjust-0.9.9 lib/dm-adjust/adapters/data_objects_adapter.rb