dynamoose/dynamoose

[FEATURE] Update documentation to give a hint on how to extract an array of items from a query response

Open

Aperta il 30 nov 2021

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)JavaScript (2025 star) (349 fork)batch import
difficulty:lowgood first issuehelp wantedstatus:todotype:enhancementtype:other

Descrizione

Summary:

https://dynamoosejs.com/guide/Query/#queryexeccallback The Dynamoose documentation says the following about the response object of a query:

The results array you receive back is a standard JavaScript array of objects. However, the array has some special properties with extra information about your query operation that you can access. This does not prevent the ability do running loops or accessing the objects within the array.

On my REST API using Dynamoose, I wanted to be able to return the array of items returned from a Dynamoose query I had created. But after reading the documentation quoted above and inspecting the response object ,I (and perhaps a few others on issue #488) was still confused on how go about isolating the array of items that were retrieved from the query, from the rest of the response object.

@fishcharlie then suggested using es6 array destructuring, which turned out to be the perfect solution to my problem.

My request is to update the documentation to give other developers a hint on how to easily extract an array of items from a query response. The wording could be as follows:

To isolate the array of items retrieved from the rest of the response, you can simply use es6 array destructuring

const results = await Cat.query().exec();
const items = [...results];
// items now holds an array of the items that were retrieved by the query

Code sample:

Schema

// Code here

(N/A)

Model

// Code here

(N/A)

General

// Code here

(N/A)

Environment:

Operating System: Operating System Version: Node.js version (node -v): NPM version: (npm -v): Dynamoose version: (N/A)

Other information (if applicable):

(N/A)

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this feature has not already been suggested before
  • I have filled out all fields above
  • I am running the latest version of Dynamoose

Guida contributor