Last active
April 6, 2024 03:20
-
-
Save filmaj/e4965efbc1aae013d611b00231325301 to your computer and use it in GitHub Desktop.
Revisions
-
filmaj revised this gist
Apr 6, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ const DocumentClientQueryReadable = require('./documentclientqueryreadable'); const JSONStream = require('JSONStream'); awsLite({ plugins: [import('@aws-lite/dynamodb')]}).then((aws) => { new DocumentClientQueryReadable(aws, { TableName: 'whatevers', IndexName: 'PartitionedByYear', KeyConditionExpression: 'yearUpdated = :yearUpdated AND startdate BETWEEN :start AND :end', ExpressionAttributeValues: { -
filmaj created this gist
Apr 6, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ const { Readable } = require('node:stream'); const DocumentSource = require('./documentsource'); module.exports = class DocumentClientQueryReadable extends Readable { constructor (client, params) { super({ objectMode: true }); this.source = new DocumentSource(client, params); this.source.on('data', this.onData.bind(this)); this.source.on('end', this.onEnd.bind(this)); } _read () { this.source.readStart(); } onData (chunk) { this.push(chunk); } onEnd () { this.push(null); this.source.removeListener('data', this.onData); this.source.removeListener('end', this.onEnd); } }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ const { EventEmitter } = require('node:events'); module.exports = class DocumentSource extends EventEmitter { constructor (client, params) { super(); this.client = client; this.params = params; } readStart () { this.read().then((res) => { if (res.LastEvaluatedKey) { this.params = { ...this.params, ExclusiveStartKey: res.LastEvaluatedKey }; this.emit('data', res); } else { this.emit('data', res); this.emit('end'); } }); } read () { return this.client.DynamoDB.Query(this.params); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ const awsLite = require('@aws-lite/client'); const DocumentClientQueryReadable = require('./documentclientqueryreadable'); const JSONStream = require('JSONStream'); awsLite({ plugins: [import('@aws-lite/dynamodb')]}).then((aws) => { new DocumentClientQueryReadable(aws, { TableName: 'ArcOssContributorsStaging-UsersTable-HMR07QFCV7F9-m3', IndexName: 'PartitionedByYear', KeyConditionExpression: 'yearUpdated = :yearUpdated AND startdate BETWEEN :start AND :end', ExpressionAttributeValues: { ':yearUpdated': `2024`, ':start': `2024-03-01`, ':end': `2024-03-31` }, ScanIndexForward: false // sort descending to get most recent records }).pipe(JSONStream.stringify(false)).pipe(process.stdout); });