@blueleader07/typeorm
Version:
Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, MongoDB databases.
60 lines (58 loc) • 2.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dynamoParamHelper = void 0;
const DynamoUpdateExpressionOptions_1 = require("../models/DynamoUpdateExpressionOptions");
const DynamoFindOptions_1 = require("../models/DynamoFindOptions");
const DynamoGlobalSecondaryIndexHelper_1 = require("./DynamoGlobalSecondaryIndexHelper");
const DynamoObjectHelper_1 = require("./DynamoObjectHelper");
const indexedWhere = (options, indices) => {
indices = indices || [];
const index = indices.find((index) => {
return index.name === options.index;
});
const where = {};
if (index && options.where) {
const columns = index.columns || [];
const partitionKey = (0, DynamoGlobalSecondaryIndexHelper_1.buildPartitionKey)(columns);
const values = [];
for (let i = 0; i < columns.length; i += 1) {
const column = columns[i];
const value = options.where[column.propertyName];
values.push(value);
}
where[partitionKey] = values.join("#");
}
return (0, DynamoObjectHelper_1.isNotEmpty)(where) ? where : options.where;
};
exports.dynamoParamHelper = {
find(tableName, options, indices) {
options.where = indexedWhere(options, indices);
const params = {
TableName: tableName,
KeyConditionExpression: DynamoFindOptions_1.DynamoFindOptions.toKeyConditionExpression(options),
ExpressionAttributeNames: DynamoFindOptions_1.DynamoFindOptions.toAttributeNames(options),
ExpressionAttributeValues: DynamoFindOptions_1.DynamoFindOptions.toExpressionAttributeValues(options),
ScanIndexForward: options.sort !== "DESC",
};
if (options.index) {
params.IndexName = options.index;
}
if (options.limit) {
params.Limit = options.limit;
}
if (options.exclusiveStartKey) {
params.ExclusiveStartKey = options.exclusiveStartKey;
}
return params;
},
update(tableName, options) {
return {
TableName: tableName,
Key: options.where,
UpdateExpression: DynamoUpdateExpressionOptions_1.DynamoUpdateExpressionOptions.toUpdateExpression(options),
ExpressionAttributeNames: DynamoUpdateExpressionOptions_1.DynamoUpdateExpressionOptions.toAttributeNames(options),
ExpressionAttributeValues: DynamoUpdateExpressionOptions_1.DynamoUpdateExpressionOptions.toExpressionAttributeValues(options),
};
},
};
//# sourceMappingURL=DynamoParamHelper.js.map