From 11b5e8b606d53a0ef4ccc6249f677d022d4acc7a Mon Sep 17 00:00:00 2001 From: Stef Vartolomeev Date: Fri, 15 Jul 2022 12:12:06 +0300 Subject: [PATCH] annotations: Add example of usage with Glboal Secondary Indexes --- .../README.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/dynamodb-data-mapper-annotations/README.md b/packages/dynamodb-data-mapper-annotations/README.md index 10a05ccc..a5321815 100644 --- a/packages/dynamodb-data-mapper-annotations/README.md +++ b/packages/dynamodb-data-mapper-annotations/README.md @@ -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`