Sha256: 6630e3dca29e034c0584cf9b4b90c9be2522793b3995189087ba89fa4976865c

Contents?: true

Size: 875 Bytes

Versions: 6

Compression:

Stored size: 875 Bytes

Contents

Sequel::Model.dataset_module do
  # only postgree
  # Bucket.can.all_tags -> can_tags mora biti zadnji
  def all_tags field=:tags, *args
    sqlq = sql.split(' FROM ')[1]
    sqlq = "select lower(unnest(#{field})) as tag FROM " + sqlq
    sqlq = "select tag as name, count(tag) as cnt from (#{sqlq}) as tags group by tag order by cnt desc"
    DB.fetch(sqlq).map(&:h).or([])
  end

  # were users.id in (select unnest(user_ids) from doors)
  # def where_unnested klass
  #   target_table = klass.to_s.tableize
  #   where("#{table_name}.id in (select unnest(#{table_name.singularize}_ids) from #{target_table})")
  # end
  # assumes field name is tags
  def where_any data, field
    return self unless data.present?

    if data.is_a?(Array)
      xwhere data.map { |v| "#{v}=any(#{field})" }.join(' or ')
    else
      xwhere('?=any(%s)' % field, data)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lux-fw-0.5.37 ./plugins/db/helpers/array_search.rb
lux-fw-0.5.36 ./plugins/db/helpers/array_search.rb
lux-fw-0.5.35 ./plugins/db/helpers/array_search.rb
lux-fw-0.5.34 ./plugins/db/helpers/array_search.rb
lux-fw-0.5.33 ./plugins/db/helpers/array_search.rb
lux-fw-0.5.32 ./plugins/db/helpers/array_search.rb