-
Notifications
You must be signed in to change notification settings - Fork 19
Allow paging in Table.scan. #470
Conversation
Add an overload of Table.scan that accepts a callback that will be invoked as each page of results is fetched. If this callback returns `false`, no more pages will be fetched. These changes also fix a bug wherein the AWS implementation of Table.scan would not fetch all results if they had been paginated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
aws/table.ts
Outdated
} | ||
params.ExclusiveStartKey = result.LastEvaluatedKey; | ||
} | ||
return items; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this unconditionally means the types sort of "lie". We will end up always returning an array - and perhaps surprisingly, an empty array in the case that you passed in a callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had not thought about doing this conditionally--I'll give that a shot.
const db = await getDb(); | ||
const result = await db.scan({ | ||
const params: any = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a shame we can't use a type annotation here, but I think due to the await import
it isn't easy to name this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not sure how we'd type it.
return items; | ||
} else { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: tihs is effectively equivalent to just "return items";
Add an overload of Table.scan that accepts a callback that will be
invoked as each page of results is fetched. If this callback returns
false
, no more pages will be fetched.These changes also fix a bug wherein the AWS implementation of
Table.scan would not fetch all results if they had been paginated.