batchPutItem

Spec

async batchWriteItem(
    tnmInput: TynamoBatchWriteItemInput<TSource>
): Promise<TynamoBatchWriteItemOutput<TSource>>

Unlike Dynamo, there is no limit.

Internally, they are split properly and processed in parallel.

Input

export type PutOrDelete<TSource> =
    | {
          Operation: "put";
          Item: TSource;
      }
    | {
          Operation: "delete";
          Key: Partial<TSource>;
      };
      
      
export interface TynamoBatchWriteItemInput<TSource> {
    RequestItems: PutOrDelete<TSource>[];
    
    // Derived from DynamoDB.
    ReturnConsumedCapacity?: ReturnConsumedCapacity;
    ReturnItemCollectionMetrics?: ReturnItemCollectionMetrics;
}

Name

Type

Info

RequestItems

PutOrDelete<@DynamoEntity>[]

Array of single operation of put or delete.

Unlisted param is derived from DynamoDB.

Check here for more information.

Output

export type PutOrDelete<TSource> =
    | {
          Operation: "put";
          Item: TSource;
      }
    | {
          Operation: "delete";
          Key: Partial<TSource>;
      };
      

export interface TynamoBatchWriteItemOutput<TSource> {
    UnprocessedItems?: PutOrDelete<TSource>[];

    // Derived from DynamoDB.
    $response: Response<BatchWriteItemOutput, AWSError>;
    ItemCollectionMetrics?: ItemCollectionMetricsPerTable;
    ConsumedCapacity?: ConsumedCapacityMultiple;
}

Name

Type

Info

UnprocessedKeys

PutOrDelete<@DynamoEntity>[]

Failed operations.

Unlisted param is derived from DynamoDB.

Check here for more information.

Example

@DynamoEntity()
class Cat {
    @DynamoProperty({ keyType: KeyType.hash })
    id!: number;

    @DynamoProperty({ keyType: KeyType.attr })
    name!: string;

    constructor(id: number, name: string) {
        this.id = id;
        this.name = name;
    }
}

const tynamo: Tynamo = new Tynamo({
    region: "ap-northeast-2",
    endpoint: "http://localhost:8000"
});
const tynamoTable = tynamo.getTableOf(Cat);

const operations: PutOrDelete<Cat>[] = [];
for(let i=0; i<100; i++){
    operations.push({
        Operation: "put",
        Item: new Cat(i, i.toString())
    })
}

await tynamoTable.batchWriteItem({
    RequestItems: operations
});

Last updated

Was this helpful?