Sha256: d89cb9551cf81499be7ad9214a65ef6b5d4ed243c83abbe241851a981462e517

Contents?: true

Size: 625 Bytes

Versions: 2

Compression:

Stored size: 625 Bytes

Contents

module Sequel::Plugins::LuxArrays
  module ClassMethods
  end

  module DatasetMethods
    # def tagged_with(tag=nil, field=:tags)
    #   return self unless tag
    #   where("? = any (#{field})", tag)
    # end

    # 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
  end

end

Sequel::Model.plugin :lux_arrays

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lux-fw-0.1.35 ./lib/plugins/db_helpers/arrays_and_tags.rb
lux-fw-0.1.17 ./lib/plugins/db_helpers/arrays_and_tags.rb