2014-03-11 22:55:32 +01:00
|
|
|
module RDBMSFunctions
|
|
|
|
def rdbms_date_add(source, unit, amount)
|
2014-04-18 23:55:15 +02:00
|
|
|
adapter_type = ActiveRecord::Base.connection.adapter_name.downcase.to_sym
|
2014-03-11 22:55:32 +01:00
|
|
|
case adapter_type
|
2014-03-13 23:50:46 +01:00
|
|
|
when :mysql, :mysql2
|
2014-03-11 23:05:10 +01:00
|
|
|
"DATE_ADD(`#{source}`, INTERVAL #{amount} #{unit})"
|
2014-04-18 23:55:15 +02:00
|
|
|
when :postgresql
|
2014-03-11 22:55:32 +01:00
|
|
|
"(#{source} + INTERVAL '#{amount} #{unit}')"
|
|
|
|
else
|
|
|
|
raise NotImplementedError, "Unknown adapter type '#{adapter_type}'"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|