0.0.5 • Published 7 years ago

dynamodb-niceupdate v0.0.5

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

dynamodb-niceupdate

Creates DynamoDB's DocumentClient.update() param object that performs an update operation, using UpdateExpression. Any empty value will be recursively removed, to make DynamoDB happy.

npm.io
npm Build Status Coverage Status

Usage

import { createFieldsUpdateParams } from 'dynamodb-niceupdate'

const params = createFieldsUpdateParams({
  tableName: 'DynamoDB_Table_name',
  keySchema: { Id: '123' },
  item: {
    a: 'b',
    b: { foo: ['bar'] },
    c: 3,
    d: [], // this empty list is removed
    e: {}, // this empty set is removed
    f: [{ x: '' }], // this empty object is removed
  }
})

assert.deepEqual(params, {
  TableName: 'DynamoDB_Table_name',
  ReturnValues: 'ALL_NEW',
  Key: { Id: '123' },
  ExpressionAttributeNames: {
    '#updatedOn': 'UpdatedOn',
    '#field0': `a`,
    '#field1': `b`,
    '#field2': `c`,
    '#field3': `d`,
    '#field4': `e`,
    '#field5': `f`
  },
  UpdateExpression: 'REMOVE #field3, #field4, #field5 SET #updatedOn=:now, #field0=:value0, #field1=:value1, #field2=:value2',
  ExpressionAttributeValues: {
    ':now': `${timestamp}`,
    ':value0': 'b',
    ':value1': { foo: ['bar'] },
    ':value2': 3
  }
})

const doc = new DynamoDB.DocumentClient({})
doc.update(params, callback)

Checkout the tests in src/index.spec.js.

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago