Add a related model subquery API
As regards subqueries, I have already set up instance methods on my models that will go out and grab related records. I am injecting them automatically by parsing my model pseudo-code as such:
model User:
{
hashKey: 'id',
schema: {
id: vogels.types.uuid(),
orders: vogels.types.stringSet()
}
}
model Order:
{
hashKey: 'id',
schema: {
id: vogels.types.uuid(),
user: Joi.string()
}
}
In this case I'd store the id attribute from each related order in the Users model instance 'orders' set, then use Order.getItems() to query the orders back out by their keys rather than scanning the whole Order table looking for a user id that matched or building global secondary indexes on that attribute.
Right now when I create my models I inject getters for the related data into Model.prototype. This works fine for lazy loading, but sometimes I want to make a single query and get back related model instances already included in a model instance substructure that lets me interact with them against the other model's API.
So basically, I have lazy loading solved, but I need a solution similar to how you roll up multiple queries into a single response to get around dynamo's max records in a resultset restriction, except synthesizing results from a subquery to another table rather than aggregating results for multiple queries on the same table.
@keithchilders could you provide an example of your lazy loading instance methods?