Skip to content

Commit

Permalink
Fixed #65 Pagination issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Arora committed May 21, 2021
1 parent 7bd6429 commit 084133a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ async function getQueryResultsFromS3(params) {

} else if (Boolean(params.config.pagination)) {
//user wants DML response paginated

const paginationFactor = Boolean(params.config.NextToken) ? 0 : 1

let paginationParams = {
QueryExecutionId: params.config.QueryExecutionId,
MaxResults: params.config.pagination + 1,
MaxResults: params.config.pagination + paginationFactor,
NextToken: params.config.NextToken,
};

Expand All @@ -102,7 +105,7 @@ async function getQueryResultsFromS3(params) {
.promise();
if (params.config.formatJson) {
return {
items: await cleanUpPaginatedDML(queryResults),
items: await cleanUpPaginatedDML(queryResults, paginationFactor),
nextToken: queryResults.NextToken,
};
} else {
Expand All @@ -124,14 +127,14 @@ async function getQueryResultsFromS3(params) {
}
}

async function cleanUpPaginatedDML(queryResults) {
async function cleanUpPaginatedDML(queryResults, paginationFactor) {
const dataTypes = await getDataTypes();
const columnNames = Object.keys(dataTypes).reverse();
let rowObject = {};
let unformattedS3RowArray = null;
let formattedArray = [];

for (let i = 1; i < queryResults.ResultSet.Rows.length; i++) {
for (let i = paginationFactor; i < queryResults.ResultSet.Rows.length; i++) {
unformattedS3RowArray = queryResults.ResultSet.Rows[i].Data;

for (let j = 0; j < unformattedS3RowArray.length; j++) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "athena-express",
"version": "7.0.3",
"version": "7.1.0",
"description": "Athena-Express makes it easier to execute SQL queries on Amazon Athena by consolidating & astracting several methods in the AWS SDK",
"main": "./lib/index.js",
"types": "./index.d.ts",
Expand Down

0 comments on commit 084133a

Please sign in to comment.