Sha256: 37a150ae555aeaca376bc79cbe21797031ab341cde553ee267acc3e6596f402f
Contents?: true
Size: 829 Bytes
Versions: 1
Compression:
Stored size: 829 Bytes
Contents
module DataMapper module Queries class InsertStatement def initialize(database, instance) @database, @instance = database, instance end # The only thing this method is responsible for is generating the insert statement. # It is the database adapters responsibility to get the last inserted id def to_sql table = @database[@instance.class] keys = [] values = [] @instance.dirty_attributes.each_pair { |k,v| keys << table[k].to_sql; values << v } # Formatting is a bit off here, but it looks nicer in the log this way. sql = "INSERT INTO #{table.to_sql} (#{keys.join(', ')}) \ VALUES (#{values.map { |v| @database.quote_value(v) }.join(', ')})" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
datamapper-0.1.0 | lib/data_mapper/queries/insert_statement.rb |