Skip to content

Commit

Permalink
dynamo: index projection
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Sep 3, 2024
1 parent 685c976 commit ab20880
Showing 1 changed file with 60 additions and 2 deletions.
62 changes: 60 additions & 2 deletions platform/src/components/aws/dynamo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ export interface DynamoArgs {
* The range key field of the index. This field needs to be defined in the `fields`.
*/
rangeKey?: Input<string>;
/**
* The fields to project into the index.
* @default `"all"`
* @example
* Project only the key fields: `userId` and `createdAt`.
* ```js
* {
* hashKey: "userId",
* rangeKey: "createdAt",
* projection: "keys_only"
* }
* ```
*
* Project the `noteId` field in addition to the key fields.
* ```js
* {
* hashKey: "userId",
* rangeKey: "createdAt",
* projection: ["noteId"]
* }
* ```
*/
projection?: Input<"all" | "keys_only" | Input<string>[]>;
}>
>
>;
Expand Down Expand Up @@ -110,6 +133,27 @@ export interface DynamoArgs {
* The range key field of the index. This field needs to be defined in the `fields`.
*/
rangeKey: Input<string>;
/**
* The fields to project into the index.
* @default `"all"`
* @example
* Project only the key field: `createdAt`.
* ```js
* {
* rangeKey: "createdAt",
* projection: "keys_only"
* }
* ```
*
* Project the `noteId` field in addition to the key field.
* ```js
* {
* rangeKey: "createdAt",
* projection: ["noteId"]
* }
* ```
*/
projection?: Input<"all" | "keys_only" | Input<string>[]>;
}>
>
>;
Expand Down Expand Up @@ -410,14 +454,28 @@ export class Dynamo extends Component implements Link.Linkable {
name,
hashKey: index.hashKey,
rangeKey: index.rangeKey,
projectionType: "ALL",
...(index.projection === "keys_only"
? { projectionType: "KEYS_ONLY" }
: Array.isArray(index.projection)
? {
projectionType: "INCLUDE",
nonKeyAttributes: index.projection,
}
: { projectionType: "ALL" }),
}),
),
localSecondaryIndexes: Object.entries(localIndexes ?? {}).map(
([name, index]) => ({
name,
rangeKey: index.rangeKey,
projectionType: "ALL",
...(index.projection === "keys_only"
? { projectionType: "KEYS_ONLY" }
: Array.isArray(index.projection)
? {
projectionType: "INCLUDE",
nonKeyAttributes: index.projection,
}
: { projectionType: "ALL" }),
}),
),
},
Expand Down

0 comments on commit ab20880

Please sign in to comment.