Class: Aws::Plugins::DynamoDBSimpleAttributes
- Inherits:
-
Seahorse::Client::Plugin
- Object
- Seahorse::Client::Plugin
- Aws::Plugins::DynamoDBSimpleAttributes
- Defined in:
- lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb
Overview
Simplifies working with Amazon DynamoDB attribute values. Translates attribute values for requests and responses to sensible Ruby natives.
This plugin is enabled by default for all DynamoDB::Client objects. You can disable this plugin by passing ‘simple_attributes: false` to the client constructor:
ddb = Aws::DynamoDB::Client.new(simple_attributes: false)
## Input Examples
With this plugin enabled, ‘simple_attributes: true`:
dynamodb.put_item(
table_name: 'aws-sdk',
item: {
id: 'uuid',
age: 35,
tags: Set.new(%w(simple attributes)),
data: StringIO.new('data'),
scores: [5, 4.5, 4.9, nil],
name: {
first: 'John',
last: 'Doe',
}
}
)
With this plugin disabled, ‘simple_attributes: false`:
# note that all types are prefixed in a hash and that
# numeric types must be serialized as strings
dynamodb.put_item(
table_name: 'aws-sdk',
item: {
'id' => { s: 'uuid' },
'age' => { n: '35' },
'tags' => { ss: ['simple', 'attributes'] },
'data' => { b: 'data' },
'scores' => {
l: [
{ n: '5' },
{ n: '4.5' },
{ n: '4.9' },
{ null: true },
]
},
'name' => {
m: {
'first' => { s: 'John' },
'last' => { s: 'Doe' },
}
}
}
)
## Output Examples
With this plugin enabled, ‘simple_attributes: true`:
resp = dynamodb.get(table_name: 'aws-sdk', key: { id: 'uuid' })
resp.item
{
id: 'uuid',
age: 35,
tags: Set.new(%w(simple attributes)),
data: StringIO.new('data'),
scores: [5, 4.5, 4.9, nil],
name: {
first: 'John',
last: 'Doe',
}
}
With this plugin disabled, ‘simple_attributes: false`:
# note that the request `:key` had to be type prefixed
resp = dynamodb.get(table_name: 'aws-sdk', key: { 'id' => { s: 'uuid' }})
resp.item
# {
# "id"=> <struct s='uuid', n=nil, b=nil, ss=nil, ns=nil, bs=nil, m=nil, l=nil, null=nil, bool=nil>
# "age"=> <struct s=nil, n="35", b=nil, ss=nil, ns=nil, bs=nil, m=nil, l=nil, null=nil, bool=nil>
# ...
# }
Defined Under Namespace
Classes: Handler, ValueTranslator
Instance Method Summary collapse
Methods inherited from Seahorse::Client::Plugin
#add_options, #after_initialize, after_initialize, after_initialize_hooks, before_initialize, #before_initialize, before_initialize_hooks, handlers, option, options
Methods included from Seahorse::Client::HandlerBuilder
#handle, #handle_request, #handle_response, #handler_for, #new_handler
Instance Method Details
#add_handlers(handlers, config) ⇒ Object
102 103 104 105 106 |
# File 'lib/aws-sdk-core/plugins/dynamodb_simple_attributes.rb', line 102 def add_handlers(handlers, config) if config.simple_attributes handlers.add(Handler, step: :initialize) end end |