UNPKG

@blueleader07/typeorm

Version:

Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.

53 lines (51 loc) 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DynamoFindOptions = exports.BeginsWith = void 0; const DynamoAttributeHelper_1 = require("../helpers/DynamoAttributeHelper"); const DynamoTextHelper_1 = require("../helpers/DynamoTextHelper"); const DynamoObjectHelper_1 = require("../helpers/DynamoObjectHelper"); class BeginsWith { } exports.BeginsWith = BeginsWith; class DynamoFindOptions { static toAttributeNames(findOptions) { return DynamoAttributeHelper_1.dynamoAttributeHelper.toAttributeNames(findOptions.where, findOptions.beginsWith); } static toKeyConditionExpression(findOptions) { if ((0, DynamoObjectHelper_1.isNotEmpty)(findOptions.where)) { const keys = Object.keys(findOptions.where); const values = []; for (let i = 0; i < keys.length; i++) { const key = keys[i]; const attribute = (0, DynamoTextHelper_1.poundToUnderscore)(key); values.push(`#${attribute} = :${attribute}`); } return DynamoFindOptions.appendBeginsWith(values.join(" and "), findOptions.beginsWith); } return undefined; } static appendBeginsWith(expression, beginsWith) { if (beginsWith) { const attribute = (0, DynamoTextHelper_1.poundToUnderscore)(beginsWith.attribute); return `${expression} and begins_with(#${attribute}, :${attribute})`; } return expression; } static toExpressionAttributeValues(findOptions) { if ((0, DynamoObjectHelper_1.isNotEmpty)(findOptions.where)) { const keys = Object.keys(findOptions.where); const values = {}; for (let i = 0; i < keys.length; i++) { const key = keys[i]; values[`:${(0, DynamoTextHelper_1.poundToUnderscore)(key)}`] = findOptions.where[key]; } if (findOptions.beginsWith) { values[`:${(0, DynamoTextHelper_1.poundToUnderscore)(findOptions.beginsWith.attribute)}`] = findOptions.beginsWith.value; } return values; } return undefined; } } exports.DynamoFindOptions = DynamoFindOptions; //# sourceMappingURL=DynamoFindOptions.js.map