Skip to content

Commit

Permalink
docs: update info regarding DocumentClient instantiation with AWS SDK v3
Browse files Browse the repository at this point in the history
  • Loading branch information
naorpeled authored Apr 10, 2023
1 parent 562c0b6 commit 30a82ca
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,32 @@ Require or import `Table` and `Entity` from `dynamodb-toolbox`:
import { Table, Entity } from 'dynamodb-toolbox'
```

Create a Table (with the DocumentClient using aws-sdk v2):
Create a Table (with the DocumentClient using aws-sdk v3):

```typescript
import DynamoDB from 'aws-sdk/clients/dynamodb'
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'

const marshallOptions = {
// Whether to automatically convert empty strings, blobs, and sets to `null`.
convertEmptyValues: false, // if not false explicitly, we set it to true.
// Whether to remove undefined values while marshalling.
removeUndefinedValues: false, // false, by default.
// Whether to convert typeof object to map attribute.
convertClassInstanceToMap: false, // false, by default.
}

const unmarshallOptions = {
// Whether to return numbers as a string instead of converting them to native JavaScript numbers.
// NOTE: this is required to be true in order to use the bigint data type.
wrapNumbers: false, // false, by default.
}

const translateConfig = { marshallOptions, unmarshallOptions }

// Instantiate a DocumentClient
export const DocumentClient = DynamoDBDocumentClient.from(new DynamoDBClient(), translateConfig)

const DocumentClient = new DynamoDB.DocumentClient({
// Specify your client options as usual
convertEmptyValues: false
})

// Instantiate a table
const MyTable = new Table({
Expand Down
20 changes: 19 additions & 1 deletion docs/docs/introduction/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,25 @@ const { Table, Entity } = require('dynamodb-toolbox')
```typescript title="TypeScript"
import { Table, Entity } from 'dynamodb-toolbox'
```
## Load the DocumentClient using aws-sdk v2

## Load the DocumentClient using aws-sdk v3 (>=v0.8.0)

```typescript title="TypeScript"
import { DynamoDB } from '@aws-sdk/client-dynamodb'
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'

const marshallOptions = {
// Specify your client options as usual
convertEmptyValues: false
}

const translateConfig = { marshallOptions }

export const DocumentClient = DynamoDBDocumentClient.from(new DynamoDBClient(), translateConfig)
```

## Load the DocumentClient using aws-sdk v2 (<v0.8.0)

```typescript title="TypeScript"
import DynamoDB from 'aws-sdk/clients/dynamodb'
Expand Down
16 changes: 16 additions & 0 deletions docs/docs/introduction/what-is-dynamodb-toolbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ This library **DOES NOT** create DynamoDB Tables for you. You must create the ta
### Define a Table

```typescript

// >=v0.8.0
import { DynamoDB } from '@aws-sdk/client-dynamodb'
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'

const marshallOptions = {
// Specify your client options as usual
convertEmptyValues: false
}

const translateConfig = { marshallOptions }

export const DocumentClient = DynamoDBDocumentClient.from(new DynamoDBClient(), translateConfig)

// <v0.8.0
import DynamoDB from 'aws-sdk/clients/dynamodb'

const DocumentClient = new DynamoDB.DocumentClient({
Expand Down

0 comments on commit 30a82ca

Please sign in to comment.