Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace scanHelper

Index

Functions

  • scanAll(dynamodb: DynamoDB, req: ScanInput): Promise<any[]>
  • Paginate through a scan to collect all results.

    For large results this can use significantly more memory than scanByCallback.

    Parameters

    • dynamodb: DynamoDB

      The DynamoDB client instance to use.

    • req: ScanInput

      The scan input.

    Returns Promise<any[]>

  • scanByCallback(dynamodb: DynamoDB, req: ScanInput, callback: (items: any[]) => boolean | Promise<boolean>): Promise<void>
  • Paginate through a scan and pass each page of results to a callback. Pagination can be aborted by returning false (or a Promise that resolves to false) from the callback.

    For large results this can use significantly less memory than scanAll.

    An example where scan is used to delete every object in a table. (For large tables it's more efficient to delete and recreate the table.)

    const scanInput = dynemeh.requestBuilder.buildScanInput(tableSchema);
    await dynameh.scanHelper.scanByCallback(dynamodbClient, scanInput, async items => {
    const keysToDelete = objectSchema.sortKeyField ?
    items.map(item => [item[tableSchema.partitionKeyField], item[tableSchema.sortKeyField]]) :
    items.map(item => item[tableSchema.partitionKeyField]);
    const batchDeleteInput = dynameh.requestBuilder.buildBatchDeleteInput(tableSchema, keysToDelete);
    await dynameh.batchHelper.batchWriteAll(dynamodbClient, batchDeleteInput);
    return true;
    });

    Parameters

    • dynamodb: DynamoDB

      The DynamoDB client instance to use.

    • req: ScanInput

      The scan input.

    • callback: (items: any[]) => boolean | Promise<boolean>

      A function that each page of results is passed to. Return false (or a Promise that resolves to false) to abort the scan.

        • (items: any[]): boolean | Promise<boolean>
        • Parameters

          • items: any[]

          Returns boolean | Promise<boolean>

    Returns Promise<void>

  • scanCountAll(dynamodb: DynamoDB, req: ScanInput): Promise<number>
  • Paginate through a scan to count all results. This is more efficient than scanAll when only the count is needed.

    Parameters

    • dynamodb: DynamoDB

      The DynamoDB client instance to use.

    • req: ScanInput

      The scan input.

    Returns Promise<number>

Generated using TypeDoc