Autosave: 2024-06-23 13:00:03

This commit is contained in:
thomasabishop 2024-06-23 13:00:03 +01:00
parent b96aa58485
commit 97735f1070
2 changed files with 31 additions and 0 deletions

View file

@ -2,6 +2,7 @@
tags: tags:
- AWS - AWS
- databases - databases
- dynamodb
--- ---
# Database options # Database options

View file

@ -21,11 +21,41 @@ const client = new DynamoDBClient({
}); });
``` ```
### DynamoDB Document Client
The Document Client returns the data as a standard JSON document in the manner
of a document-based NoSQL database. Without it, DynamoDB will return the data
with type data which is unwieldy and hard to parse.
To transform into a document structure:
```js
import DynamoDBClient from "@aws-sdk/client-dynamodb";
import DynamoDBDocumentClient from "@aws-sdk/lib-dynamodb";
const client = new DynamoDBClient({
region: "eu-west-2",
accessKeyId: process.env.ACCESS_KEY_ID,
secretAccessKey: process.env.ACCESS_KEY_ID,
});
const dynamoDbDocumentClient = DynamoDBDocumentClient.from(client);
```
## Query a table ## Query a table
Querying is the most performant and cost-effective method since it is an O(1) Querying is the most performant and cost-effective method since it is an O(1)
lookup against a partition key or secondary index. lookup against a partition key or secondary index.
```js
const params = {
TableName: "YourTableName",
KeyConditionExpression: "#pk = :pk",
ExpressionAttributeNames: { "#pk": "PrimaryKeyAttributeName" },
ExpressionAttributeValues: { ":pk": "PrimaryKeyValue" },
};
```
## Scan a table ## Scan a table
Scanning is less performant (O(n)) and most expensive since it requires checking Scanning is less performant (O(n)) and most expensive since it requires checking