batchGet method

Future<BatchGetOutput> batchGet({
  1. ReturnConsumedCapacity? returnConsumedCapacity,
  2. required Map<String, KeysAndProjection> requestItems,
})

Returns the attributes of one or more items from one or more tables by delegating to DynamoDB.batchGetItem().

Implementation

Future<BatchGetOutput> batchGet({
  ReturnConsumedCapacity? returnConsumedCapacity,
  required Map<String, KeysAndProjection> requestItems,
}) async {
  final ri = requestItems.map((k, v) => MapEntry(
      k,
      KeysAndAttributes(
        keys: v.keys.map((e) => e.fromJsonToAttributeValue()).toList(),
        projectionExpression: v.projectionExpression,
        consistentRead: v.consistentRead,
        expressionAttributeNames: v.expressionAttributeNames,
      )));
  final response = await dynamoDB.batchGetItem(
    requestItems: ri,
    returnConsumedCapacity: returnConsumedCapacity,
  );

  return BatchGetOutput(
    response.consumedCapacity ?? [],
    response.responses?.map(
          (k, v) => MapEntry(
            k,
            v.map((e) => e.toJson()).toList(),
          ),
        ) ??
        {},
    response.unprocessedKeys?.map(
          (k, v) => MapEntry(
            k,
            KeysAndProjection(
                keys: v.keys.map((e) => e.toJson()).toList(),
                expressionAttributeNames: v.expressionAttributeNames ?? {},
                consistentRead: v.consistentRead ?? false,
                projectionExpression: v.projectionExpression ?? ''),
          ),
        ) ??
        {},
  );
}