query method

Future<QueryOutput> query({
  1. required AttributeValue hashKeyValue,
  2. required String tableName,
  3. List<String>? attributesToGet,
  4. bool? consistentRead,
  5. bool? count,
  6. Key? exclusiveStartKey,
  7. int? limit,
  8. Condition? rangeKeyCondition,
  9. bool? scanIndexForward,
})

Gets the values of one or more items and its attributes by primary key (composite primary key, only).

Narrow the scope of the query using comparison operators on the RangeKeyValue of the composite key. Use the ScanIndexForward parameter to get results in forward or reverse order by range key.

May throw ProvisionedThroughputExceededException. May throw ResourceNotFoundException. May throw RequestLimitExceeded. May throw InternalServerError.

Parameter hashKeyValue : Attribute value of the hash component of the composite primary key.

Parameter tableName : The name of the table in which you want to query. Allowed characters are a-z, A-Z, 0-9, _ (underscore), - (hyphen) and . (period).

Parameter count : If set to true, Amazon DynamoDB returns a total number of items that match the query parameters, instead of a list of the matching items and their attributes. Do not set Count to true while providing a list of AttributesToGet, otherwise Amazon DynamoDB returns a validation error.

Parameter exclusiveStartKey : Primary key of the item from which to continue an earlier query. An earlier query might provide this value as the LastEvaluatedKey if that query operation was interrupted before completing the query; either because of the result set size or the Limit parameter. The LastEvaluatedKey can be passed back in a new query request to continue the operation from that point.

Parameter limit : The maximum number of items to return. If Amazon DynamoDB hits this limit while querying the table, it stops the query and returns the matching values up to the limit, and a LastEvaluatedKey to apply in a subsequent operation to continue the query. Also, if the result set size exceeds 1MB before Amazon DynamoDB hits this limit, it stops the query and returns the matching values, and a LastEvaluatedKey to apply in a subsequent operation to continue the query.

Parameter rangeKeyCondition : A container for the attribute values and comparison operators to use for the query.

Parameter scanIndexForward : Specifies forward or backward traversal of the index. Amazon DynamoDB returns results reflecting the requested order, determined by the range key. The default value is true (forward).

Implementation

Future<QueryOutput> query({
  required AttributeValue hashKeyValue,
  required String tableName,
  List<String>? attributesToGet,
  bool? consistentRead,
  bool? count,
  Key? exclusiveStartKey,
  int? limit,
  Condition? rangeKeyCondition,
  bool? scanIndexForward,
}) async {
  ArgumentError.checkNotNull(hashKeyValue, 'hashKeyValue');
  ArgumentError.checkNotNull(tableName, 'tableName');
  _s.validateStringLength(
    'tableName',
    tableName,
    3,
    255,
    isRequired: true,
  );
  _s.validateNumRange(
    'limit',
    limit,
    1,
    1152921504606846976,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.0',
    'X-Amz-Target': 'DynamoDB_20111205.Query'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'HashKeyValue': hashKeyValue,
      'TableName': tableName,
      if (attributesToGet != null) 'AttributesToGet': attributesToGet,
      if (consistentRead != null) 'ConsistentRead': consistentRead,
      if (count != null) 'Count': count,
      if (exclusiveStartKey != null) 'ExclusiveStartKey': exclusiveStartKey,
      if (limit != null) 'Limit': limit,
      if (rangeKeyCondition != null) 'RangeKeyCondition': rangeKeyCondition,
      if (scanIndexForward != null) 'ScanIndexForward': scanIndexForward,
    },
  );

  return QueryOutput.fromJson(jsonResponse.body);
}