it("throws error when operation is not supported", async () => { expect( () => new DynamoDbItemReader( "BOOM", new AWS.DynamoDB.DocumentClient(), dynamoDbParams ) ).toThrow( "Unsupported DynamoDB operation! Supported operations are SCAN and QUERY." ); });
function Message() { this.dynamoDB = new AWS.DynamoDB.DocumentClient({ region: config.REGION, endpoint: config.DYNAMODB_ENDPOINT }); this.tableName = `${config.ENV_NAME}_Messages`; }
constructor(connectionTableName, endpoint) { this.connectionTableName = connectionTableName; this.DDB = new AWS.DynamoDB(); this.documentClient = new AWS.DynamoDB.DocumentClient(); this.endpoint = endpoint; }
it("generates next object", async () => { documentClient.scan.mockImplementation(yields({ Items: ["Foo"] })); const reader = new DynamoDbItemReader( "SCAN", new AWS.DynamoDB.DocumentClient(), dynamoDbParams ); const next = await reader.next(); expect(next).toEqual({ item: "Foo", cursor: { index: 0 }, finished: true }); });
const clientConstructor = (options = {}) => { const dynamoClient = new DynamoDB.DocumentClient(options) promisifyDocumentClient(dynamoClient) autoRetry(dynamoClient) appendDeleteAll(dynamoClient) appendPutAll(dynamoClient) appendQueryExtensions(dynamoClient) appendScanExtensions(dynamoClient) return dynamoClient }
describe("when using SCAN operation", () => { beforeEach(async () => { const reader = new DynamoDbItemReader( "SCAN", new AWS.DynamoDB.DocumentClient(), dynamoDbParams ); await reader.next(); }); it("scans DynamoDb", () => { expect(documentClient.query).not.toHaveBeenCalled(); expect(documentClient.scan).toHaveBeenCalled(); }); it("uses the specified parameters", () => { expect(documentClient.scan).toHaveBeenCalledWith( dynamoDbParams, expect.any(Function) ); }); });
constructor({ dynamoDB, cache, cacheTableName = 'nd-geohash_HashKeyCache', hashKey = 'hash', geohashKey = 'geohash', geohashIndex = 'index.geohash', locationKey = 'location', hashKeyLength = 6}) { // initialize instance variables this.geohashService = new Geohash({ hashKeyLength: hashKeyLength }); this.dbClient = new AWS.DynamoDB.DocumentClient({ service: dynamoDB}); this.cache = cache; this.cacheTableName = cacheTableName; this.hashKey = hashKey; this.geohashKey = geohashKey; this.geohashIndex = geohashIndex; this.locationKey = locationKey; // promisify as required this.dbClient.putAsync = Promise.promisify(this.dbClient.put, { context: this.dbClient }); this.dbClient.queryAsync = Promise.promisify(this.dbClient.query, { context: this.dbClient }); this.dbClient.updateAsync = Promise.promisify(this.dbClient.update, { context: this.dbClient }); }
// ############################################################ async function putLabelsInDB(bucketName, objectKey, labels) { const dynamoDB = new DynamoDB.DocumentClient({ apiVersion: "latest" }); await dynamoDB .put({ TableName: process.env.VIDEOS_DYNAMODB_TABLE, Item: { videoName: objectKey, videoBucket: bucketName, labels, }, }) .promise(); }
constructor() { this._connector = new aws.DynamoDB.DocumentClient(CONSTANTS.DYNAMODB_OPTIONS); }
constructor(tableName) { this.tableName = tableName; this.documentClient = new AWS.DynamoDB.DocumentClient(); }
constructor(connectionTableName, endpoint) { this.connectionTableName = connectionTableName; this.DDB = new AWS.DynamoDB(); this.documentClient = new AWS.DynamoDB.DocumentClient(); this.endpoint = endpoint; }
it("throws error when operation is not supported", async () => { expect( () => new DynamoDbItemReader( "BOOM", new AWS.DynamoDB.DocumentClient(), dynamoDbParams ) ).toThrow( "Unsupported DynamoDB operation! Supported operations are SCAN and QUERY." ); });
it("generates next object", async () => { documentClient.scan.mockImplementation(yields({ Items: ["Foo"] })); const reader = new DynamoDbItemReader( "SCAN", new AWS.DynamoDB.DocumentClient(), dynamoDbParams ); const next = await reader.next(); expect(next).toEqual({ item: "Foo", cursor: { index: 0 }, finished: true }); });
function User() { this.saltRounds = 10; this.dynamoDB = new AWS.DynamoDB.DocumentClient({ region: config.REGION, endpoint: config.DYNAMODB_ENDPOINT }); this.tableName = `${config.ENV_NAME}_Users`; }
constructor(tableName) { this.tableName = tableName; this.documentClient = new AWS.DynamoDB.DocumentClient(); }