import { DynamoDBClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../DynamoDBClient"; import { QueryInput, QueryOutput } from "../models/models_0"; import { deserializeAws_json1_0QueryCommand, serializeAws_json1_0QueryCommand } from "../protocols/Aws_json1_0"; import { getSerdePlugin } from "@aws-sdk/middleware-serde"; import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http"; import { Command as $Command } from "@aws-sdk/smithy-client"; import { FinalizeHandlerArguments, Handler, HandlerExecutionContext, MiddlewareStack, HttpHandlerOptions as __HttpHandlerOptions, MetadataBearer as __MetadataBearer, SerdeContext as __SerdeContext, } from "@aws-sdk/types"; export interface QueryCommandInput extends QueryInput {} export interface QueryCommandOutput extends QueryOutput, __MetadataBearer {} /** *

The Query operation finds items based on primary key values. * You can query any table or secondary index that has a composite primary key (a partition * key and a sort key). *

*

Use the KeyConditionExpression parameter to provide a specific value * for the partition key. The Query operation will return all of the items * from the table or index with that partition key value. You can optionally narrow the * scope of the Query operation by specifying a sort key value and a * comparison operator in KeyConditionExpression. To further refine the Query results, * you can optionally provide a FilterExpression. A FilterExpression determines which items * within the results should be returned to you. All of the other results are discarded. *

*

* A Query operation always returns a result set. If no matching items are found, * the result set will be empty. Queries that do not return results consume the minimum number of * read capacity units for that type of read operation. *

* *

* DynamoDB calculates the number of read capacity units consumed based on item size, * not on the amount of data that is returned to an application. The number of capacity * units consumed will be the same whether you request all of the attributes (the default behavior) * or just some of them (using a projection expression). The number will also be the same * whether or not you use a FilterExpression. *

*
*

* Query results are always sorted by the sort key value. If the data type of the sort key is Number, * the results are returned in numeric order; otherwise, the results are returned in order of UTF-8 bytes. * By default, the sort order is ascending. To reverse the order, set the ScanIndexForward parameter * to false. *

*

A single Query operation will read up to the maximum number of items * set (if using the Limit parameter) or a maximum of 1 MB of data and then * apply any filtering to the results using FilterExpression. If * LastEvaluatedKey is present in the response, you will need to paginate * the result set. For more information, see Paginating * the Results in the Amazon DynamoDB Developer Guide.

*

* FilterExpression is applied after a Query finishes, but before * the results are returned. * A FilterExpression cannot contain partition key or sort key attributes. * You need to specify those attributes in the KeyConditionExpression. *

* *

* A Query operation can return an empty result set and a LastEvaluatedKey * if all the items read for the page of results are filtered out. *

*
*

You can query a table, a local secondary index, or a global secondary index. For a * query on a table or on a local secondary index, you can set the * ConsistentRead parameter to true and obtain a * strongly consistent result. Global secondary indexes support eventually consistent reads * only, so do not specify ConsistentRead when querying a global * secondary index.

* @example * Use a bare-bones client and the command you need to make an API call. * ```javascript * import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb"; // ES Modules import * // const { DynamoDBClient, QueryCommand } = require("@aws-sdk/client-dynamodb"); // CommonJS import * const client = new DynamoDBClient(config); * const command = new QueryCommand(input); * const response = await client.send(command); * ``` * * @see {@link QueryCommandInput} for command's `input` shape. * @see {@link QueryCommandOutput} for command's `response` shape. * @see {@link DynamoDBClientResolvedConfig | config} for command's `input` shape. * */ export class QueryCommand extends $Command { // Start section: command_properties // End section: command_properties constructor(readonly input: QueryCommandInput) { // Start section: command_constructor super(); // End section: command_constructor } /** * @internal */ resolveMiddleware( clientStack: MiddlewareStack, configuration: DynamoDBClientResolvedConfig, options?: __HttpHandlerOptions ): Handler { this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize)); const stack = clientStack.concat(this.middlewareStack); const { logger } = configuration; const clientName = "DynamoDBClient"; const commandName = "QueryCommand"; const handlerExecutionContext: HandlerExecutionContext = { logger, clientName, commandName, inputFilterSensitiveLog: QueryInput.filterSensitiveLog, outputFilterSensitiveLog: QueryOutput.filterSensitiveLog, }; const { requestHandler } = configuration; return stack.resolve( (request: FinalizeHandlerArguments) => requestHandler.handle(request.request as __HttpRequest, options || {}), handlerExecutionContext ); } private serialize(input: QueryCommandInput, context: __SerdeContext): Promise<__HttpRequest> { return serializeAws_json1_0QueryCommand(input, context); } private deserialize(output: __HttpResponse, context: __SerdeContext): Promise { return deserializeAws_json1_0QueryCommand(output, context); } // Start section: command_body_extra // End section: command_body_extra }