Query

The Query operation finds items based on primary key values. You can query any table or secondary index that has a composite primary key (a partition key and a sort key).

Source:
See:

Methods

(inner) query(request, optionsopt) → {Promise}

Source:
See:

Finds items based on primary key values.

Example
// Returns all items in `SomeTable` of `id` `42` and `birthDate` between 1985 and 2019
 await query({
   TableName: 'SomeTable',
   KeyConditionExpression: "id = :identifier AND birthDate BETWEEN :d1 AND :d2",
   ExpressionAttributeValues: {
     identifier: { N: 42 },
     d1: { S: '1985-01-01' },
     d2: { S: '2019-01-01' }
   }
 });
Parameters:
Name Type Attributes Description
request Object

Parameters as expected by DynamoDB Query operation. Must contain, at least, TableName attribute.

options Object <optional>

The configuration options parameters.

Properties
Name Type Attributes Default Description
groupDelayMs number <optional>
100

The delay between individual requests. Defaults to 100 ms.

raw boolean <optional>
false

Whether to return the full DynamoDB response object when true or just the Items property value.

Returns:

A promise that resolves to the response from DynamoDB.

Type
Promise

(inner) queryFor(tableName, requestopt, optionsopt) → {Promise}

Source:
See:

Creates a function that finds items based on primary key values. You would typically use this function through forTable.

Examples
// Returns all items in `SomeTable` of `id` `42` and `birthDate` between 1985 and 2019
 await queryFor('SomeTable')({
   KeyConditionExpression: "id = :identifier AND birthDate BETWEEN :d1 AND :d2",
   ExpressionAttributeValues: {
     ':identifier': { N: 42 },
     ':d1': { S: '1985-01-01' },
     ':d2': { S: '2019-01-01' }
   }
 });
// Exported from `forTable`
 const { query } = forTable('SomeTable');
 await query({
   KeyConditionExpression: "id = :identifier AND postedBy BETWEEN :p1 AND :p2",
   ExpressionAttributeValues: {
     ':identifier': { N: 42 },
     ':p1': { S: 'Alice' },
     ':p2': { S: 'Dave' }
   }
 });
Parameters:
Name Type Attributes Description
tableName String

The name of the table to perform the operation on

request Object <optional>

Parameters as expected by DynamoDB Query operation. A TableName attributes specified here will override tableName argument.

options Object <optional>

The configuration options parameters.

Properties
Name Type Attributes Default Description
groupDelayMs number <optional>
100

The delay between individual requests. Defaults to 100 ms.

raw boolean <optional>
false

Whether to return the full DynamoDB response object when true or just the Items property value.

Returns:

A promise that resolves to the response from DynamoDB.

Type
Promise