Skip to content

Instantly share code, notes, and snippets.

@Guy7B
Last active October 22, 2022 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Guy7B/495732ecc3c9915bf160de97940e2a28 to your computer and use it in GitHub Desktop.
Save Guy7B/495732ecc3c9915bf160de97940e2a28 to your computer and use it in GitHub Desktop.
const { utils } = require('dynamo-data-transform');
const TABLE_NAME = 'UsersExample';
/**
* The tool supply following parameters:
* @param {DynamoDBDocumentClient} ddb - dynamo db document client https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-dynamodb
* @param {boolean} isDryRun - true if this is a dry run
*/
const transformUp = async ({ ddb, isDryRun }) => {
const addFirstAndLastName = (item) => {
// Just for the example:
// Assume the FullName has one space between first and last name
const [firstName, ...lastName] = item.name.split(' ');
return {
...item,
firstName,
lastName: lastName.join(' '),
};
};
return utils.transformItems(ddb, TABLE_NAME, addFirstAndLastName, isDryRun);
};
module.exports = {
transformUp,
transformationNumber: 1,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment