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).
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 |
||||||||||||||||
options |
Object |
<optional> |
The configuration options parameters. Properties
|
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 |
|||||||||||||||
options |
Object |
<optional> |
The configuration options parameters. Properties
|
Returns:
A promise that resolves to the response from DynamoDB.
- Type
- Promise