Skip to content

Documentation: .index must be called before .wherePartitionKey #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tracked by #374
jthomerson opened this issue May 19, 2020 · 1 comment
Closed
Tracked by #374

Documentation: .index must be called before .wherePartitionKey #301

jthomerson opened this issue May 19, 2020 · 1 comment
Labels

Comments

@jthomerson
Copy link
Contributor

It would be good to show examples of querying on a GSI in the documentation. I was scratching my head for a while because I had code like this:

async function find(pk: string, skPrefix?: string, index?: MyIndexEnum): Promise<Foo[]> {
   let query = store.query().wherePartitionKey(pk);

   if (index) {
      query = query.index(index);
   }

   if (skPrefix && !isEmpty(skPrefix)) {
      query = query.whereSortKey().beginsWith(skPrefix.toLowerCase());
   }

   console.debug(`Query ${index || 'table'} for "${pk}" begins_with(${skPrefix})`);

   return query.exec();
}

I didn't realize that you had to call .index(...) before calling wherePartitionKey. That seems a bit counterintuitive on this builder pattern, but if it was documented along with the query documentation, that'd make it easy to see.

@michaelwittwer
Copy link
Member

@jthomerson also closing in favour of #374, thanks for bringing that to our attention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants