Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

annotations: Add example of usage with Glboal Secondary Indexes #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/dynamodb-data-mapper-annotations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ class BlogPost {
}
```

To declare Global Secondary Index (GSI) you should use the `indexKeyConfigurations` property of the `attribute` annotation:

```typescript
import {
attribute,
hashKey,
table,
} from '@aws/dynamodb-data-mapper-annotations';

@table('posts')
class BlogPost {
@hashKey()
id: string;

// define a GSI index named `authorIndex` that uses `author`` as partition key
@attribute({indexKeyConfigurations: {
authorIndex: 'HASH'
}})
author?: string;

// define a GSI index named `postedAtIndex` that uses `postedAt`` as sort key
@attribute({indexKeyConfigurations: {
postedAtIndex: 'RANGE'
}})
postedAt?: Date;

@attribute()
text?: string;
}
```

## Supported Annotations

### `attribute`
Expand Down