Module: Aws::Record::ItemOperations::ItemOperationsClassMethods
- Included in:
- Aws::Record
- Defined in:
- lib/aws-record/record/item_operations.rb
Instance Method Summary collapse
-
#find(opts) ⇒ Aws::Record
Builds and returns an instance of your model.
-
#find_with_opts(opts) ⇒ Aws::Record
Note that
#find_with_opts
will pass through all options other than:key
unaltered to the underlying Aws::DynamoDB::Client#get_item request. -
#update(opts) ⇒ Object
Performs an Aws::DynamoDB::Client#update_item call immediately on the table, using the attribute key/value pairs provided.
Instance Method Details
#find(opts) ⇒ Aws::Record
Returns builds and returns an instance of your model.
239 240 241 |
# File 'lib/aws-record/record/item_operations.rb', line 239 def find(opts) find_with_opts(key: opts) end |
#find_with_opts(opts) ⇒ Aws::Record
Note that #find_with_opts
will pass through all options other than :key
unaltered to the underlying Aws::DynamoDB::Client#get_item request. You should ensure that you have an aws-sdk gem version which supports the options you are including, and avoid adding options not recognized by the underlying client to avoid runtime exceptions.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/aws-record/record/item_operations.rb', line 269 def find_with_opts(opts) key = opts.delete(:key) request_key = {} @keys.keys.each_value do |attr_sym| unless key[attr_sym] raise Errors::KeyMissing.new( "Missing required key #{attr_sym} in #{key}" ) end attr_name = attributes.storage_name_for(attr_sym) request_key[attr_name] = attributes.attribute_for(attr_sym). serialize(key[attr_sym]) end request_opts = { table_name: table_name, key: request_key }.merge(opts) resp = dynamodb_client.get_item(request_opts) if resp.item.nil? nil else build_item_from_resp(resp) end end |
#update(opts) ⇒ Object
Performs an Aws::DynamoDB::Client#update_item call immediately on the table, using the attribute key/value pairs provided.
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/aws-record/record/item_operations.rb', line 316 def update(opts) key = {} updates = {} @keys.keys.each_value do |attr_sym| unless value = opts.delete(attr_sym) raise Errors::KeyMissing.new( "Missing required key #{attr_sym} in #{opts}" ) end attr_name = attributes.storage_name_for(attr_sym) key[attr_name] = attributes.attribute_for(attr_sym).serialize(value) end request_opts = { table_name: table_name, key: key } update_tuple = _build_update_expression(opts) unless update_tuple.nil? uex, exp_attr_names, exp_attr_values = update_tuple request_opts[:update_expression] = uex request_opts[:expression_attribute_names] = exp_attr_names request_opts[:expression_attribute_values] = exp_attr_values unless exp_attr_values.empty? end dynamodb_client.update_item(request_opts) end |