// BatchWriter batch writes an array of write requests to a table
BatchWriter batch writes an array of write requests to a table
// BatchWriter batch writes an array of write requests to a table
func (c *Client) BatchWriter(ctx context.Context, tableName string, requests ...*dynamodb.WriteRequest) (int, error) {
	totalWritten := 0
	chunks := c.ChunkWriteRequests(requests)
	for _, chunk := range chunks {
		out, err := c.DynamoDB.BatchWriteItemWithContext(ctx, &dynamodb.BatchWriteItemInput{
			RequestItems: map[string][]*dynamodb.WriteRequest{
				tableName: chunk,
			},
		})
		if err != nil {
			return totalWritten, err
		}
		totalWritten += len(chunk) - len(out.UnprocessedItems)
		if len(out.UnprocessedItems) > 0 {
			for table, reqs := range out.UnprocessedItems {
				total, err := c.BatchWriter(ctx, table, reqs...)
				totalWritten += total
				if err != nil {
					return totalWritten, err
				}
			}
		}
	}
	return totalWritten, nil
}
func ( c * Client ) BatchWriter ( ctx context . Context , tableName string , requests ... * dynamodb . WriteRequest ) ( int , error ) { totalWritten := 0 chunks := c . ChunkWriteRequests ( requests ) for _ , chunk := range chunks { out , err := c . DynamoDB . BatchWriteItemWithContext ( ctx , & dynamodb . BatchWriteItemInput { RequestItems : map [ string ] [ ] * dynamodb . WriteRequest { tableName : chunk , } , } ) if err != nil { return totalWritten , err } totalWritten += len ( chunk ) - len ( out . UnprocessedItems ) if len ( out . UnprocessedItems ) > 0 { for table , reqs := range out . UnprocessedItems { total , err := c . BatchWriter ( ctx , table , reqs ... ) totalWritten += total if err != nil { return totalWritten , err } } } } return totalWritten , nil }
BatchWriter batch writes an array of write requests to a table
BatchWriter batch writes an array of write requests to a table