Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DataMapper

Object mapper for domain object interaction with DynamoDB.

To use, define a schema that describes how an item is represented in a DynamoDB table. This schema will be used to marshall a native JavaScript object into its desired persisted form. Attributes present on the object but not in the schema will be ignored.

Hierarchy

  • DataMapper

Index

Constructors

constructor

  • new DataMapper(__namedParameters: object): DataMapper

Methods

batchDelete

  • Deletes items from DynamoDB in batches of 25 or fewer via one or more BatchWriteItem operations. The items may be from any number of tables; tables and schemas for each item are determined using the {DynamoDbSchema} property and the {DynamoDbTable} property on defined on each item supplied.

    This method will automatically retry any delete requests returned by DynamoDB as unprocessed. Exponential backoff on unprocessed items is employed on a per-table basis.

    Type parameters

    Parameters

    Returns AsyncIterableIterator<T>

batchGet

  • batchGet<T>(items: SyncOrAsyncIterable<T>, __namedParameters?: object): AsyncIterableIterator<T>
  • Retrieves items from DynamoDB in batches of 100 or fewer via one or more BatchGetItem operations. The items may be from any number of tables; tables and schemas for each item are determined using the {DynamoDbSchema} property and the {DynamoDbTable} property on defined on each item supplied.

    This method will automatically retry any get requests returned by DynamoDB as unprocessed. Exponential backoff on unprocessed items is employed on a per-table basis.

    Type parameters

    Parameters

    • items: SyncOrAsyncIterable<T>

      A synchronous or asynchronous iterable of items to get.

    • Default value __namedParameters: object = {}

    Returns AsyncIterableIterator<T>

batchPut

  • Puts items into DynamoDB in batches of 25 or fewer via one or more BatchWriteItem operations. The items may be from any number of tables; tables and schemas for each item are determined using the {DynamoDbSchema} property and the {DynamoDbTable} property on defined on each item supplied.

    This method will automatically retry any put requests returned by DynamoDB as unprocessed. Exponential backoff on unprocessed items is employed on a per-table basis.

    Type parameters

    Parameters

    Returns AsyncIterableIterator<T>

batchWrite

  • Puts or deletes items from DynamoDB in batches of 25 or fewer via one or more BatchWriteItem operations. The items may belong to any number of tables; tables and schemas for each item are determined using the {DynamoDbSchema} property and the {DynamoDbTable} property on defined on each item supplied.

    This method will automatically retry any write requests returned by DynamoDB as unprocessed. Exponential backoff on unprocessed items is employed on a per-table basis.

    Type parameters

    Parameters

    • items: SyncOrAsyncIterable<[WriteType, T]>

      A synchronous or asynchronous iterable of tuples of the string 'put'|'delete' and the item on which to perform the specified write action.

    Returns AsyncIterableIterator<[WriteType, T]>

createTable

  • createTable(valueConstructor: ZeroArgumentsConstructor<any>, __namedParameters: object): Promise<void>
  • Perform a CreateTable operation using the schema accessible via the {DynamoDbSchema} property and the table name accessible via the {DynamoDbTable} property on the prototype of the constructor supplied.

    The promise returned by this method will not resolve until the table is active and ready for use.

    Parameters

    • valueConstructor: ZeroArgumentsConstructor<any>

      The constructor used for values in the table.

    • __namedParameters: object

    Returns Promise<void>

delete

  • Perform a DeleteItem operation using the schema accessible via the {DynamoDbSchema} property and the table name accessible via the {DynamoDbTable} property on the item supplied.

    Type parameters

    Parameters

    • item: T

      The item to delete

    • Optional options: DeleteOptions

      Options to configure the DeleteItem operation

    Returns Promise<T | undefined>

  • deprecated

    Type parameters

    Parameters

    Returns Promise<T | undefined>

deleteTable

  • deleteTable(valueConstructor: ZeroArgumentsConstructor<any>): Promise<void>
  • Perform a DeleteTable operation using the schema accessible via the {DynamoDbSchema} property and the table name accessible via the {DynamoDbTable} property on the prototype of the constructor supplied.

    The promise returned by this method will not resolve until the table is deleted and can no longer be used.

    Parameters

    • valueConstructor: ZeroArgumentsConstructor<any>

      The constructor used for values in the table.

    Returns Promise<void>

ensureTableExists

  • ensureTableExists(valueConstructor: ZeroArgumentsConstructor<any>, options: CreateTableOptions): Promise<void>
  • If the table does not already exist, perform a CreateTable operation using the schema accessible via the {DynamoDbSchema} property and the table name accessible via the {DynamoDbTable} property on the prototype of the constructor supplied.

    The promise returned by this method will not resolve until the table is active and ready for use.

    Parameters

    • valueConstructor: ZeroArgumentsConstructor<any>

      The constructor used for values in the table.

    • options: CreateTableOptions

      Options to configure the CreateTable operation

    Returns Promise<void>

ensureTableNotExists

  • ensureTableNotExists(valueConstructor: ZeroArgumentsConstructor<any>): Promise<void>
  • If the table exists, perform a DeleteTable operation using the schema accessible via the {DynamoDbSchema} property and the table name accessible via the {DynamoDbTable} property on the prototype of the constructor supplied.

    The promise returned by this method will not resolve until the table is deleted and can no longer be used.

    Parameters

    • valueConstructor: ZeroArgumentsConstructor<any>

      The constructor used for values in the table.

    Returns Promise<void>

executeUpdateExpression

  • executeUpdateExpression<T>(expression: UpdateExpression, key: object, valueConstructor: ZeroArgumentsConstructor<T>, options?: ExecuteUpdateExpressionOptions): Promise<T>
  • Execute a custom update expression using the schema and table name defined on the provided valueConstructor.

    This method does not support automatic version checking, as the current state of a table's version attribute cannot be inferred from an update expression object. To perform a version check manually, add a condition expression:

     const currentVersion = 1;
     updateExpression.set('nameOfVersionAttribute', currentVersion + 1);
     const condition = {
         type: 'Equals',
         subject: 'nameOfVersionAttribute',
         object: currentVersion
     };
    
     const updated = await mapper.executeUpdateExpression(
         updateExpression,
         itemKey,
         constructor,
         {condition}
     );
    

    NB: Property names and attribute paths in the update expression should reflect the names used in the schema.

    Type parameters

    Parameters

    • expression: UpdateExpression

      The update expression to execute.

    • key: object

      The full key to identify the object being updated.

      • [propertyName: string]: any
    • valueConstructor: ZeroArgumentsConstructor<T>

      The constructor with which to map the result to a domain object.

    • Default value options: ExecuteUpdateExpressionOptions = {}

      Options with which to customize the UpdateItem request.

    Returns Promise<T>

    The updated item.

get

  • Perform a GetItem operation using the schema accessible via the {DynamoDbSchema} method and the table name accessible via the {DynamoDbTable} method on the item supplied.

    Type parameters

    Parameters

    • item: T

      The item to get

    • Optional options: GetOptions

      Options to configure the GetItem operation

    Returns Promise<T>

  • deprecated

    Type parameters

    Parameters

    Returns Promise<T>

parallelScan

  • Perform a Scan operation using the schema accessible via the {DynamoDbSchema} method and the table name accessible via the {DynamoDbTable} method on the prototype of the constructor supplied.

    This scan will be performed by multiple parallel workers, each of which will perform a sequential scan of a segment of the table or index. Use the segments parameter to specify the number of workers to be used.

    Type parameters

    Parameters

    • valueConstructor: ZeroArgumentsConstructor<T>

      The constructor to be used for each item returned by the scan

    • segments: number

      The number of parallel workers to use to perform the scan

    • Optional options: ParallelScanOptions

      Options to configure the Scan operation

    Returns ParallelScanIterator<T>

    An asynchronous iterator that yields scan results. Intended to be consumed with a for await ... of loop.

  • deprecated

    Type parameters

    Parameters

    Returns ParallelScanIterator<T>

put

  • Perform a PutItem operation using the schema accessible via the {DynamoDbSchema} method and the table name accessible via the {DynamoDbTable} method on the item supplied.

    Type parameters

    Parameters

    • item: T

      The item to save to DynamoDB

    • Optional options: PutOptions

      Options to configure the PutItem operation

    Returns Promise<T>

  • deprecated

    Type parameters

    Parameters

    Returns Promise<T>

query

  • Perform a Query operation using the schema accessible via the {DynamoDbSchema} method and the table name accessible via the {DynamoDbTable} method on the prototype of the constructor supplied.

    Type parameters

    Parameters

    • valueConstructor: ZeroArgumentsConstructor<T>

      The constructor to use for each query result.

    • keyCondition: ConditionExpression | object

      A condition identifying a particular hash key value.

    • Optional options: QueryOptions

      Additional options for customizing the Query operation

    Returns QueryIterator<T>

    An asynchronous iterator that yields query results. Intended to be consumed with a for await ... of loop.

  • deprecated

    Type parameters

    Parameters

    Returns QueryIterator<T>

scan

update

  • Perform an UpdateItem operation using the schema accessible via the {DynamoDbSchema} method and the table name accessible via the {DynamoDbTable} method on the item supplied.

    Type parameters

    Parameters

    • item: T

      The item to save to DynamoDB

    • Optional options: UpdateOptions

      Options to configure the UpdateItem operation

    Returns Promise<T>

  • deprecated

    Type parameters

    Parameters

    Returns Promise<T>