async batchWriteItem(
tnmInput: TynamoBatchWriteItemInput<TSource>
): Promise<TynamoBatchWriteItemOutput<TSource>>
Unlike Dynamo, there is no limit.
Internally, they are split properly and processed in parallel.
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;
}
Unlisted param is derived from DynamoDB
.
Check here for more information.
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;
}
Unlisted param is derived from DynamoDB
.
Check here for more information.
@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
});