Class: Dynamoid::AdapterPlugin::AwsSdkV2::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/adapter_plugin/aws_sdk_v2.rb

Overview

Represents a table. Exposes data from the “DescribeTable” API call, and also provides methods for coercing values to the proper types based on the table’s schema data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Table

Returns a new instance of Table.

Parameters:

  • schema (Hash)

    Data returns from a “DescribeTable” call



905
906
907
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 905

def initialize(schema)
  @schema = schema[:table]
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



900
901
902
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 900

def schema
  @schema
end

Instance Method Details

#col_type(col) ⇒ Object

Returns the API type (e.g. “N”, “S”) for the given column, if the schema defines it, nil otherwise



927
928
929
930
931
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 927

def col_type(col)
  col = col.to_s
  col_def = schema[:attribute_definitions].find { |d| d[:attribute_name] == col.to_s }
  col_def && col_def[:attribute_type]
end

#hash_keyObject



919
920
921
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 919

def hash_key
  @hash_key ||= schema[:key_schema].find { |d| d[:key_type] == HASH_KEY  }.try(:attribute_name).to_sym
end

#item_countObject



933
934
935
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 933

def item_count
  schema[:item_count]
end

#range_keyObject



909
910
911
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 909

def range_key
  @range_key ||= schema[:key_schema].find { |d| d[:key_type] == RANGE_KEY }.try(:attribute_name)
end

#range_typeObject



913
914
915
916
917
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v2.rb', line 913

def range_type
  range_type ||= schema[:attribute_definitions].find { |d|
    d[:attribute_name] == range_key
  }.try(:fetch,:attribute_type, nil)
end