Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding parameter to specify a max number #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ Full syntax is:
-h, --help output usage information
-V, --version output the version number
-t, --table [tablename] Add the table you want to output to csv
-d, --describe
-c, --count Number of items to export
-d, --describe


Pre-requisites
Expand Down
26 changes: 22 additions & 4 deletions dynamoDBtoCSV.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@ var Papa = require('papaparse');
var headers = [];
var unMarshalledArray = [];

program.version('0.0.1').option('-t, --table [tablename]', 'Add the table you want to output to csv').option("-d, --describe").option("-r, --region [regionname]").parse(process.argv);
var iterations = 0;

program.version('0.0.1')
.option('-t, --table [tablename]', 'Add the table you want to output to csv')
.option("-d, --describe")
.option('-c, --count [countToExport]')
.option("-r, --region [regionname]").parse(process.argv);

if (!program.count) {
console.log("You must specify the count (number of items to export)");
program.outputHelp();
process.exit(1);
} else {
console.log(program.count);
}

if (!program.table) {
console.log("You must specify a table");
program.outputHelp();
process.exit(1);
}


if (program.region && AWS.config.credentials) {
AWS.config.update({region: program.region});
} else {
Expand Down Expand Up @@ -47,8 +62,11 @@ var scanDynamoDB = function ( query ) {

if ( !err ) {
unMarshalIntoArray( data.Items ); // Print out the subset of results.
if ( data.LastEvaluatedKey ) { // Result is incomplete; there is more to come.
if ( data.LastEvaluatedKey && iterations < program.count ) { // Result is incomplete; there is more to come.

query.ExclusiveStartKey = data.LastEvaluatedKey;
iterations++;

scanDynamoDB(query);
}
else {
Expand All @@ -61,8 +79,8 @@ var scanDynamoDB = function ( query ) {
unMarshalledArray.unshift( dummyRow );
console.log(Papa.unparse( unMarshalledArray ));
}
}
else
}
else
console.dir(err);

});
Expand Down