rdbms_functions.rb 433 B

12345678910111213
  1. module RDBMSFunctions
  2. def rdbms_date_add(source, unit, amount)
  3. adapter_type = ActiveRecord::Base.connection.adapter_name.downcase.to_sym
  4. case adapter_type
  5. when :mysql, :mysql2
  6. "DATE_ADD(`#{source}`, INTERVAL #{amount} #{unit})"
  7. when :postgresql
  8. "(#{source} + INTERVAL '#{amount} #{unit}')"
  9. else
  10. raise NotImplementedError, "Unknown adapter type '#{adapter_type}'"
  11. end
  12. end
  13. end