Sha256: d5bfd1adbc16ace101af047282c563e4b370104cf7e84274ee67ce3881b88c7f
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
module Gizzard module Mysql extend ActiveSupport::Concern included do scope :filtered_by, -> (column, value) do v = value.respond_to?(:strip) ? value.strip : value v.present? ? where(column => value) : all end scope :forward_matching_by, -> (column, value) { where("`#{table_name}`.`#{column}` LIKE ?", "#{sanitize_sql_like(value)}%") } scope :backward_matching_by, -> (column, value) { where("`#{table_name}`.`#{column}` LIKE ?", "%#{sanitize_sql_like(value)}") } scope :partial_matching_by, -> (column, value) { where("`#{table_name}`.`#{column}` LIKE ?", "%#{sanitize_sql_like(value)}%") } end class_methods do def order_by_field(column, values) values.present? ? order(Arel.sql("field(`#{table_name}`.`#{column}`, #{values.join(',')})")) : all end def order_by_id_field(ids) order_by_field(:id, ids) end def force_index(indexes) from("#{table_name} USE INDEX(#{Array(indexes).join(', ')})") end def lock_in_share lock('LOCK IN SHARE MODE') end end def to_id id end def lock_in_share! lock!('LOCK IN SHARE MODE') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gizzard-0.2.0 | lib/gizzard/mysql.rb |