예제 #1
0
        public async Task <IList <T> > QueryAllAsync(DynamoQuery query)
        {
            query.TableName = tableName;

            var remaining = query.Limit;

            var result = new List <T>();

            QueryResult a;

            do
            {
                a = await client.QueryAsync(query, retryPolicy).ConfigureAwait(false);

                foreach (var item in a.Items)
                {
                    result.Add(item.As <T>());
                }

                remaining -= a.Count;

                query.ExclusiveStartKey = a.LastEvaluatedKey;
                query.Limit             = remaining;
            }while (a.LastEvaluatedKey != null && remaining >= 0);

            return(result);
        }
예제 #2
0
        public async Task <QueryResult> QueryAsync(DynamoQuery query, RetryPolicy retryPolicy)
        {
            var       retryCount = 0;
            Exception lastException;

            do
            {
                if (retryCount > 0)
                {
                    await Task.Delay(retryPolicy.GetDelay(retryCount)).ConfigureAwait(false);
                }

                try
                {
                    return(await QueryAsync(query).ConfigureAwait(false));
                }
                catch (DynamoDbException ex) when(ex.IsTransient)
                {
                    lastException = ex;
                }

                retryCount++;
            }while (retryPolicy.ShouldRetry(retryCount));

            throw new DynamoDbException($"Error querying '{query.TableName}': {lastException.Message}", lastException);
        }
예제 #3
0
        public async Task <IList <T> > QueryAsync(DynamoQuery query)
        {
            query.TableName = tableName;

            var result = await client.QueryAsync(query, retryPolicy).ConfigureAwait(false);

            return(new QueryResult <T>(result));
        }
예제 #4
0
        public async Task <QueryResult> QueryAsync(DynamoQuery query)
        {
            var httpRequest = Setup("Query", query.ToJson());

            var json = await SendAndReadJsonElementAsync(httpRequest).ConfigureAwait(false);

            return(QueryResult.FromJsonElement(json));
        }
예제 #5
0
        public async Task <int> CountAsync(DynamoQuery query)
        {
            query.TableName = tableName;
            query.Select    = SelectEnum.COUNT;

            var result = await client.QueryCount(query).ConfigureAwait(false);

            return(result.Count);
        }
예제 #6
0
        public async Task <CountResult> QueryCountAsync(DynamoQuery query)
        {
            query.Select = SelectEnum.COUNT;

            var httpRequest = Setup("Query", query.ToJson());

            string responseText = await SendAsync(httpRequest).ConfigureAwait(false);

            return(System.Text.Json.JsonSerializer.Deserialize <CountResult>(responseText));
        }
예제 #7
0
        public async Task <QueryResult> QueryAsync(DynamoQuery query)
        {
            var httpRequest = Setup("Query", query.ToJson());

            var responseText = await SendAsync(httpRequest).ConfigureAwait(false);

            var responseJson = JsonObject.Parse(responseText);

            return(QueryResult.FromJson(responseJson));
        }
예제 #8
0
        public async Task <CountResult> QueryCountAsync(DynamoQuery query)
        {
            query.Select = SelectEnum.COUNT;

            var httpRequest = Setup("Query", query.ToJson());

            var responseText = await SendAsync(httpRequest).ConfigureAwait(false);

            var responseJson = JsonObject.Parse(responseText);

            return(responseJson.As <CountResult>());
        }
예제 #9
0
        public Task <IReadOnlyList <T> > QueryAsync(params Expression[] expressions)
        {
            var e = new DynamoQueryExpression(PrimaryKey.Names, expressions);

            var query = new DynamoQuery {
                KeyConditionExpression    = e.KeyExpression.Text,
                ExpressionAttributeNames  = (e.HasAttributeNames) ? e.AttributeNames : null,
                ExpressionAttributeValues = e.AttributeValues,
                FilterExpression          = e.FilterExpression?.Text
            };

            return(QueryAsync(query));
        }
예제 #10
0
        public async Task <QueryResult> QueryAsync(DynamoQuery query)
        {
            #region Preconditions

            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            #endregion

            var httpRequest = Setup("Query", query.ToJson());

            var responseText = await SendAsync(httpRequest).ConfigureAwait(false);

            var responseJson = JsonObject.Parse(responseText);

            return(QueryResult.FromJson(responseJson));
        }
예제 #11
0
        public Task <IList <T> > QueryAsync(Query q)
        {
            var e = new DynamoQueryExpression(PrimaryKey.Names, q.Expressions);

            var query = new DynamoQuery {
                IndexName = q.Index?.Name,
                Limit     = q.Take ?? 0,
                KeyConditionExpression    = e.KeyExpression.Text,
                ExpressionAttributeNames  = (e.HasAttributeNames) ? e.AttributeNames : null,
                ExpressionAttributeValues = e.AttributeValues,
                FilterExpression          = e.FilterExpression?.Text
            };

            if (q.Orders != null && q.Orders[0].IsDescending)
            {
                query.ScanIndexForward = false;
            }

            return(QueryAsync(query));
        }