sam-goodwin / punchcard

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

Support local and global secondary indexes on DynamoDB Tables #104

Closed sam-goodwin closed 4 years ago

sam-goodwin commented 4 years ago

As per https://github.com/punchcard/punchcard/issues/103, we want to support indexes on DynamoDB tables. How should we do this?

I think the desired experience should be similar to how the table is created where the developer only needs to provide a tuple of the columns to index:

@Birowsky's example:

class RestarauntRecord extends Record({
  id: string,
  byUserId: string,
  status: string,
  avgRating: number
    .apply(Minimum(?))
    .apply(Maximum(?))
  starCount: string, // or integer?number? Not sure why your definition defines this column as a string?
}) {}

const table = new DynamoDB.Table(stack, 'id', RestarauntRecord, 'key');
const byStars = table.globalIndex(['starCount', 'avgRating']);
const byUserId = table.globalIndex(['byUserId', 'avgRating']);
const byStatus = table.globalIndex(['status', 'avgRating']);

What about projections? Should developers create another record class to represent the projection, or can we support an array of columns to project?

const projected = table.globalIndex('starCount', 'avgRating',
  // columns to project?
  ['starCount', 'byUserId', 'avgRating']
);
Birowsky commented 4 years ago

Not sure why your definition defines this column as a string?

The type there is explicit: 'One' | 'Two' | 'Three' | 'Four' | 'Five'.

Should developers create another record class to represent the projection, or can we support an array of columns to project?

I see array of columns as the ideal approach.