Sha256: c2f25dd9182007ce763ab7fb8d64ac89b3f686eb4c3bddadbfacb1cb592398ed

Contents?: true

Size: 601 Bytes

Versions: 1

Compression:

Stored size: 601 Bytes

Contents

module DataMapper
  module Queries
    
    class UpdateStatement
      
      def initialize(database, instance)
        @database, @instance = database, instance
      end
      
      def to_sql
        table = @database[@instance.class]
        
        sql = "UPDATE " << table.to_sql << " SET "
        
        @instance.dirty_attributes.map do |k, v|
          sql << table[k].to_sql << " = " << @database.quote_value(v) << ", "
        end
        
        sql[0, sql.size - 2] << " WHERE #{table.key.to_sql} = " << @database.quote_value(@instance.key)
      end
      
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datamapper-0.1.0 lib/data_mapper/queries/update_statement.rb