huginn/lib/rdbms_functions.rb

14 lines
433 B
Ruby
Raw Normal View History

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
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
"(#{source} + INTERVAL '#{amount} #{unit}')"
else
raise NotImplementedError, "Unknown adapter type '#{adapter_type}'"
end
end
end