Module: AWS.DynamoDB.Converter

Defined in:
lib/dynamodb/converter.js

Method Summary

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

  • wrapNumbers (Boolean)

    Whether to return numbers as a NumberValue object instead of converting them to native JavaScript numbers. This allows for the safe round-trip transport of numbers of arbitrary size.

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

  • wrapNumbers (Boolean)

    Whether to return numbers as a NumberValue object instead of converting them to native JavaScript numbers. This allows for the safe round-trip transport of numbers of arbitrary size.

Returns:

  • (map)

    An object in the DynamoDB record format.

output(data, options) ⇒ 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

  • options (map)

Options Hash (options):

  • convertEmptyValues (Boolean)

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

  • wrapNumbers (Boolean)

    Whether to return numbers as a NumberValue object instead of converting them to native JavaScript numbers. This allows for the safe round-trip transport of numbers of arbitrary size.

See Also:

unmarshall(data, options) ⇒ 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

  • options (map)

Options Hash (options):

  • convertEmptyValues (Boolean)

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

  • wrapNumbers (Boolean)

    Whether to return numbers as a NumberValue object instead of converting them to native JavaScript numbers. This allows for the safe round-trip transport of numbers of arbitrary size.

Returns:

  • (map)

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