Class: Aws::DynamoDB::Plugins::SimpleAttributes

Inherits:
Seahorse::Client::Plugin
  • Object
show all
Defined in:
lib/aws-sdk-dynamodb/plugins/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 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

Instance Method Details

#add_handlers(handlers, config) ⇒ Object



109
110
111
112
113
# File 'lib/aws-sdk-dynamodb/plugins/simple_attributes.rb', line 109

def add_handlers(handlers, config)
  if config.simple_attributes
    handlers.add(Handler, step: :initialize)
  end
end