noppoMan / npdynamodb

A Node.js Simple Query Builder and ORM for AWS DynamoDB
112 stars 18 forks source link

No example in readme for querying indexes #46

Closed brett--anderson closed 8 years ago

brett--anderson commented 8 years ago

How do I write a query with the ORM that will run against a local secondary index, rather than the parent table? I can't see an example of this in the readme.

noppoMan commented 8 years ago

Hi Brett,

Here is an example for it

FooModel.query(function(qb){
  qb.indexName("Local or Global SecondaryIndexName");
})
.where('hashKeyForTheIndex', "value")
.fetch()
.then(function(data){
  console.log(data.toJSON());
});

You can switch the target index with QueryBuilder.indexName("name")

noppoMan commented 8 years ago

Here is a practical usage for indexName in the test. https://github.com/noppoMan/npdynamodb/blob/master/test/query_builder_read_spec.js#L524

brett--anderson commented 8 years ago

Awesome, thanks! I'll close the issue since there are examples in the tests.