import { AttributeValue, QueryCommandInput, QueryCommandOutput } from '@aws-sdk/client-dynamodb'; /** * This class helps with building queries to a DDB table */ declare class Query { private _ddb; private _params; private _sortKeyName; constructor(config: { region: string; }, table: string); /** * Sets the TableName parameter for the command input. * This method is not necessary if you provided the table name in the construction of Query. * * @param name - string of the table name to query on * @returns Query with populated params */ table(name: string): Query; /** * Sets the IndexName parameter for the command input. * * @param name - string of the index name to query on * @returns Query with populated params */ index(name: string): Query; /** * Helps with setting up KeyConditionExpression for command input where name = value. * this is for the partition key only. If you also need to specify sort key, then use sortKey() then .eq(), .lt() or .gt(). * However, if you use .condition() for the sort key expression, you will need to use values() and possibly names(). * * @param name - string of the partition key name * @param value - value you are querying for on the partition key * @returns Query with populated params */ key(name: string, value: AttributeValue): Query; /** * Helps with setting up KeyConditionExpression for command input. * This is for the sort key only. If you also need to specify partition key, then use key(). * You must call this method before .eq(), .gt(), .gte(), .lt(), .lte(). * However, if you use .condition() for the sort key expression, you will need to use values() and possibly names(). * * @param name - string of the sort key name * @returns Query with populated params */ sortKey(name: string): Query; /** * Helps with setting up KeyConditionExpression for sort key only. * It results in an equal expression using the sort key "# = :". * You only want to supply the value of the sort key here since we assume you called .sortKey(name) before calling this one * * @param value - the value to check for equality against the sort key * @returns Query with populated params */ eq(value: AttributeValue): Query; /** * Helps with setting up KeyConditionExpression for sort key only. * It results in a less than expression using the sort key "#\ \< :\". * You only want to supply the value of the sort key here since we assume you called .sortKey(name) before calling this one * * @param value - the value to check for relation against the sort key * @returns Query with populated params */ lt(value: AttributeValue): Query; /** * Helps with setting up KeyConditionExpression for sort key only. * It results in a less than or equal expression using the sort key "#\ \<= :\". * You only want to supply the value of the sort key here since we assume you called .sortKey(name) before calling this one * * @param value - the value to check for relation against the sort key * @returns Query with populated params */ lte(value: AttributeValue): Query; /** * Helps with setting up KeyConditionExpression for sort key only. * It results in a greater than expression using the sort key "#\ \> :\". * You only want to supply the value of the sort key here since we assume you called .sortKey(name) before calling this one * * @param value - the value to check for relation against the sort key * @returns Query with populated params */ gt(value: AttributeValue): Query; /** * Helps with setting up KeyConditionExpression for sort key only. * It results in a greater than or equal to expression using the sort key "#\ \>= :\". * You only want to supply the value of the sort key here since we assume you called .sortKey(name) before calling this one * * @param value - the value to check for relation against the sort key * @returns Query with populated params */ gte(value: AttributeValue): Query; /** * Helps with setting up KeyConditionExpression for sort key only. * It results in the between expression using the sort key "# BETWEEN : AND :". * You only want to supply the two between values of the sort key here since we assume you called .sortKey(name) before calling this one * * @param value1 - the first value to check for against the sort key * @param value2 - the second value to check for against the sort key * @returns Query with populated params */ between(value1: AttributeValue, value2: AttributeValue): Query; /** * Helps with setting up KeyConditionExpression for sort key only. * It results in a begins_with expression using the sort key "begins_with( # ,: )". * You only want to supply the two between values of the sort key here since we assume you called .sortKey(name) before calling this one * * @param value - the value to check for relation against the sort key * @returns Query with populated params */ begins(value: AttributeValue): Query; /** * Helper method to set the internal expression. Used by public methods on querying on sort key. * * @param expr - string that defines the relation to query on (ex: =, \>, \<, etc.) * @param value - the AttributeValue to check against * @returns Query with populated params */ private _internalExpression; /** * Helper method to set the condition. Used by public methods on querying on sort key. * * @param expression - string that defines the condition to query on (ex: begins_with()) * @returns Query with populated params */ private _setCondition; /** * Sets the ExclusiveStartKey parameter for the command input. * Use for pagination by providing the LastEvaluatedKey in the previous request as the ExclusiveStartKey in the new request. * * @param key - primary key of the element to start with (exclusive) in a query * @returns Query with populated params */ start(key: { [key: string]: AttributeValue; } | undefined): Query; /** * Sets the FilterExpression parameter of the command input. * Items that do not satisfy the FilterExpression criteria are not returned. * A FilterExpression does not allow key attributes. You cannot define a filter expression based on a partition key or a sort key. * A FilterExpression is applied after the items have already been read; the process of filtering does not consume any additional read capacity units. * Filter expressions can use the same comparators, functions, and logical operators as a key condition expression, with the addition of the not-equals operator (\<\>), the OR operator, the CONTAINS operator, the IN operator, and the BEGINS_WITH operator. * * @param str - a string that contains conditions that DynamoDB applies after the Query operation, but before the data is returned to you * @returns Query with populated params * * @example Filtering on items that do not have the latest attribute * ```ts * # Usage * Query.filter(attribute_not_exists(latest)) * ``` */ filter(str: string): Query; /** * Sets ConsistentRead to be true for command input. * If set to true, then the operation uses strongly consistent reads; otherwise, the operation uses eventually consistent reads. * * @returns Query with populated params */ strong(): Query; /** * Sets the ExpressionAttributeNames of the command input. * The following are some use cases for using ExpressionAttributeNames: * To access an attribute whose name conflicts with a DynamoDB reserved word: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html * To create a placeholder for repeating occurrences of an attribute name in an expression. * To prevent special characters in an attribute name from being misinterpreted in an expression. * Use the # character in an expression to dereference an attribute name. * * @param obj - object of one or more substitution tokens for attribute names in an expression * @returns Query with populated params * * @example Using the reserved word 'Percentile' in your request * ```ts * # Usage * Query.names({"#P":"Percentile"}).condition("#P = 50"); * ``` */ names(obj?: { [key: string]: string; }): Query; /** * Sets the ExpressionAttributeValues of the command input. * Use the : (colon) character in an expression to dereference an attribute value. * * @param obj - object of one or more values that can be substituted in an expression * @returns Query with populated params * * @example Filtered query on status * ```ts * # Usage * Query.values({ ":avail":{"S":"Available"}, ":back":{"S":"Backordered"}, ":disc":{"S":"Discontinued"} }).filter('ProductStatus IN (:avail, :back, :disc)'); * ``` */ values(obj?: { [key: string]: AttributeValue; }): Query; /** * Sets ProjectionExpression of the command input. * A string or list of strings that identifies one or more attributes to retrieve from the table. * If no attribute names are specified, then all attributes are returned. * If any of the requested attributes are not found, they do not appear in the result. * * @param expr - string or list of strings of the attributes to retrieve * @returns Query with populated params */ projection(expr: string | string[]): Query; /** * Sets the Select parameter of the command input. The valid values are: * ALL_ATTRIBUTES - Returns all item attributes from the specified table or index. If you query a local secondary index, then for each matching item in the index, DynamoDB fetches the entire item from the parent table. If the index is configured to project all item attributes, then all the data can be obtained from the local secondary index, and no fetching is required. * ALL_PROJECTED_ATTRIBUTES - Allowed only when querying an index. Retrieves all attributes that have been projected into the index. If the index is configured to project all attributes, this return value is equivalent to specifying ALL_ATTRIBUTES. * COUNT - Returns the number of matching items, rather than the matching items themselves. * SPECIFIC_ATTRIBUTES - Returns only the attributes listed in AttributesToGet. This return value is equivalent to specifying AttributesToGet without specifying any value for Select. * If you query or scan a local secondary index and request only attributes that are projected into that index, the operation will read only the index and not the table. * If any of the requested attributes are not projected into the local secondary index, DynamoDB fetches each of these attributes from the parent table. * This extra fetching incurs additional throughput cost and latency. * If you query or scan a global secondary index, you can only request attributes that are projected into the index. * Global secondary index queries cannot fetch attributes from the parent table. * If neither Select nor AttributesToGet are specified, DynamoDB defaults to ALL_ATTRIBUTES when accessing a table, and ALL_PROJECTED_ATTRIBUTES when accessing an index. * If you use the ProjectionExpression parameter, then the value for Select can only be SPECIFIC_ATTRIBUTES. * Any other value for Select will return an error. * * @param str - ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES, SPECIFIC_ATTRIBUTES, or COUNT (not case-sensitive) * @returns Query with populated params */ select(str: 'ALL_ATTRIBUTES' | 'ALL_PROJECTED_ATTRIBUTES' | 'SPECIFIC_ATTRIBUTES' | 'COUNT'): Query; /** * Sets the Limit parameter of the command input. * If DynamoDB processes the number of items up to the limit while processing the results, it stops the operation and returns the matching values up to that point, and a key in LastEvaluatedKey to apply in a subsequent operation, so that you can pick up where you left off. * Also, if the processed dataset size exceeds 1 MB before DynamoDB reaches this limit, it stops the operation and returns the matching values up to the limit, and a key in LastEvaluatedKey to apply in a subsequent operation to continue the operation. * * @param num - the maximum number of items to evaluate (not necessarily the number of matching items) * @returns Query with populated params */ limit(num: number): Query; /** * Sets the ScanIndexForward parameter of the command input. * If true (default), the traversal is performed in ascending order; if false, the traversal is performed in descending order * * @param yesOrNo - true or false * @returns Query with populated params */ forward(yesOrNo?: boolean): Query; /** * Sets the ReturnConsumedCapacity of the command input. * Determines the level of detail about either provisioned or on-demand throughput consumption that is in the response: * INDEXES - The response includes the aggregate ConsumedCapacity for the operation, together with ConsumedCapacity for each table and secondary index that was accessed. * TOTAL - The response includes only the aggregate ConsumedCapacity for the operation. * NONE - No ConsumedCapacity details are included in the response. * * @param str - indexes, total, or none (non-case-sensitive strings) * @returns Query with populated params */ capacity(str: 'INDEXES' | 'TOTAL' | 'NONE'): Query; /** * Gets the internal _params value of the command input. Used for testing purposes. * * @returns The parameters for the QueryCommandInput * * @example Returning command input * ```ts * # Result * { * Key: {}, * TableName: string, * ConsistentRead?: boolean, * ExclusiveStartKey?: {}, * ExpressionAttributeNames?: {}, * ExpressionAttributeValues?: {}, * FilterExpression?: string, * IndexName: string, * KeyConditionExpression?: string, * Limit?: number, * ProjectionExpression?: string, * ReturnConsumedCapacity?: 'INDEXES' | 'TOTAL' | 'NONE', * ScanIndexForward?: boolean, * Select?: 'ALL_ATTRIBUTES' | 'ALL_PROJECTED_ATTRIBUTES' | 'COUNT' | 'SPECIFIC_ATTRIBUTES' * } * ``` */ getParams(): QueryCommandInput; /** * Sends the internal parameters as input to the DynamoDB table to execute the query request. * Call this after populating the command input params with the above methods. * If LastEvaluatedKey is empty, then the "last page" of results has been processed and there is no more data to be retrieved. * If LastEvaluatedKey is not empty, it does not necessarily mean that there is more data in the result set. * The only way to know when you have reached the end of the result set is when LastEvaluatedKey is empty. * Items and LastEvaluatedKey are returned unmarshalled. * * @returns The output from the query command * * @example * ```ts * # Result * { * ConsumedCapacity?: [], * Count?: number, * Items?: {}[], * LastEvaluatedKey?: {}, * ScannedCount?: number * } * ``` */ execute(): Promise; } export default Query; //# sourceMappingURL=query.d.ts.map