duenamodb
Version:
Simple, strongly-typed helpers around the AWS SDK DynamoDB client.
28 lines • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.putItem = exports.createPutItem = void 0;
const client_dynamodb_1 = require("@aws-sdk/client-dynamodb");
const util_dynamodb_1 = require("@aws-sdk/util-dynamodb");
const client_1 = require("./client");
const createPutItem = (options) => {
const { tablename } = options;
return (item, options = {}) => (0, exports.putItem)(tablename, (0, util_dynamodb_1.marshall)(item), options);
};
exports.createPutItem = createPutItem;
const putItem = async (tableName, input, options) => {
if (!input) {
throw new Error("Missing put item input");
}
const command = new client_dynamodb_1.PutItemCommand({
...options,
Item: input,
TableName: tableName,
});
const res = await client_1.DDBClient.instance.send(command);
if (res.$metadata.httpStatusCode !== 200) {
throw res;
}
return (0, util_dynamodb_1.unmarshall)(input);
};
exports.putItem = putItem;
//# sourceMappingURL=put.js.map