# batchPutItem

### Spec

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

{% hint style="info" %}
Unlike Dynamo, there is no limit. &#x20;

Internally, they are split properly and processed in parallel.
{% endhint %}

### Input&#x20;

```typescript
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. |

{% hint style="info" %}
Unlisted param is derived from `DynamoDB`.

Check [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html) for more information.
{% endhint %}

### Output

```typescript
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. |

{% hint style="info" %}
Unlisted param is derived from `DynamoDB`.

Check [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html) for more information.
{% endhint %}

### Example

```typescript
@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
});


```
