cantino/huginn

View on GitHub
lib/rdbms_functions.rb

Summary

Maintainability
A
0 mins
Test Coverage
module RdbmsFunctions
  def rdbms_date_add(source, unit, amount)
    adapter_type = ActiveRecord::Base.connection.adapter_name.downcase.to_sym
    case adapter_type
      when :mysql, :mysql2
        "DATE_ADD(`#{source}`, INTERVAL #{amount} #{unit})"
      when :postgresql
        "(#{source} + INTERVAL '#{amount} #{unit}')"
      else
        raise NotImplementedError, "Unknown adapter type '#{adapter_type}'"
    end
  end
end