sam-goodwin / punchcard

Type-safe AWS infrastructure.
Apache License 2.0
506 stars 20 forks source link

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

Closed sam-goodwin closed 4 years ago

sam-goodwin commented 4 years ago

Closes #104

Two new mechanics for Records:

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'
  }
});