Skip to main content

ScanItems

Store.scan()

Create a scan request.

import { DynamoDBClient } from '@aws-cdk/client-dynamodb'
import { Store } from '@declanprice/dynostore'

const store = new Store('customers', new new DynamoDBClient())

const scan = store.scan<CustomerItem | OtherItemType>()

using(index)

Use a specific index.

scan.using('indexName')

filter(...conditions)

Provide any combination of supported dynamodb conditions, multiple conditions must be seperated by either and(), or() conditions otherwise an error will be thrown.

scan.filter(
group(
gt('age', 2),
and(),
lt('age', 30)
)
or(),
eq('age', 33)
)

project(projectionString)

Project specific fields to be returned.

scan.project('id,fistName,lastName')

limit(count)

Restrict the number of items to be returned.

scan.limit(100)

startAt(key)

Provide a starting key for pagination purposes, if the previous query returns a valid lastKey item you can pass it to the next query.

scan.startAt({id: '123'})

sort(direction)

Provide an optional sort direction in ascending or descending order, the default is ascending.

scan.sort('asc')

scan.sort('desc')

parallel(totalSegments, currentSegment)

Optionally run the scan in parallel, you must provide the total segments and the current segment.

scan.parallel(4, 1);

exec()

Execute the query.

const response: ScanResponse<CustomerItem | OtherItemType>[] = await scan.exec();

const { items, lastKey } = response;

A ScanResponse contains the following properties:

SyntaxDescription
itemsan array of unmarshalled items, when no items are found the array will be empty
lastKeyif more items are avaiable to query then lastKey will be the item key to use in the next query