Skip to main content

scan

Introduction​

scan method performs scan request using aws-sdk ScanCommand.

Items in ScanCommandOutput is fully typed based on your Schema declaration.

execute​

scan takes 2 optionnal arguments:

  1. FilterExpression
  2. options
const res = await User.scan(
{
age: {
$gt: 22
}
},
{ ReturnConsumedCapacity: "TOTAL" }
);

res.Items[0].firstname;

options​

options is an object which accepts ScanCommandInput options and DynamoQL specific options.

exec​

exec boolean directive to execute or not the actual request.
When false scan will return ScanCommandInput object.

import type { ScanCommandInput } from "@aws-sdk/client-dynamodb";

const cmd: ScanCommandInput = await User.scan(
{
age: {
$gt: 22
}
},
{ exec: false }
);

Select​

Select accepts an array of attributes which produces a ProjectionExpression, or "ALL" | "COUNT".

const res = await User.scan(
{
age: {
$gt: 22
}
},
{ Select: ["id", "isActive"] }
);

note

Select affects ScanCommandOutput type.

const { Items } = await User.scan(
{
age: {
$gt: 22
}
},
{ Select: ["id", "isActive"] }
);

Items[0].firstname; // Property 'firstname' does not exist on type { id: string; isActive?:boolean } ...
const res = await User.scan(
{
age: {
$gt: 22
}
},
{ Select: "COUNT" }
);

res.Items; // Property 'Items' does not exist on type ScanCommandOutput

getterInfo​

getterInfo allows you to pass any value to your Schema get function's third argument.

const res = await User.scan(
{
age: {
$gt: 22
}
},
{ getterInfo: { forFrontend: true } }
);