Module: AWS.DynamoDB.Converter

Defined in:
lib/dynamodb/converter.js

Method Summary collapse

Method Details

input(data, options) ⇒ map

Convert a JavaScript value to its equivalent DynamoDB AttributeValue type

Parameters:

  • data (any)

    The data to convert to a DynamoDB AttributeValue

  • options (map)

Options Hash (options):

  • convertEmptyValues (Boolean)

    Whether to automatically convert empty strings, blobs, and sets to null

Returns:

  • (map)

    An object in the Amazon DynamoDB AttributeValue format

See Also:

marshall(data, options) ⇒ map

Convert a JavaScript object into a DynamoDB record.

Examples:

Convert a JavaScript object into a DynamoDB record

var marshalled = AWS.DynamoDB.Converter.marshall({
  string: 'foo',
  list: ['fizz', 'buzz', 'pop'],
  map: {
    nestedMap: {
      key: 'value',
    }
  },
  number: 123,
  nullValue: null,
  boolValue: true,
  stringSet: new DynamoDBSet(['foo', 'bar', 'baz'])
});

Parameters:

  • data (any)

    The data to convert to a DynamoDB record

  • options (map)

Options Hash (options):

  • convertEmptyValues (Boolean)

    Whether to automatically convert empty strings, blobs, and sets to null

Returns:

  • (map)

    An object in the DynamoDB record format.

output(data) ⇒ Object|Array|String|Number|Boolean|null

Convert a DynamoDB AttributeValue object to its equivalent JavaScript type.

Parameters:

  • data (map)

    An object in the Amazon DynamoDB AttributeValue format

See Also:

unmarshall(data) ⇒ map

Convert a DynamoDB record into a JavaScript object.

Examples:

Convert a record received from a DynamoDB stream

var unmarshalled = AWS.DynamoDB.Converter.unmarshall({
  string: {S: 'foo'},
  list: {L: [{S: 'fizz'}, {S: 'buzz'}, {S: 'pop'}]},
  map: {
    M: {
      nestedMap: {
        M: {
          key: {S: 'value'}
        }
      }
    }
  },
  number: {N: '123'},
  nullValue: {NULL: true},
  boolValue: {BOOL: true}
});

Parameters:

  • data (any)

    The DynamoDB record

Returns:

  • (map)

    An object whose properties have been converted from DynamoDB's AttributeValue format into their corresponding native JavaScript types.