Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(shape, dynamodb): Pick/Extend mechanics for Records to support DynamoDB Indexes #108

Merged
merged 9 commits into from
Feb 7, 2020

Conversation

sam-goodwin
Copy link
Owner

@sam-goodwin sam-goodwin commented Feb 5, 2020

Closes #104

Two new mechanics for Records:

  • Extends a Record to create a child record class - sub-typing! any suggestions for better name?
class A extends Record({
  a: string
}) {}
// extend A to create B
class B extends A.Extends({
  b: string
}) {}
// equiv. to:
type B = A & {
  b: string
}
  • Pick members from the Record (useful for DDB projections)
class BOnly extends B.Pick(['b']) {}
// equiv to.
type BOnly = Pick<B, 'b'>

DynamoDB Indexes and Projections

This is then used to support Projections in DynamoDB Indexes.

class Counter extends Record({
  key: string,
  count: integer,
  data: binary, // large amount of binary data
}) {}

const hashTable = new DynamoDB.Table(stack, 'Table', {
  data: Counter,
  key: {
    partition: 'key'
  }
});

const countIndex = hashTable.globalIndex({
  indexName: 'index',
  key: {
    partition: 'count',
    sort: 'key'
  }
});

Projections:

class CounterProjection extends Counter.Pick(['key', 'count']) {}

const countIndex = hashTable.projectTo(CounterProjection).globalIndex({
  indexName: 'index',
  key: {
    partition: 'count',
    sort: 'key'
  }
});

"Arn",
],
},
"/index/*",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the CDK grants * if you ever use an index :(

@sam-goodwin sam-goodwin changed the title [WIP] feat(shape, dynamodb): Pick/Extend mechanics for Records to support DynamoDB Indexes feat(shape, dynamodb): Pick/Extend mechanics for Records to support DynamoDB Indexes Feb 7, 2020
@sam-goodwin sam-goodwin merged commit a8db539 into master Feb 7, 2020
@sam-goodwin sam-goodwin deleted the dynamodb-indexes branch February 7, 2020 12:25
@sam-goodwin sam-goodwin moved this from Doing to Done in v0.13.0 Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

Support local and global secondary indexes on DynamoDB Tables
1 participant