I am trying to make a LIKE
query work in my SQLite in development and PostgreSQL in production (Heroku) without using an if-else statement for either environment. If-else statement doesn't seem like a viable option.
My answer right now was based off the solution provided here: Generic Ruby solution for SQLite3 "LIKE" or PostgreSQL "ILIKE"?
This is what my course model looks like:
class Course < ApplicationRecord
has_many :enrollments
has_many :users, through: :enrollments
has_many :course_subjects
has_many :subjects, through: :course_subjects
def self.search(search)
where("lower(name) LIKE lower(?)", "%#{search}%")
end
end
How can I structure my LIKE query to be compatible with both SQLite and PostgreSQL?