activerecord_save_many 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/activerecord_save_many.rb +4 -3
- data/spec/activerecord_save_many_spec.rb +1 -1
- metadata +1 -1
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.5.0
|
|
@@ -87,7 +87,8 @@ module ActiveRecord
|
|
|
87
87
|
columns.map{|col| obj[col]}
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
sql = connection.save_many_sql(
|
|
90
|
+
sql = connection.save_many_sql(self,
|
|
91
|
+
table_name,
|
|
91
92
|
columns,
|
|
92
93
|
rows,
|
|
93
94
|
{ :ignore=>options[:ignore],
|
|
@@ -101,12 +102,12 @@ module ActiveRecord
|
|
|
101
102
|
end
|
|
102
103
|
|
|
103
104
|
module MySQL
|
|
104
|
-
def save_many_sql(table_name, columns, rows, options)
|
|
105
|
+
def save_many_sql(klass, table_name, columns, rows, options)
|
|
105
106
|
Functions::check_options(SQL_OPTIONS_KEYS, options)
|
|
106
107
|
|
|
107
108
|
sql = ["insert", ("delayed" if options[:async]), ("ignore" if options[:ignore])].compact.join(' ') +
|
|
108
109
|
" into #{table_name} (#{columns.join(',')}) values " +
|
|
109
|
-
rows.map{|vals| "(" + vals.map{|v| quote_value(v)}.join(",") +")"}.join(",") +
|
|
110
|
+
rows.map{|vals| "(" + vals.map{|v| klass.quote_value(v)}.join(",") +")"}.join(",") +
|
|
110
111
|
(" on duplicate key update "+columns.map{|c| options[:updates][c] || "#{c}=values(#{c})"}.join(",") if options[:update]).to_s
|
|
111
112
|
end
|
|
112
113
|
end
|
|
@@ -106,8 +106,8 @@ module ActiveRecord
|
|
|
106
106
|
stub(k).table_name{tablename}
|
|
107
107
|
cns = column_names.map{|cn| col=Object.new ; stub(col).name{cn} ; col}
|
|
108
108
|
stub(k).columns{cns}
|
|
109
|
+
stub(k).quote_value{|v| "'#{v}'"}
|
|
109
110
|
connection = ActiveRecord::ConnectionAdapters::MysqlAdapter.new
|
|
110
|
-
stub(connection).quote_value{|v| "'#{v}'"}
|
|
111
111
|
stub(connection).execute_raw{|sql|
|
|
112
112
|
sql.should == match_sql
|
|
113
113
|
}
|