Пример #1
0
        private void SetRequester()
        {
            var generator      = new ExpressionGenerator(_tableDescription, IndexName, QueryInfo.WhereExpression);
            var generateResult = generator.Analyze();

            var sortKeyExists = !string.IsNullOrEmpty(generator.SortKeyName);

            // Hash key only in this index
            if (!sortKeyExists)
            {
                // If HashKey not found in where expr
                if (generateResult.HashKey == null)
                {
                    _requester = new ScanRequester();
                }
                else
                {
                    if (string.IsNullOrEmpty(IndexName) && string.IsNullOrWhiteSpace(generateResult.FilterExpression))
                    {
                        _requester = new GetItemRequester();
                    }
                    else
                    {
                        _requester = new QueryRequester();
                    }
                }
            }
            // HashKey and SortKey
            else
            {
                // If HashKey or SortKey not found in where expr
                if (generateResult.HashKey == null &&
                    generateResult.SortKey == null)
                {
                    _requester = new ScanRequester();
                }
                else
                {
                    if (string.IsNullOrEmpty(IndexName) &&
                        string.IsNullOrWhiteSpace(generateResult.FilterExpression) &&
                        generateResult.SortKey?.Operator == "=")
                    {
                        _requester = new GetItemRequester();
                    }
                    else
                    {
                        _requester = new QueryRequester();
                    }
                }
            }

            _requester.Command = Command;

            _requester.SetParameters(
                Context.Client,
                QueryInfo,
                generateResult.ExpressionAttributeNames,
                generateResult.ExpressionAttributeValues,
                generateResult.HashKey,
                generateResult.SortKey,
                generator.HashKeyName,
                generator.SortKeyName,
                TableName,
                IndexName,
                generateResult.FilterExpression
                );
        }