Method: Dynamoid::Indexes::ClassMethods#global_secondary_index
- Defined in:
- lib/dynamoid/indexes.rb
#global_secondary_index(options = {}) ⇒ Object
Defines a Global Secondary index on a table. Keys can be specified as hash-only, or hash & range.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dynamoid/indexes.rb', line 32 def global_secondary_index( = {}) unless .present? raise Dynamoid::Errors::InvalidIndex, 'empty index definition' end unless [:hash_key].present? raise Dynamoid::Errors::InvalidIndex, 'A global secondary index requires a :hash_key to be specified' end index_opts = { read_capacity: Dynamoid::Config.read_capacity, write_capacity: Dynamoid::Config.write_capacity }.merge() index_opts[:dynamoid_class] = self index_opts[:type] = :global_secondary index = Dynamoid::Indexes::Index.new(index_opts) gsi_key = index_key([:hash_key], [:range_key]) global_secondary_indexes[gsi_key] = index self end |