module ActiveBookings::DBUtils
Public Class Methods
active_record4?()
click to toggle source
# File lib/active_bookings/db_utils.rb, line 21 def active_record4? ::ActiveRecord::VERSION::MAJOR == 4 end
active_record5?()
click to toggle source
# File lib/active_bookings/db_utils.rb, line 25 def active_record5? ::ActiveRecord::VERSION::MAJOR == 5 end
connection()
click to toggle source
# File lib/active_bookings/db_utils.rb, line 4 def connection ActiveBookings::Booking.connection end
escape_like(str)
click to toggle source
escape _ and % characters in strings, since these are wildcards in SQL.
# File lib/active_bookings/db_utils.rb, line 45 def escape_like(str) str.gsub(/[!%_]/) { |x| '!' + x } end
like_operator()
click to toggle source
# File lib/active_bookings/db_utils.rb, line 29 def like_operator using_postgresql? ? 'ILIKE' : 'LIKE' end
time_comparison(query, field, operator, time)
click to toggle source
Compare times according to the DB
# File lib/active_bookings/db_utils.rb, line 34 def time_comparison(query, field, operator, time) if using_postgresql? query.where("#{field}::timestamp #{operator} ?::timestamp", time.to_time.utc.to_s) elsif using_sqlite? query.where("Datetime(#{field}) #{operator} Datetime('#{time.to_time.utc.iso8601}')") else query.where("#{field} #{operator} ?", time.to_time) end end
using_mysql?()
click to toggle source
# File lib/active_bookings/db_utils.rb, line 12 def using_mysql? #We should probably use regex for mysql to support prehistoric adapters connection && connection.adapter_name == 'Mysql2' end
using_postgresql?()
click to toggle source
# File lib/active_bookings/db_utils.rb, line 8 def using_postgresql? connection && connection.adapter_name == 'PostgreSQL' end
using_sqlite?()
click to toggle source
# File lib/active_bookings/db_utils.rb, line 17 def using_sqlite? connection && connection.adapter_name == 'SQLite' end