Closed sam-goodwin closed 4 years ago
Closes #104
Extends
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
class BOnly extends B.Pick(['b']) {} // equiv to. type BOnly = Pick<B, 'b'>
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' } });
Closes #104
Two new mechanics for Records:
Extends
a Record to create a child record class - sub-typing! any suggestions for better name?Pick
members from the Record (useful for DDB projections)DynamoDB Indexes and Projections
This is then used to support Projections in DynamoDB Indexes.
Projections: