Sha256: e6156fb806d19aef3f488f8eb9cfb19ada633220904a04e35afad980cc29506f

Contents?: true

Size: 756 Bytes

Versions: 4

Compression:

Stored size: 756 Bytes

Contents

class Dynomite::Item
  module Indexes
    def index_names
      indexes.map(&:index_name)
    end

    # Sorted by indexes with composite keys with partition and sort keys first
    # so they take priority for Indexes::Finder#find
    def indexes
      lsi = local_secondary_indexes.map { |i| Index.new(i) }.sort_by { |i| i.fields.size * -1 }
      gsi = global_secondary_indexes.map { |i| Index.new(i) }.sort_by { |i| i.fields.size * -1 }
      lsi + gsi
    end

    def local_secondary_indexes
      table = desc_table(table_name)
      table.local_secondary_indexes.to_a
    end

    def global_secondary_indexes
      table = desc_table(table_name)
      table.global_secondary_indexes.to_a.select { |i| i.index_status == "ACTIVE" }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dynomite-2.0.3 lib/dynomite/item/indexes.rb
dynomite-2.0.2 lib/dynomite/item/indexes.rb
dynomite-2.0.1 lib/dynomite/item/indexes.rb
dynomite-2.0.0 lib/dynomite/item/indexes.rb