Class: AWS::DynamoDB::Item
- Inherits:
-
Core::Resource
- Object
- Core::Resource
- AWS::DynamoDB::Item
- Extended by:
- Types
- Includes:
- Expectations, Keys
- Defined in:
- lib/aws/dynamo_db/item.rb
Overview
Represents a DynamoDB item. An item is identified by simple or complex primary key (according to the table schema) and consists of a collection of attributes. Attributes are name/value pairs where the value may be a string, number, string set, or number set.
Getting an item by hash key value:
item = table.items['hash-key-value']
Getting an item from a table with both hash and range keys:
item = table.items['hash-key','range-key']
Instance Attribute Summary collapse
-
#hash_value ⇒ String, Numeric
readonly
The hash key value of the item.
-
#range_value ⇒ String, ...
readonly
The range key value of the item, or
nil
if the table has a simple primary key. -
#table ⇒ Table
readonly
The table in which the item is stored.
Attributes included from Core::Model
Class Method Summary collapse
Instance Method Summary collapse
-
#attributes ⇒ AttributeCollection
An object representing the attributes of the item.
-
#delete(options = {}) ⇒ Object
Deletes the item.
-
#exists?(options = {}) ⇒ Boolean
True if the item exists.
-
#initialize(table, *args) ⇒ Item
constructor
A new instance of Item.
Methods included from Types
format_attribute_value, value_from_response, values_from_response_hash
Methods included from Keys
#item_key_hash, #item_key_options
Methods inherited from Core::Resource
attribute_providers, attribute_providers_for, attributes, #attributes_from_response, define_attribute_type, #eql?, #inspect
Methods included from Core::Cacheable
Methods included from Core::Model
#client, #config_prefix, #inspect
Constructor Details
#initialize(table, *args) ⇒ Item
Returns a new instance of Item.
48 49 50 51 52 53 |
# File 'lib/aws/dynamo_db/item.rb', line 48 def initialize(table, *args) opts = args.pop if args.last.kind_of?(Hash) (@hash_value, @range_value) = args @table = table super(table, opts) end |
Instance Attribute Details
#hash_value ⇒ String, Numeric (readonly)
Returns The hash key value of the item.
41 42 43 |
# File 'lib/aws/dynamo_db/item.rb', line 41 def hash_value @hash_value end |
#range_value ⇒ String, ... (readonly)
Returns The range key value of the item, or nil
if the table has a simple primary key.
45 46 47 |
# File 'lib/aws/dynamo_db/item.rb', line 45 def range_value @range_value end |
#table ⇒ Table (readonly)
Returns The table in which the item is stored.
38 39 40 |
# File 'lib/aws/dynamo_db/item.rb', line 38 def table @table end |
Class Method Details
.new_from(op, response_object, table, *args) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/aws/dynamo_db/item.rb', line 104 def self.new_from(op, response_object, table, *args) table.assert_schema! hash_value = value_from_response(response_object[table.hash_key.name]) range_value = value_from_response(response_object[table.range_key.name]) if table.range_key raise "missing hash key value in put_item response" unless hash_value raise "missing range key value in put_item response" unless range_value || !table.range_key super(op, response_object, table, hash_value, range_value, *args) end |
Instance Method Details
#attributes ⇒ AttributeCollection
Returns An object representing the attributes of the item.
99 100 101 |
# File 'lib/aws/dynamo_db/item.rb', line 99 def attributes AttributeCollection.new(self) end |
#delete(options = {}) ⇒ Object
Deletes the item.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/aws/dynamo_db/item.rb', line 74 def delete( = {}) client_opts = (self) expected = expect_conditions() client_opts[:expected] = expected unless expected.empty? client_opts[:return_values] = [:return].to_s.upcase if [:return] resp = client.delete_item(client_opts) values_from_response_hash(resp.data["Attributes"]) if [:return] and resp.data["Attributes"] end |
#exists?(options = {}) ⇒ Boolean
Returns True if the item exists.
90 91 92 93 94 95 |
# File 'lib/aws/dynamo_db/item.rb', line 90 def exists?( = {}) client_opts = (self, ) client_opts[:attributes_to_get] = [table.hash_key.name] resp = client.get_item(client_opts) resp.data.key?("Item") end |