balmbees / dynamo-types

Typescript AWS DynamoDB ORM
231 stars 18 forks source link

Is there a way to apply filters expression on query #59

Closed besasch88 closed 4 years ago

besasch88 commented 4 years ago

Hi, thanks for your project! I'm trying to use your library to execute get and queries on DynamoDB. I'd like to know if there is a way to apply also filters in a query operation, in my case on a GSI. Is there also a way to use ExclusiveStartKey for the next query call? Thanks

breath103 commented 4 years ago

Hi, so it's two different question here: A. How to use filter on query? B. How to use ExclusiveStartKey?

so for A, we don't really support it for now. you can refer https://github.com/balmbees/dynamo-types/issues/24 this for the exact reason, but in short: you should avoid that pattern.

B, sure this is kind of missing in readme.md i guess -

    const records: Models.WordDictionaryItem[] = [];
    let exclusiveStartKey: undefined | any;
    do {
      const result = await Models.WordDictionaryItem.primaryKey.scan({
        exclusiveStartKey, limit: 200,
      });
      exclusiveStartKey = result.lastEvaluatedKey;
      records.push(...result.records);
    } while (!!exclusiveStartKey);

    return records;

hope that helps.