Skip to content

Commit

Permalink
Merge 4eb2574 into ff49d97
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed May 9, 2020
2 parents ff49d97 + 4eb2574 commit c72e644
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/docs/guide/Query.md
Expand Up @@ -85,6 +85,8 @@ This function will limit which attributes DynamoDB returns for each item in the
Cat.query("name").eq("Will").attributes(["id", "name"]); // Return all documents but only return the `id` & `name` properties for each item
```

This function uses the `ProjectionExpression` DynamoDB property to save bandwidth and not send the entire item over the wire.

## query.count()

Instead of returning an array of documents this function will cause the query operation to return a special object with the count information for the query. The response you will receive from the query operation with this setting will be an object with the properties `count` & `queriedCount`, which have the same values as described in [`query.exec([callback])`](#queryexeccallback).
Expand Down
2 changes: 2 additions & 0 deletions docs/docs/guide/Scan.md
Expand Up @@ -86,6 +86,8 @@ This function will limit which attributes DynamoDB returns for each item in the
Cat.scan().attributes(["id", "name"]); // Return all documents but only return the `id` & `name` properties for each item
```

This function uses the `ProjectionExpression` DynamoDB property to save bandwidth and not send the entire item over the wire.

## scan.parallel(parallelScans)

This function will run parallel scans on your table. The `parallelScans` parameter should be a number representing how many concurrent scans you wish to preform on the table. The results will be merged into a single array, with the `count`, `scannedCount`, & `timesScanned` properties being summed in the response. In the event there are multiple `lastKey` properties these will be merged into an array of objects.
Expand Down
2 changes: 1 addition & 1 deletion lib/DocumentRetriever.ts
Expand Up @@ -178,7 +178,7 @@ DocumentRetriever.prototype.getRequest = async function(this: DocumentRetriever)
object.ExclusiveStartKey = Document.isDynamoObject(this.settings.startAt) ? this.settings.startAt : this.internalSettings.model.Document.objectToDynamo(this.settings.startAt);
}
if (this.settings.attributes) {
object.AttributesToGet = this.settings.attributes;
object.ProjectionExpression = this.settings.attributes.join(", ");
}
const indexes = await this.internalSettings.model.schema.getIndexes(this.internalSettings.model);
if (this.settings.index) {
Expand Down
8 changes: 7 additions & 1 deletion test/Query.js
Expand Up @@ -1166,7 +1166,13 @@ describe("Query", () => {
it("Should send correct request on query.exec", async () => {
queryPromiseResolver = () => ({"Items": []});
await Model.query("name").eq("Charlie").attributes(["id"]).exec();
expect(queryParams.AttributesToGet).to.eql(["id"]);
expect(queryParams.ProjectionExpression).to.eql("id");
});

it("Should send correct request on query.exec with multiple attributes", async () => {
queryPromiseResolver = () => ({"Items": []});
await Model.query("name").eq("Charlie").attributes(["id", "name"]).exec();
expect(queryParams.ProjectionExpression).to.eql("id, name");
});
});

Expand Down
11 changes: 9 additions & 2 deletions test/Scan.js
Expand Up @@ -608,9 +608,16 @@ describe("Scan", () => {

it("Should send correct request on scan.exec", async () => {
scanPromiseResolver = () => ({"Items": []});
await Model.scan().attributes(["id"]).exec();
expect(scanParams.AttributesToGet).to.eql(["id"]);
await Model.scan("name").eq("Charlie").attributes(["id"]).exec();
expect(scanParams.ProjectionExpression).to.eql("id");
});

it("Should send correct request on scan.exec with multiple attributes", async () => {
scanPromiseResolver = () => ({"Items": []});
await Model.scan("name").eq("Charlie").attributes(["id", "name"]).exec();
expect(scanParams.ProjectionExpression).to.eql("id, name");
});

});

describe("scan.parallel", () => {
Expand Down

0 comments on commit c72e644

Please sign in to comment.