Support local and global secondary indexes on DynamoDB Tables
sam-goodwin opened this issue · comments
As per #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']
);
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.