UNPKG

dynamodb-fast-access

Version:

Default CRUD operations for managing AWS DynamoDB table items in an easy-to-extend structure.

61 lines (60 loc) 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class ExpressionCreator { static getUpdateExpression(attributes) { const attrib = attributes; let expression = ''; Object.keys(attrib).forEach(field => { if (attrib[field] !== undefined) { if (expression !== '') expression += ', '; expression += '#' + field + ' = ' + ':' + field; } }); return expression; } static getUpdateExpressionRemove(attributes) { let expression = ''; for (const attribute of attributes) { if (attribute !== '') { if (expression !== '') expression += ', '; expression += '#' + attributes; } } return expression; } static getFilterExpression(attributes) { const attrib = attributes; let expression = ''; Object.keys(attrib).forEach(field => { if (attrib[field] !== undefined) { if (expression !== '') expression += ' and '; expression += '#' + field + ' = ' + ':' + field; } }); return expression; } static getExpressionAttributeValues(attributes) { const attrib = attributes; const expression = {}; Object.keys(attrib).forEach(field => { if (attrib[field] !== undefined) { expression[':' + field] = attrib[field]; } }); return expression; } static getExpressionAttributeNames(attributes) { const attrib = attributes; const expression = {}; Object.keys(attrib).forEach(field => { if (attrib[field] !== undefined) { expression['#' + field] = field; } }); return expression; } } exports.ExpressionCreator = ExpressionCreator;